Skip to content

Commit 66fdf66

Browse files
committed
When scrubbing file names, we don't care about slash direction
1 parent 56b9c7e commit 66fdf66

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/test_html.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,15 @@ def test_cant_find_static_files(self):
565565
with self.assertRaisesRegex(CoverageException, msg):
566566
cov.html_report()
567567

568+
def filepath_to_regex(path):
569+
"""Create a regex for scrubbing a file path."""
570+
regex = re.escape(path)
571+
# If there's a backslash, let it match either slash.
572+
regex = regex.replace(r"\\", r"[\\/]")
573+
if env.WINDOWS:
574+
regex = "(?i)" + regex
575+
return regex
576+
568577

569578
def compare_html(dir1, dir2):
570579
"""Specialized compare function for HTML files."""
@@ -575,13 +584,13 @@ def compare_html(dir1, dir2):
575584
# Some words are identifiers in one version, keywords in another.
576585
(r'<span class="(nam|key)">(print|True|False)</span>', r'<span class="nam">\2</span>'),
577586
# Occasionally an absolute path is in the HTML report.
578-
(re.escape(TESTS_DIR), 'TESTS_DIR'),
587+
(filepath_to_regex(TESTS_DIR), 'TESTS_DIR'),
579588
(r'/Users/ned/coverage/trunk/tests', 'TESTS_DIR'),
580-
(flat_rootname(unicode_class(TESTS_DIR)), '_TESTS_DIR'),
589+
(filepath_to_regex(flat_rootname(unicode_class(TESTS_DIR))), '_TESTS_DIR'),
581590
(flat_rootname(u'/Users/ned/coverage/trunk/tests'), '_TESTS_DIR'),
582591
# The temp dir the tests make.
583-
(re.escape(os.getcwd()), 'TEST_TMPDIR'),
584-
(flat_rootname(unicode_class(os.getcwd())), '_TEST_TMPDIR'),
592+
(filepath_to_regex(os.getcwd()), 'TEST_TMPDIR'),
593+
(filepath_to_regex(flat_rootname(unicode_class(os.getcwd()))), '_TEST_TMPDIR'),
585594
(r'/private/var/folders/[\w/]{35}/coverage_test/tests_test_html_\w+_\d{8}', 'TEST_TMPDIR'),
586595
(r'_private_var_folders_\w{35}_coverage_test_tests_test_html_\w+_\d{8}', '_TEST_TMPDIR'),
587596
]

0 commit comments

Comments
 (0)