@@ -565,6 +565,15 @@ def test_cant_find_static_files(self):
565
565
with self .assertRaisesRegex (CoverageException , msg ):
566
566
cov .html_report ()
567
567
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
+
568
577
569
578
def compare_html (dir1 , dir2 ):
570
579
"""Specialized compare function for HTML files."""
@@ -575,13 +584,13 @@ def compare_html(dir1, dir2):
575
584
# Some words are identifiers in one version, keywords in another.
576
585
(r'<span class="(nam|key)">(print|True|False)</span>' , r'<span class="nam">\2</span>' ),
577
586
# Occasionally an absolute path is in the HTML report.
578
- (re . escape (TESTS_DIR ), 'TESTS_DIR' ),
587
+ (filepath_to_regex (TESTS_DIR ), 'TESTS_DIR' ),
579
588
(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' ),
581
590
(flat_rootname (u'/Users/ned/coverage/trunk/tests' ), '_TESTS_DIR' ),
582
591
# 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' ),
585
594
(r'/private/var/folders/[\w/]{35}/coverage_test/tests_test_html_\w+_\d{8}' , 'TEST_TMPDIR' ),
586
595
(r'_private_var_folders_\w{35}_coverage_test_tests_test_html_\w+_\d{8}' , '_TEST_TMPDIR' ),
587
596
]
0 commit comments