Skip to content

Commit c61c373

Browse files
committed
always use multiline output
1 parent b68445c commit c61c373

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

devtools/debug.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ def __init__(self, *, filename: str, lineno: int, frame: str, arguments: List[De
5757

5858
def __str__(self) -> str:
5959
template = '{s.filename}:{s.lineno} {s.frame}'
60-
if len(self.arguments) == 1:
61-
return (template + ': {a}').format(s=self, a=self.arguments[0])
62-
else:
63-
return (template + '\n {a}').format(s=self, a='\n '.join(str(a) for a in self.arguments))
60+
# turns out single line output is ugly
61+
# if len(self.arguments) == 1:
62+
# return (template + ': {a}').format(s=self, a=self.arguments[0])
63+
# else:
64+
return (template + '\n {a}').format(s=self, a='\n '.join(str(a) for a in self.arguments))
6465

6566
def __repr__(self) -> str:
6667
arguments = ' '.join(str(a) for a in self.arguments)
@@ -75,7 +76,9 @@ class Debug:
7576
ast.DictComp, ast.ListComp, ast.SetComp, ast.GeneratorExp
7677
)
7778

78-
def __init__(self, *, warnings: Optional[bool]=None, frame_context_length: int=50):
79+
def __init__(self, *,
80+
warnings: Optional[bool]=None,
81+
frame_context_length: int=50):
7982
if warnings is None:
8083
self._warnings = env_true('PY_DEVTOOLS_WARNINGS', 'TRUE')
8184
else:

tests/test_expr_render.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def test_simple():
1616
s = re.sub(':\d{2,}', ':<line no>', str(v))
1717
# print(s)
1818
assert (
19-
'tests/test_expr_render.py:<line no> test_simple: len(a) = 3 (int)'
19+
'tests/test_expr_render.py:<line no> test_simple\n'
20+
' len(a) = 3 (int)'
2021
) == s
2122

2223

@@ -59,7 +60,8 @@ def test_newline():
5960
s = re.sub(':\d{2,}', ':<line no>', str(v))
6061
# print(s)
6162
assert (
62-
'tests/test_expr_render.py:<line no> test_newline: foobar(1, 2, 3) = 6 (int)'
63+
'tests/test_expr_render.py:<line no> test_newline\n'
64+
' foobar(1, 2, 3) = 6 (int)'
6365
) == s
6466

6567

@@ -70,7 +72,8 @@ def test_trailing_bracket():
7072
s = re.sub(':\d{2,}', ':<line no>', str(v))
7173
# print(s)
7274
assert (
73-
'tests/test_expr_render.py:<line no> test_trailing_bracket: foobar(1, 2, 3) = 6 (int)'
75+
'tests/test_expr_render.py:<line no> test_trailing_bracket\n'
76+
' foobar(1, 2, 3) = 6 (int)'
7477
) == s
7578

7679

@@ -83,7 +86,8 @@ def test_multiline():
8386
s = re.sub(':\d{2,}', ':<line no>', str(v))
8487
# print(s)
8588
assert (
86-
'tests/test_expr_render.py:<line no> test_multiline: foobar(1, 2, 3) = 6 (int)'
89+
'tests/test_expr_render.py:<line no> test_multiline\n'
90+
' foobar(1, 2, 3) = 6 (int)'
8791
) == s
8892

8993

@@ -94,7 +98,8 @@ def test_multiline_trailing_bracket():
9498
s = re.sub(':\d{2,}', ':<line no>', str(v))
9599
# print(s)
96100
assert (
97-
'tests/test_expr_render.py:<line no> test_multiline_trailing_bracket: foobar(1, 2, 3 ) = 6 (int)'
101+
'tests/test_expr_render.py:<line no> test_multiline_trailing_bracket\n'
102+
' foobar(1, 2, 3 ) = 6 (int)'
98103
) == s
99104

100105

@@ -139,7 +144,7 @@ def test_multiple_trailing_lines():
139144
)
140145
s = re.sub(':\d{2,}', ':<line no>', str(v))
141146
assert (
142-
'tests/test_expr_render.py:<line no> test_multiple_trailing_lines: foobar( 1, 2, 3 ) = 6 (int)'
147+
'tests/test_expr_render.py:<line no> test_multiple_trailing_lines\n foobar( 1, 2, 3 ) = 6 (int)'
143148
) == s
144149

145150

@@ -165,7 +170,7 @@ def test_syntax_warning():
165170
assert '-1\n"' in str(warning.message)
166171
s = re.sub(':\d{2,}', ':<line no>', str(v))
167172
assert (
168-
'tests/test_expr_render.py:<line no> test_syntax_warning: 1 (int)'
173+
'tests/test_expr_render.py:<line no> test_syntax_warning\n 1 (int)'
169174
) == s
170175

171176

@@ -184,5 +189,5 @@ def test_no_syntax_warning():
184189
)
185190
)
186191
)
187-
assert 'test_no_syntax_warning: 1 (int)' in str(v)
192+
assert 'test_no_syntax_warning\n 1 (int)' in str(v)
188193
assert len(warning_checker) == 0

tests/test_main.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def test_func(v):
5555
assert p.returncode == 0, (p.stderr, p.stdout)
5656
assert p.stdout.replace(str(f), '/path/to/test.py') == (
5757
'running debug...\n'
58-
'/path/to/test.py:8 <module>: foobar = "hello world" (str) len=11\n'
58+
'/path/to/test.py:8 <module>\n'
59+
' foobar = "hello world" (str) len=11\n'
5960
'/path/to/test.py:4 test_func\n'
6061
' "in test func" (str) len=12\n'
6162
' v = 42 (int)\n'
@@ -68,7 +69,7 @@ def test_odd_path(mocker):
6869
mocked_relative_to = mocker.patch('pathlib.Path.relative_to')
6970
mocked_relative_to.side_effect = ValueError()
7071
v = debug.format('test')
71-
assert re.search('/.*?/test_main.py:\d{2,} test_odd_path: "test" \(str\) len=4', str(v)), v
72+
assert re.search('/.*?/test_main.py:\d{2,} test_odd_path\n "test" \(str\) len=4', str(v)), v
7273

7374

7475
def test_small_call_frame():
@@ -151,23 +152,23 @@ class Bar:
151152

152153
b = Bar()
153154
v = debug.format(b.y.x)
154-
assert 'test_attributes: b.y.x = 1 (int)' in str(v)
155+
assert 'test_attributes\n b.y.x = 1 (int)' in str(v)
155156

156157

157158
def test_eval():
158159
with pytest.warns(RuntimeWarning):
159160
v = eval('debug.format(1)')
160161

161-
assert str(v) == '<string>:1 <module>: 1 (int)'
162+
assert str(v) == '<string>:1 <module>\n 1 (int)'
162163

163164

164165
def test_warnings_disabled():
165166
debug_ = Debug(warnings=False)
166167
with pytest.warns(None) as warnings:
167168
v1 = eval('debug_.format(1)')
168-
assert str(v1) == '<string>:1 <module>: 1 (int)'
169+
assert str(v1) == '<string>:1 <module>\n 1 (int)'
169170
v2 = debug_.format(1)
170-
assert 'test_warnings_disabled: 1 (int)' in str(v2)
171+
assert 'test_warnings_disabled\n 1 (int)' in str(v2)
171172
assert len(warnings) == 0
172173

173174

0 commit comments

Comments
 (0)