Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicating paths during remapping #1755

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A key indication of whether the test is doing what it should: comment out "the fix" and see if the test fails. When I comment out these two lines, all the tests still pass.

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you removed this test code.

make_files()
self.make_file(".coveragerc", """\
[paths]
plugins =
plugins/
ci/girder/plugins/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird; I didn't touch this, and these files remain on my local repository. Go figure, I'll check it out later.

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, this is pretty obvious; so that's a stupid check to take away.

assert set(files2) == set(files1)

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