Skip to content

Commit c6a5c8d

Browse files
committed
Implement tests
1 parent 25848f4 commit c6a5c8d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

testing/code/test_excinfo.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,23 @@ def f():
11031103
assert line.endswith("mod.py")
11041104
assert tw_mock.lines[12] == ":3: ValueError"
11051105

1106+
def test_toterminal_value(self, importasmod, tw_mock):
1107+
mod = importasmod(
1108+
"""
1109+
def g(x):
1110+
raise ValueError(x)
1111+
def f():
1112+
g('some_value')
1113+
"""
1114+
)
1115+
excinfo = pytest.raises(ValueError, mod.f)
1116+
excinfo.traceback = excinfo.traceback.filter(excinfo)
1117+
repr = excinfo.getrepr(style="value")
1118+
repr.toterminal(tw_mock)
1119+
1120+
assert tw_mock.get_write_msg(0) == "some_value"
1121+
assert tw_mock.get_write_msg(1) == "\n"
1122+
11061123
def test_toterminal_long_missing_source(
11071124
self, importasmod, tmp_path: Path, tw_mock
11081125
) -> None:
@@ -1250,8 +1267,6 @@ def i():
12501267
)
12511268
r = excinfo.getrepr(style="long")
12521269
r.toterminal(tw_mock)
1253-
for line in tw_mock.lines:
1254-
print(line)
12551270
assert tw_mock.lines[0] == ""
12561271
assert tw_mock.lines[1] == " def f():"
12571272
assert tw_mock.lines[2] == "> g()"

testing/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def markup(self, text, **kw):
119119
return text
120120

121121
def get_write_msg(self, idx):
122-
flag, msg = self.lines[idx]
123-
assert flag == TWMock.WRITE
122+
assert self.lines[idx][0] == TWMock.WRITE
123+
msg = self.lines[idx][1]
124124
return msg
125125

126126
fullwidth = 80

0 commit comments

Comments
 (0)