Skip to content

Commit

Permalink
test: add more tests nedbat#684
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Rusak authored and nedbat committed Dec 2, 2023
1 parent 962ca96 commit fdb6841
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/coveragetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def check_coverage(
# Get the analysis results, and check that they are right.
analysis = cov._analyze(mod)
statements = sorted(analysis.statements)
if lines is not None:
if lines is not None and len(lines) != 0:
if isinstance(lines[0], int):
# lines is just a list of numbers, it must match the statements
# found in the code.
Expand Down
68 changes: 60 additions & 8 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,14 +1405,6 @@ def test_excluding_for_suite(self) -> None:
assert a == 1
""",
[1,7], "", excludes=['#pragma: NO COVER'])
self.check_coverage("""\
a = 0
def very_long_function_to_exclude_name(very_long_argument1,
very_long_argument2):
pass
assert a == 0
""",
[1,5], "", excludes=['function_to_exclude'])

def test_excluding_for_else(self) -> None:
self.check_coverage("""\
Expand Down Expand Up @@ -1554,6 +1546,50 @@ def fn(foo): #pragma: NO COVER
""",
[6,7], "", excludes=['#pragma: NO COVER'])

self.check_coverage("""\
a = 0
def very_long_function_to_exclude_name(very_long_argument1,
very_long_argument2):
pass
assert a == 0
""",
[1,5], "", excludes=['function_to_exclude'])

self.check_coverage("""\
a = 0
def very_long_function_to_exclude_name(
very_long_argument1,
very_long_argument2
):
pass
assert a == 0
""",
[1,7], "", excludes=['function_to_exclude'])

self.check_coverage("""\
def my_func(
super_long_input_argument_0=0,
super_long_input_argument_1=1,
super_long_input_argument_2=2):
pass
def my_func_2(super_long_input_argument_0=0, super_long_input_argument_1=1, super_long_input_argument_2=2):
pass
""",
[], "", excludes=['my_func'])

self.check_coverage("""\
def my_func(
super_long_input_argument_0=0,
super_long_input_argument_1=1,
super_long_input_argument_2=2):
pass
def my_func_2(super_long_input_argument_0=0, super_long_input_argument_1=1, super_long_input_argument_2=2):
pass
""",
[1,5], "5", excludes=['my_func_2'])

def test_excluding_method(self) -> None:
self.check_coverage("""\
class Fooey:
Expand All @@ -1568,6 +1604,22 @@ def foo(self): #pragma: NO COVER
""",
[1,2,3,8,9], "", excludes=['#pragma: NO COVER'])

self.check_coverage("""\
class Fooey:
def __init__(self):
self.a = 1
def very_long_method_to_exclude_name(
very_long_argument1,
very_long_argument2
):
pass
x = Fooey()
assert x.a == 1
""",
[1,2,3,11,12], "", excludes=['method_to_exclude'])

def test_excluding_class(self) -> None:
self.check_coverage("""\
class Fooey: #pragma: NO COVER
Expand Down

0 comments on commit fdb6841

Please sign in to comment.