Skip to content

Commit 0c902ec

Browse files
committed
Strengthen all tests
1 parent 368050e commit 0c902ec

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

src/_pytest/_code/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
10481048
self.reprfileloc.toterminal(tw)
10491049
tw.write_source(source)
10501050
for line in traceback_lines.explanations:
1051-
tw.line(line, red=True, bold=True)
1051+
tw.line(line, bold=True, red=True)
10521052
if self.reprlocals:
10531053
self.reprlocals.toterminal(tw, indent=" " * 8)
10541054
return
@@ -1058,7 +1058,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
10581058

10591059
tw.write_source(source)
10601060
for line in traceback_lines.explanations:
1061-
tw.line(line, red=True, bold=True)
1061+
tw.line(line, bold=True, red=True)
10621062

10631063
if self.reprlocals:
10641064
tw.line("")

src/_pytest/_io/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def write_source(self, source: str) -> None:
1414

1515
def _highlight(self, source):
1616
"""Highlight the given source code according to the "code_highlight" option"""
17-
if not self.hasmarkup and 0:
17+
if not self.hasmarkup:
1818
return source
1919
try:
2020
from pygments.formatters.terminal import TerminalFormatter
@@ -32,8 +32,8 @@ class ParsedTraceback:
3232
errors = attr.ib() # type: Tuple[str, ...]
3333
explanations = attr.ib() # type: Tuple[str, ...]
3434

35-
ERROR_PREFIX = "> "
36-
EXPLANATION_PREFIX = "E "
35+
ERROR_PREFIX = "> "
36+
EXPLANATION_PREFIX = "E "
3737

3838
class State(Enum):
3939
source = auto()
@@ -51,8 +51,9 @@ def from_lines(cls, lines: Sequence[str]) -> "ParsedTraceback":
5151
for line in lines:
5252
if state == cls.State.source and line.startswith(cls.ERROR_PREFIX):
5353
state = cls.State.error
54-
elif state == cls.State.error and line.startswith(cls.EXPLANATION_PREFIX):
54+
if line.startswith(cls.EXPLANATION_PREFIX):
5555
state = cls.State.explanation
56+
5657
if state == cls.State.source:
5758
sources.append(line)
5859
elif state == cls.State.error:

testing/code/test_code.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,14 @@ def test_with_continuations(self):
226226
"E assert 1 == 2\n",
227227
"E + where 2 = z()\n",
228228
)
229+
230+
def test_no_flow_lines(self):
231+
lines = [
232+
" assert 0\n",
233+
"E assert 0\n",
234+
]
235+
236+
result = ParsedTraceback.from_lines(lines)
237+
assert result.sources == (" assert 0\n",)
238+
assert result.errors == ()
239+
assert result.explanations == ("E assert 0\n",)

testing/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def write(self, msg, **kw):
7979

8080
def write_source(self, source):
8181
for line in source.splitlines():
82-
self.line(source)
82+
self.line(line)
8383

8484
def line(self, line, **kw):
8585
self.lines.append(line)

testing/test_terminal.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,16 @@ def test_this():
920920
"=*= FAILURES =*=",
921921
"{red}{bold}_*_ test_this _*_{reset}",
922922
"",
923+
" {kw}def{hl-reset} {function}test_this{hl-reset}():",
924+
"> fail()",
925+
"",
923926
"{bold}{red}test_color_yes.py{reset}:5: ",
924927
"_ _ * _ _*",
925928
"",
929+
" {kw}def{hl-reset} {function}fail{hl-reset}():",
930+
"> {kw}assert{hl-reset} {number}0{hl-reset}",
931+
"{bold}{red}E assert 0{reset}",
932+
"",
926933
"{bold}{red}test_color_yes.py{reset}:2: AssertionError",
927934
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
928935
]
@@ -941,7 +948,10 @@ def test_this():
941948
"=*= FAILURES =*=",
942949
"{red}{bold}_*_ test_this _*_{reset}",
943950
"{bold}{red}test_color_yes.py{reset}:5: in test_this",
951+
" fail()",
944952
"{bold}{red}test_color_yes.py{reset}:2: in fail",
953+
" {kw}assert{hl-reset} {number}0{hl-reset}",
954+
"{bold}{red}E assert 0{reset}",
945955
"{red}=*= {red}{bold}1 failed{reset}{red} in *s{reset}{red} =*={reset}",
946956
]
947957
]
@@ -2029,7 +2039,7 @@ def test_foo():
20292039
for line in [
20302040
" {kw}def{hl-reset} {function}test_foo{hl-reset}():",
20312041
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}",
2032-
"{red}{bold}E assert 1 == 10{reset}",
2042+
"{bold}{red}E assert 1 == 10{reset}",
20332043
]
20342044
]
20352045
)

0 commit comments

Comments
 (0)