Skip to content

Commit bf47990

Browse files
committed
Fix tests for GitHub windows platform
The tests were failing because of differences in file paths. It was comparing: C:\Users\runneradmin\AppData\... to: C:\Users\RUNNER~1\AppData\... and failing. These changes normalize the file paths so the comparisons work properly.
1 parent c8b9a28 commit bf47990

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

tests/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from coverage import env
1919
from coverage.backward import code_object, import_local_file, StringIO
2020
from coverage.data import line_counts
21-
from coverage.files import abs_file
21+
from coverage.files import abs_file, relative_filename
2222
from coverage.misc import CoverageException
2323

2424
from tests.coveragetest import CoverageTest, CoverageTestMethodsMixin, TESTS_DIR, UsingModulesMixin
@@ -472,16 +472,16 @@ def test_ordered_combine(self):
472472
# The order of the [paths] setting matters
473473
def make_data_file():
474474
data = coverage.CoverageData(".coverage.1")
475-
data.add_lines({os.path.abspath('ci/girder/g1.py'): dict.fromkeys(range(10))})
476-
data.add_lines({os.path.abspath('ci/girder/plugins/p1.py'): dict.fromkeys(range(10))})
475+
data.add_lines({abs_file('ci/girder/g1.py'): dict.fromkeys(range(10))})
476+
data.add_lines({abs_file('ci/girder/plugins/p1.py'): dict.fromkeys(range(10))})
477477
data.write()
478478

479479
def get_combined_filenames():
480480
cov = coverage.Coverage()
481481
cov.combine()
482482
cov.save()
483483
data = cov.get_data()
484-
filenames = {os.path.relpath(f).replace("\\", "/") for f in data.measured_files()}
484+
filenames = {relative_filename(f).replace("\\", "/") for f in data.measured_files()}
485485
return filenames
486486

487487
# Case 1: get the order right.

tests/test_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FilesTest(CoverageTest):
2525

2626
def abs_path(self, p):
2727
"""Return the absolute path for `p`."""
28-
return os.path.join(os.getcwd(), os.path.normpath(p))
28+
return os.path.join(abs_file(os.getcwd()), os.path.normpath(p))
2929

3030
def test_simple(self):
3131
self.make_file("hello.py")

tests/test_html.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import coverage
1919
from coverage.backward import unicode_class
2020
from coverage import env
21-
from coverage.files import flat_rootname
21+
from coverage.files import abs_file, flat_rootname
2222
import coverage.html
2323
from coverage.misc import CoverageException, NotPython, NoSource
2424
from coverage.report import get_analysis_to_report
@@ -635,6 +635,8 @@ def compare_html(expected, actual):
635635
# The temp dir the tests make.
636636
(filepath_to_regex(os.getcwd()), 'TEST_TMPDIR'),
637637
(filepath_to_regex(flat_rootname(unicode_class(os.getcwd()))), '_TEST_TMPDIR'),
638+
(filepath_to_regex(abs_file(os.getcwd())), 'TEST_TMPDIR'),
639+
(filepath_to_regex(flat_rootname(unicode_class(abs_file(os.getcwd())))), '_TEST_TMPDIR'),
638640
(r'/private/var/folders/[\w/]{35}/coverage_test/tests_test_html_\w+_\d{8}', 'TEST_TMPDIR'),
639641
(r'_private_var_folders_\w{35}_coverage_test_tests_test_html_\w+_\d{8}', '_TEST_TMPDIR'),
640642
]

tests/test_process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import coverage
2121
from coverage import env
2222
from coverage.data import line_counts
23-
from coverage.files import python_reported_file
23+
from coverage.files import abs_file, python_reported_file
2424
from coverage.misc import output_encoding
2525

2626
from tests.coveragetest import CoverageTest, TESTS_DIR, xfail
@@ -390,8 +390,8 @@ def test_combine_with_aliases(self):
390390
data.read()
391391
summary = line_counts(data, fullpath=True)
392392
self.assertEqual(len(summary), 1)
393-
actual = os.path.normcase(os.path.abspath(list(summary.keys())[0]))
394-
expected = os.path.normcase(os.path.abspath('src/x.py'))
393+
actual = abs_file(list(summary.keys())[0])
394+
expected = abs_file('src/x.py')
395395
self.assertEqual(expected, actual)
396396
self.assertEqual(list(summary.values())[0], 6)
397397

0 commit comments

Comments
 (0)