Skip to content

Commit 5554b67

Browse files
committed
waste time dealing with bad unicode test env. life
1 parent 964bdd3 commit 5554b67

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

Lib/test/test_traceback_timestamps.py

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,71 +46,67 @@ def cause_exception():
4646
def test_no_traceback_timestamps(self):
4747
"""Test that traceback timestamps are not shown by default"""
4848
result = script_helper.assert_python_ok(self.script_path)
49-
stderr = result.err.decode()
50-
self.assertNotIn("<@", stderr) # No timestamp should be present
49+
self.assertNotIn(b"<@", result.err) # No timestamp should be present
5150

5251
def test_traceback_timestamps_env_var(self):
5352
"""Test that PYTHON_TRACEBACK_TIMESTAMPS env var enables timestamps"""
5453
result = script_helper.assert_python_ok(
5554
self.script_path, PYTHON_TRACEBACK_TIMESTAMPS="us"
5655
)
57-
stderr = result.err.decode()
58-
self.assertIn("<@", stderr) # Timestamp should be present
56+
self.assertIn(b"<@", result.err) # Timestamp should be present
5957

6058
def test_traceback_timestamps_flag_us(self):
6159
"""Test -X traceback_timestamps=us flag"""
6260
result = script_helper.assert_python_ok(
6361
"-X", "traceback_timestamps=us", self.script_path
6462
)
65-
stderr = result.err.decode()
66-
self.assertIn("<@", stderr) # Timestamp should be present
63+
self.assertIn(b"<@", result.err) # Timestamp should be present
6764

6865
def test_traceback_timestamps_flag_ns(self):
6966
"""Test -X traceback_timestamps=ns flag"""
7067
result = script_helper.assert_python_ok(
7168
"-X", "traceback_timestamps=ns", self.script_path
7269
)
73-
stderr = result.err.decode()
74-
self.assertIn("<@", stderr) # Timestamp should be present
75-
self.assertIn("ns>", stderr) # Should have ns format
70+
stderr = result.err
71+
self.assertIn(b"<@", result.err) # Timestamp should be present
72+
self.assertIn(b"ns>", result.err) # Should have ns format
7673

7774
def test_traceback_timestamps_flag_iso(self):
7875
"""Test -X traceback_timestamps=iso flag"""
7976
result = script_helper.assert_python_ok(
8077
"-X", "traceback_timestamps=iso", self.script_path
8178
)
82-
stderr = result.err.decode()
83-
self.assertIn("<@", stderr) # Timestamp should be present
79+
self.assertIn(b"<@", result.err) # Timestamp should be present
8480
# ISO format with Z suffix for UTC
85-
self.assertRegex(stderr, r"<@\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z>")
81+
self.assertRegex(result.err, br"<@\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z>")
8682

8783
def test_traceback_timestamps_flag_value(self):
8884
"""Test that sys.flags.traceback_timestamps shows the right value"""
8985
# Default should be empty string
9086
result = script_helper.assert_python_ok(self.flags_script_path)
91-
stdout = result.out.decode().strip()
92-
self.assertEqual(stdout, "''")
87+
stdout = result.out.strip()
88+
self.assertEqual(stdout, b"''")
9389

9490
# With us flag
9591
result = script_helper.assert_python_ok(
9692
"-X", "traceback_timestamps=us", self.flags_script_path
9793
)
98-
stdout = result.out.decode().strip()
99-
self.assertEqual(stdout, "'us'")
94+
stdout = result.out.strip()
95+
self.assertEqual(stdout, b"'us'")
10096

10197
# With ns flag
10298
result = script_helper.assert_python_ok(
10399
"-X", "traceback_timestamps=ns", self.flags_script_path
104100
)
105-
stdout = result.out.decode().strip()
106-
self.assertEqual(stdout, "'ns'")
101+
stdout = result.out.strip()
102+
self.assertEqual(stdout, b"'ns'")
107103

108104
# With iso flag
109105
result = script_helper.assert_python_ok(
110106
"-X", "traceback_timestamps=iso", self.flags_script_path
111107
)
112-
stdout = result.out.decode().strip()
113-
self.assertEqual(stdout, "'iso'")
108+
stdout = result.out.strip()
109+
self.assertEqual(stdout, b"'iso'")
114110

115111
def test_traceback_timestamps_env_var_precedence(self):
116112
"""Test that -X flag takes precedence over env var"""
@@ -121,72 +117,70 @@ def test_traceback_timestamps_env_var_precedence(self):
121117
"import sys; print(repr(sys.flags.traceback_timestamps))",
122118
PYTHON_TRACEBACK_TIMESTAMPS="ns",
123119
)
124-
stdout = result.out.decode().strip()
125-
self.assertEqual(stdout, "'us'")
120+
stdout = result.out.strip()
121+
self.assertEqual(stdout, b"'us'")
126122

127123
def test_traceback_timestamps_flag_no_value(self):
128124
"""Test -X traceback_timestamps with no value defaults to 'us'"""
129125
result = script_helper.assert_python_ok(
130126
"-X", "traceback_timestamps", self.flags_script_path
131127
)
132-
stdout = result.out.decode().strip()
133-
self.assertEqual(stdout, "'us'")
128+
stdout = result.out.strip()
129+
self.assertEqual(stdout, b"'us'")
134130

