@@ -39,10 +39,9 @@ def cause_exception():
3939 self .addCleanup (unlink , self .flags_script_path )
4040
4141 self .env = EnvironmentVarGuard ()
42- self .env .set (' PYTHONUTF8' , '1' ) # -X utf8=1
42+ self .env .set (" PYTHONUTF8" , "1" ) # -X utf8=1
4343 self .addCleanup (self .env .__exit__ )
4444
45-
4645 def test_no_traceback_timestamps (self ):
4746 """Test that traceback timestamps are not shown by default"""
4847 result = script_helper .assert_python_ok (self .script_path )
@@ -78,7 +77,9 @@ def test_traceback_timestamps_flag_iso(self):
7877 )
7978 self .assertIn (b"<@" , result .err ) # Timestamp should be present
8079 # ISO format with Z suffix for UTC
81- self .assertRegex (result .err , br"<@\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z>" )
80+ self .assertRegex (
81+ result .err , rb"<@\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z>"
82+ )
8283
8384 def test_traceback_timestamps_flag_value (self ):
8485 """Test that sys.flags.traceback_timestamps shows the right value"""
@@ -180,7 +181,9 @@ def test_traceback_timestamps_invalid_flag(self):
180181 result = script_helper .assert_python_failure (
181182 "-X" , "traceback_timestamps=invalid" , self .flags_script_path
182183 )
183- self .assertIn (b"Invalid -X traceback_timestamps=value option" , result .err )
184+ self .assertIn (
185+ b"Invalid -X traceback_timestamps=value option" , result .err
186+ )
184187
185188
186189class StripExcTimestampsTests (unittest .TestCase ):
@@ -215,23 +218,37 @@ def test_strip_exc_timestamps_function(self):
215218 for mode in ("us" , "ns" , "iso" ):
216219 with self .subTest (mode ):
217220 result = script_helper .assert_python_failure (
218- "-X" , f"traceback_timestamps={ mode } " ,
219- self .script_strip_path
221+ "-X" ,
222+ f"traceback_timestamps={ mode } " ,
223+ self .script_strip_path ,
224+ )
225+ output = result .out .decode () + result .err .decode (
226+ errors = "ignore"
220227 )
221- output = result .out .decode () + result .err .decode (errors = 'ignore' )
222228
223229 # call strip_exc_timestamps in a process using the same mode as what generated our output.
224230 result = script_helper .assert_python_ok (
225- "-X" , f"traceback_timestamps={ mode } " ,
226- self .script_strip_path , output
231+ "-X" ,
232+ f"traceback_timestamps={ mode } " ,
233+ self .script_strip_path ,
234+ output ,
235+ )
236+ stripped_output = result .out .decode () + result .err .decode (
237+ errors = "ignore"
227238 )
228- stripped_output = result .out .decode () + result .err .decode (errors = 'ignore' )
229239
230240 # Verify original strings have timestamps and stripped ones don't
231241 self .assertIn ("ZeroDivisionError: division by zero <@" , output )
232- self .assertNotRegex (output , "(?m)ZeroDivisionError: division by zero(\n |\r |$)" )
233- self .assertRegex (stripped_output , "(?m)ZeroDivisionError: division by zero(\r |\n |$)" )
234- self .assertRegex (stripped_output , "(?m)FakeError: not an exception(\r |\n |$)" )
242+ self .assertNotRegex (
243+ output , "(?m)ZeroDivisionError: division by zero(\n |\r |$)"
244+ )
245+ self .assertRegex (
246+ stripped_output ,
247+ "(?m)ZeroDivisionError: division by zero(\r |\n |$)" ,
248+ )
249+ self .assertRegex (
250+ stripped_output , "(?m)FakeError: not an exception(\r |\n |$)"
251+ )
235252
236253 @force_not_colorized
237254 def test_strip_exc_timestamps_with_disabled_timestamps (self ):
@@ -240,24 +257,31 @@ def test_strip_exc_timestamps_with_disabled_timestamps(self):
240257 result = script_helper .assert_python_failure (
241258 "-X" , "traceback_timestamps=0" , self .script_strip_path
242259 )
243- output = result .out .decode () + result .err .decode (errors = ' ignore' )
260+ output = result .out .decode () + result .err .decode (errors = " ignore" )
244261
245262 # call strip_exc_timestamps in a process using the same mode as what generated our output.
246263 result = script_helper .assert_python_ok (
247264 "-X" , "traceback_timestamps=0" , self .script_strip_path , output
248265 )
249- stripped_output = result .out .decode () + result .err .decode (errors = 'ignore' )
266+ stripped_output = result .out .decode () + result .err .decode (
267+ errors = "ignore"
268+ )
250269
251270 # All strings should be unchanged by the strip function
252- self .assertRegex (stripped_output , "(?m)ZeroDivisionError: division by zero(\r |\n |$)" )
271+ self .assertRegex (
272+ stripped_output , "(?m)ZeroDivisionError: division by zero(\r |\n |$)"
273+ )
253274 # it fits the pattern but traceback timestamps were disabled to strip_exc_timestamps does nothing.
254275 self .assertRegex (
255- stripped_output , "(?m)FakeError: not an exception <@1234567890.123456>(\r |\n |$)"
276+ stripped_output ,
277+ "(?m)FakeError: not an exception <@1234567890.123456>(\r |\n |$)" ,
256278 )
257279
258280 def test_timestamp_regex_pattern (self ):
259281 """Test the regex pattern used by strip_exc_timestamps"""
260- pattern = re .compile (TIMESTAMP_AFTER_EXC_MSG_RE_GROUP , flags = re .MULTILINE )
282+ pattern = re .compile (
283+ TIMESTAMP_AFTER_EXC_MSG_RE_GROUP , flags = re .MULTILINE
284+ )
261285
262286 # Test microsecond format
263287 self .assertTrue (pattern .search (" <@1234567890.123456>" ))
@@ -268,7 +292,9 @@ def test_timestamp_regex_pattern(self):
268292
269293 # Test what should not match
270294 self .assertFalse (pattern .search ("<@>" )) # Empty timestamp
271- self .assertFalse (pattern .search (" <1234567890.123456>" )) # Missing @ sign
295+ self .assertFalse (
296+ pattern .search (" <1234567890.123456>" )
297+ ) # Missing @ sign
272298 self .assertFalse (pattern .search ("<@abc>" )) # Non-numeric timestamp
273299
274300
0 commit comments