Skip to content

Commit

Permalink
test: add a test for skipping covered functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Apr 23, 2024
1 parent b115ed3 commit 583f0c0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def run_coverage(
def assert_htmlcov_files_exist(self) -> None:
"""Assert that all the expected htmlcov files exist."""
self.assert_exists("htmlcov/index.html")
self.assert_exists("htmlcov/function_index.html")
self.assert_exists("htmlcov/class_index.html")
self.assert_exists("htmlcov/main_file_py.html")
self.assert_exists("htmlcov/helper1_py.html")
self.assert_exists("htmlcov/helper2_py.html")
Expand Down Expand Up @@ -617,6 +619,26 @@ def normal():
res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True))
assert res == 100.0
self.assert_doesnt_exist("htmlcov/main_file_py.html")
# Since there are no files to report, we can't collect any region
# information, so there are no region-based index pages.
self.assert_doesnt_exist("htmlcov/function_index.html")
self.assert_doesnt_exist("htmlcov/class_index.html")

def test_report_skip_covered_100_functions(self) -> None:
self.make_file("main_file.py", """\
def normal():
print("z")
def abnormal():
print("a")
normal()
""")
res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True))
assert res == 80.0
self.assert_exists("htmlcov/main_file_py.html")
# We have a file to report, so we get function and class index pages,
# even though there are no classes.
self.assert_exists("htmlcov/function_index.html")
self.assert_exists("htmlcov/class_index.html")

def make_init_and_main(self) -> None:
"""Helper to create files for skip_empty scenarios."""
Expand Down

0 comments on commit 583f0c0

Please sign in to comment.