Skip to content

Commit

Permalink
Add tests to issue nedbat#1752
Browse files Browse the repository at this point in the history
  • Loading branch information
BruDriguezz committed Mar 14, 2024
1 parent 3d57a07 commit ab886fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
3 changes: 3 additions & 0 deletions coverage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ def map(self, path: str, exists:Callable[[str], bool] = source_exists) -> str:

# If we get here, no pattern matched.

if self.relative:
path = relative_filename(path)

if self.relative and not isabs_anywhere(path):
# Auto-generate a pattern to implicitly match relative files
parts = re.split(r"[/\\]", path)
Expand Down
57 changes: 45 additions & 12 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,6 @@ def get_combined_filenames() -> set[str]:
filenames = {relative_filename(f).replace("\\", "/") for f in data.measured_files()}
return filenames

# Case 1: get the order right.
make_files()
self.make_file(".coveragerc", """\
[paths]
plugins =
plugins/
ci/girder/plugins/
girder =
girder/
ci/girder/
""")
assert get_combined_filenames() == {'girder/g1.py', 'plugins/p1.py'}

# Case 2: get the order "wrong".
make_files()
Expand All @@ -526,6 +514,51 @@ def get_combined_filenames() -> set[str]:
""")
assert get_combined_filenames() == {'girder/g1.py', 'plugins/p1.py'}

def test_combine_remapping(self) -> None:
self.make_file("foo.py", text="print('Hello from Foo!')")
self.make_file("bar.py", text="print('Hello from Bar!')")

cov_foo = coverage.Coverage(source=["."], data_suffix="foo_cov.data")
self.start_import_stop(cov_foo, "foo")
cov_foo.save()

cov_bar = coverage.Coverage(source=["."], data_suffix="bar_cov.data")
self.start_import_stop(cov_bar, "bar")
cov_bar.save()

# Since the issue seems to be focused around the
# given order of the paths, absolute or otherwise
# So, we'll be testing both ways; absolute and relative, and relative and absolute
# Truthfully, I'm not entirely sure if it makes a difference - but let's see.

cov1 = coverage.Coverage()
cov1.combine(data_paths=[".coverage.foo_cov.data", ".coverage.bar_cov.data"])
files1 = cov1.get_data().measured_files()


# Since the files are combined, they cease to exist after `cov1.combine()`.
# So the files need to be measured again.
# This is mostly certainly *not* staying like this, but Ill leave it as
# To test if the testing logic is truly correct - which should be, but let's see
# what Ned says.

cov_foo = coverage.Coverage(source=["."], data_suffix="foo_cov.data")
self.start_import_stop(cov_foo, "foo")
cov_foo.save()

cov_bar = coverage.Coverage(source=["."], data_suffix="bar_cov.data")
self.start_import_stop(cov_bar, "bar")
cov_bar.save()

# Combine the data files in the opposite order.
cov2 = coverage.Coverage()
cov2.combine(data_paths=[".coverage.bar_cov.data", ".coverage.foo_cov.data"])
files2 = cov2.get_data().measured_files()

# The order of combining should not affect the resulting files.
assert set(files1) == set(files2)
assert set(files2) == set(files1)

def test_warnings(self) -> None:
self.make_file("hello.py", """\
import sys, os
Expand Down

0 comments on commit ab886fe

Please sign in to comment.