Skip to content

Commit

Permalink
Test when line number is out-of-bounds and negative
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp authored and Kodiologist committed Apr 5, 2023
1 parent cd97c11 commit c57a952
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Ionuț Turturică
Itxaso Aizpurua
Iwan Briquemont
Jaap Broekhuizen
Jake VanderPlas
Jakob van Santen
Jakub Mitoraj
James Bourbeau
Expand Down
18 changes: 18 additions & 0 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@ def f(x):
assert lines[0] == "| def f(x):"
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:
"""Check if indentation is right."""
try:
Expand Down

0 comments on commit c57a952

Please sign in to comment.