135131
def test_traceback_timestamps_flag_zero(self):
136132
"""Test -X traceback_timestamps=0 disables the feature"""
137133
# Check that setting to 0 results in empty string in sys.flags
138134
result = script_helper.assert_python_ok(
139135
"-X", "traceback_timestamps=0", self.flags_script_path
140136
)
141-
stdout = result.out.decode().strip()
142-
self.assertEqual(stdout, "''")
137+
stdout = result.out.strip()
138+
self.assertEqual(stdout, b"''")
143139

144140
# Check that no timestamps appear in traceback
145141
result = script_helper.assert_python_ok(
146142
"-X", "traceback_timestamps=0", self.script_path
147143
)
148-
stderr = result.err.decode()
149-
self.assertNotIn("<@", stderr) # No timestamp should be present
144+
self.assertNotIn(b"<@", result.err) # No timestamp should be present
150145

151146
def test_traceback_timestamps_flag_one(self):
152147
"""Test -X traceback_timestamps=1 is equivalent to 'us'"""
153148
result = script_helper.assert_python_ok(
154149
"-X", "traceback_timestamps=1", self.flags_script_path
155150
)
156-
stdout = result.out.decode().strip()
157-
self.assertEqual(stdout, "'us'")
151+
stdout = result.out.strip()
152+
self.assertEqual(stdout, b"'us'")
158153

159154
def test_traceback_timestamps_env_var_zero(self):
160155
"""Test PYTHON_TRACEBACK_TIMESTAMPS=0 disables the feature"""
161156
result = script_helper.assert_python_ok(
162157
self.flags_script_path, PYTHON_TRACEBACK_TIMESTAMPS="0"
163158
)
164-
stdout = result.out.decode().strip()
165-
self.assertEqual(stdout, "''")
159+
stdout = result.out.strip()
160+
self.assertEqual(stdout, b"''")
166161

167162
def test_traceback_timestamps_env_var_one(self):
168163
"""Test PYTHON_TRACEBACK_TIMESTAMPS=1 is equivalent to 'us'"""
169164
result = script_helper.assert_python_ok(
170165
self.flags_script_path, PYTHON_TRACEBACK_TIMESTAMPS="1"
171166
)
172-
stdout = result.out.decode().strip()
173-
self.assertEqual(stdout, "'us'")
167+
stdout = result.out.strip()
168+
self.assertEqual(stdout, b"'us'")
174169

175170
def test_traceback_timestamps_invalid_env_var(self):
176171
"""Test that invalid env var values are silently ignored"""
177172
result = script_helper.assert_python_ok(
178173
self.flags_script_path, PYTHON_TRACEBACK_TIMESTAMPS="invalid"
179174
)
180-
stdout = result.out.decode().strip()
181-
self.assertEqual(stdout, "''") # Should default to empty string
175+
stdout = result.out.strip()
176+
self.assertEqual(stdout, b"''") # Should default to empty string
182177

183178
def test_traceback_timestamps_invalid_flag(self):
184179
"""Test that invalid flag values cause an error"""
185180
result = script_helper.assert_python_failure(
186181
"-X", "traceback_timestamps=invalid", self.flags_script_path
187182
)
188-
stderr = result.err.decode()
189-
self.assertIn("Invalid -X traceback_timestamps=value option", stderr)
183+
self.assertIn(b"Invalid -X traceback_timestamps=value option", result.err)
190184

191185

192186
class StripExcTimestampsTests(unittest.TestCase):
@@ -224,14 +218,14 @@ def test_strip_exc_timestamps_function(self):
224218
"-X", f"traceback_timestamps={mode}",
225219
self.script_strip_path
226220
)
227-
output = result.out.decode() + result.err.decode()
221+
output = result.out.decode() + result.err.decode(errors='replace')
228222

229223
# call strip_exc_timestamps in a process using the same mode as what generated our output.
230224
result = script_helper.assert_python_ok(
231225
"-X", f"traceback_timestamps={mode}",
232226
self.script_strip_path, output
233227
)
234-
stripped_output = result.out.decode() + result.err.decode()
228+
stripped_output = result.out.decode() + result.err.decode(errors='replace')
235229

236230
# Verify original strings have timestamps and stripped ones don't
237231
self.assertIn("ZeroDivisionError: division by zero <@", output)
@@ -246,13 +240,13 @@ def test_strip_exc_timestamps_with_disabled_timestamps(self):
246240
result = script_helper.assert_python_failure(
247241
"-X", "traceback_timestamps=0", self.script_strip_path
248242
)
249-
output = result.out.decode() + result.err.decode()
243+
output = result.out.decode() + result.err.decode(errors='replace')
250244

251245
# call strip_exc_timestamps in a process using the same mode as what generated our output.
252246
result = script_helper.assert_python_ok(
253247
"-X", "traceback_timestamps=0", self.script_strip_path, output
254248
)
255-
stripped_output = result.out.decode() + result.err.decode()
249+
stripped_output = result.out.decode() + result.err.decode(errors='replace')
256250

257251
# All strings should be unchanged by the strip function
258252
self.assertIn("ZeroDivisionError: division by zero\n", stripped_output)

0 commit comments

Comments
 (0)