MCPcopy Index your code
hub / github.com/python/cpython / test_original_unraisablehook

Method test_original_unraisablehook

Lib/test/test_sys.py:1366–1397  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1364@test.support.force_not_colorized_test_class
1365class UnraisableHookTest(unittest.TestCase):
1366 def test_original_unraisablehook(self):
1367 _testcapi = import_helper.import_module('_testcapi')
1368 from _testcapi import err_writeunraisable, err_formatunraisable
1369 obj = hex
1370
1371 with support.swap_attr(sys, 'unraisablehook',
1372 sys.__unraisablehook__):
1373 with support.captured_stderr() as stderr:
1374 err_writeunraisable(ValueError(42), obj)
1375 lines = stderr.getvalue().splitlines()
1376 self.assertEqual(lines[0], f'Exception ignored in: {obj!r}')
1377 self.assertEqual(lines[1], 'Traceback (most recent call last):')
1378 self.assertEqual(lines[-1], 'ValueError: 42')
1379
1380 with support.captured_stderr() as stderr:
1381 err_writeunraisable(ValueError(42), None)
1382 lines = stderr.getvalue().splitlines()
1383 self.assertEqual(lines[0], 'Traceback (most recent call last):')
1384 self.assertEqual(lines[-1], 'ValueError: 42')
1385
1386 with support.captured_stderr() as stderr:
1387 err_formatunraisable(ValueError(42), 'Error in %R', obj)
1388 lines = stderr.getvalue().splitlines()
1389 self.assertEqual(lines[0], f'Error in {obj!r}:')
1390 self.assertEqual(lines[1], 'Traceback (most recent call last):')
1391 self.assertEqual(lines[-1], 'ValueError: 42')
1392
1393 with support.captured_stderr() as stderr:
1394 err_formatunraisable(ValueError(42), None)
1395 lines = stderr.getvalue().splitlines()
1396 self.assertEqual(lines[0], 'Traceback (most recent call last):')
1397 self.assertEqual(lines[-1], 'ValueError: 42')
1398
1399 def test_original_unraisablehook_err(self):
1400 # bpo-22836: PyErr_WriteUnraisable() should give sensible reports

Callers

nothing calls this directly

Calls 4

import_moduleMethod · 0.45
splitlinesMethod · 0.45
getvalueMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected