parametrize tests

fix tests

working coverage test

combine existing set tests under class
This commit is contained in:
Reagan Lee 2023-09-26 15:42:56 -07:00
parent b73b4c464c
commit f090a1b181
1 changed files with 84 additions and 34 deletions

View File

@ -1345,48 +1345,98 @@ def test_reprcompare_whitespaces() -> None:
] ]
def test_pytest_assertrepr_compare_integration(pytester: Pytester) -> None: @pytest.mark.parametrize("op", [">=", "<="])
def test_operators_not_set_for_full_coverage(op, pytester: Pytester) -> None:
pytester.makepyfile( pytester.makepyfile(
""" f"""
def test_hello(): def test_hello():
x = set(range(100)) x = ["hello x"]
y = x.copy() y = ["hello y"]
y.remove(50) assert x {op} y
assert x == y
""" """
) )
result = pytester.runpytest() result = pytester.runpytest()
result.stdout.fnmatch_lines( result.stdout.no_fnmatch_line(f"assert x {op} y")
[
"*def test_hello():*",
"*assert x == y*",
"*E*Extra items*left*",
"*E*50*",
"*= 1 failed in*",
]
)
def test_sequence_comparison_uses_repr(pytester: Pytester) -> None: class TestSetAssertions:
pytester.makepyfile( @pytest.mark.parametrize("op", [">=", ">", "<=", "<", "=="])
def test_set_extra_item(self, op, pytester: Pytester) -> None:
pytester.makepyfile(
f"""
def test_hello():
x = set("hello x")
y = set("hello y")
assert x {op} y
""" """
def test_hello(): )
x = set("hello x")
y = set("hello y") result = pytester.runpytest()
assert x == y result.stdout.fnmatch_lines(
""" [
) "*def test_hello():*",
result = pytester.runpytest() f"*assert x {op} y*",
result.stdout.fnmatch_lines( ]
[ )
"*def test_hello():*", if op in [">=", ">", "=="]:
"*assert x == y*", result.stdout.fnmatch_lines(
"*E*Extra items*left*", [
"*E*'x'*", "*E*Extra items in the right set:*",
"*E*Extra items*right*", "*E*'y'",
"*E*'y'*", ]
] )
) if op in ["<=", "<", "=="]:
result.stdout.fnmatch_lines(
[
"*E*Extra items in the left set:*",
"*E*'x'",
# "*E*50*",
]
)
assert True # only reached if no error above
@pytest.mark.parametrize("op", [">", "<", "!="])
def test_set_proper_superset_equal(self, pytester: Pytester, op) -> None:
pytester.makepyfile(
f"""
def test_hello():
x = set([1, 2, 3])
y = x.copy()
assert x {op} y
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*def test_hello():*",
f"*assert x {op} y*",
"*E*Both sets are equal*",
]
)
assert True # only reached if no error above
def test_pytest_assertrepr_compare_integration(self, pytester: Pytester) -> None:
pytester.makepyfile(
"""
def test_hello():
x = set(range(100))
y = x.copy()
y.remove(50)
assert x == y
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*def test_hello():*",
"*assert x == y*",
"*E*Extra items*left*",
"*E*50*",
"*= 1 failed in*",
]
)
def test_assertrepr_loaded_per_dir(pytester: Pytester) -> None: def test_assertrepr_loaded_per_dir(pytester: Pytester) -> None: