Skip to content

Commit

Permalink
tet: add tests to reproduce #1604 (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgibbons authored and nedbat committed Apr 27, 2023
1 parent 23717ce commit 3344a78
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,59 @@ def test_report_including(self) -> None:
assert "mycode.py " in report
assert self.last_line_squeezed(report) == "TOTAL 4 0 100%"

def test_report_include_relative_files_and_path(self) -> None:
"""
Test that when relative_files is True and a relative path to a module
is included, coverage is reported for the module.
Ref: https://github.com/nedbat/coveragepy/issues/1604
"""
self.make_mycode()
self.make_file(".coveragerc", """\
[run]
relative_files = true
""")
self.make_file("submodule/mycode.py", "import mycode")

cov = coverage.Coverage()
self.start_import_stop(cov, "submodule/mycode")
report = self.get_report(cov, include="submodule/mycode.py")

# Name Stmts Miss Cover
# ---------------------------------------
# submodule/mycode.py 1 0 100%
# ---------------------------------------
# TOTAL 1 0 100%

assert "submodule/mycode.py " in report
assert self.last_line_squeezed(report) == "TOTAL 1 0 100%"

def test_report_include_relative_files_and_wildcard_path(self) -> None:
self.make_mycode()
self.make_file(".coveragerc", """\
[run]
relative_files = true
""")
self.make_file("submodule/mycode.py", "import nested.submodule.mycode")
self.make_file("nested/submodule/mycode.py", "import mycode")

cov = coverage.Coverage()
self.start_import_stop(cov, "submodule/mycode")
report = self.get_report(cov, include="*/submodule/mycode.py")

# Name Stmts Miss Cover
# -------------------------------------------------
# nested/submodule/mycode.py 1 0 100%
# submodule/mycode.py 1 0 100%
# -------------------------------------------------
# TOTAL 2 0 100%

reported_files = [line.split()[0] for line in report.splitlines()[2:4]]
assert reported_files == [
"nested/submodule/mycode.py",
"submodule/mycode.py",
]

def test_omit_files_here(self) -> None:
# https://github.com/nedbat/coveragepy/issues/1407
self.make_file("foo.py", "")
Expand Down

0 comments on commit 3344a78

Please sign in to comment.