Test when line number is out-of-bounds and negative

This commit is contained in:
Jake VanderPlas 2023-04-04 16:58:56 -07:00 committed by Kodi Arfer
parent cd97c110ca
commit c57a9527cf
2 changed files with 19 additions and 0 deletions

View File

@ -163,6 +163,7 @@ Ionuț Turturică
Itxaso Aizpurua Itxaso Aizpurua
Iwan Briquemont Iwan Briquemont
Jaap Broekhuizen Jaap Broekhuizen
Jake VanderPlas
Jakob van Santen Jakob van Santen
Jakub Mitoraj Jakub Mitoraj
James Bourbeau James Bourbeau

View File

@ -461,6 +461,24 @@ class TestFormattedExcinfo:
assert lines[0] == "| def f(x):" assert lines[0] == "| def f(x):"
assert lines[1] == " pass" assert lines[1] == " pass"
def test_repr_source_out_of_bounds(self):
pr = FormattedExcinfo()
source = _pytest._code.Source(
"""\
def f(x):
pass
"""
).strip()
pr.flow_marker = "|" # type: ignore[misc]
lines = pr.get_source(source, 100)
assert len(lines) == 1
assert lines[0] == "| ???"
lines = pr.get_source(source, -100)
assert len(lines) == 1
assert lines[0] == "| ???"
def test_repr_source_excinfo(self) -> None: def test_repr_source_excinfo(self) -> None:
"""Check if indentation is right.""" """Check if indentation is right."""
try: try: