Skip to content

Commit 19e863c

Browse files
committed
Add unit tests
Add test_sys to "./python -m test --tsan" tests.
1 parent 425b022 commit 19e863c

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lib/test/libregrtest/tsan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'test_socket',
2121
'test_sqlite3',
2222
'test_ssl',
23+
'test_sys',
2324
'test_syslog',
2425
'test_thread',
2526
'test_thread_local_bytecode',

Lib/test/test_sys.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,40 @@ def test_pystats(self):
13491349
def test_disable_gil_abi(self):
13501350
self.assertEqual('t' in sys.abiflags, support.Py_GIL_DISABLED)
13511351

1352+
def test_int_max_str_digits(self):
1353+
old_limit = sys.get_int_max_str_digits()
1354+
self.assertIsInstance(old_limit, int)
1355+
self.assertGreaterEqual(old_limit, 0)
1356+
self.addCleanup(sys.set_int_max_str_digits, old_limit)
1357+
1358+
sys.set_int_max_str_digits(0)
1359+
self.assertEqual(sys.get_int_max_str_digits(), 0)
1360+
1361+
sys.set_int_max_str_digits(2_048)
1362+
self.assertEqual(sys.get_int_max_str_digits(), 2_048)
1363+
1364+
with self.assertRaises(ValueError):
1365+
# the minimum is 640 digits
1366+
sys.set_int_max_str_digits(5)
1367+
with self.assertRaises(ValueError):
1368+
sys.set_int_max_str_digits(-2)
1369+
with self.assertRaises(TypeError):
1370+
sys.set_int_max_str_digits(2_048.0)
1371+
1372+
def test_int_max_str_digits_thread(self):
1373+
# gh-151218: Check that it's safe to call set_int_max_str_digits()
1374+
# in parallel. Previously, this test triggered warnings in TSan
1375+
# on a free threaded build.
1376+
1377+
old_limit = sys.get_int_max_str_digits()
1378+
self.addCleanup(sys.set_int_max_str_digits, old_limit)
1379+
1380+
def worker():
1381+
for i in range (20_000):
1382+
sys.set_int_max_str_digits(4300 + (i & 7))
1383+
1384+
threading_helper.run_concurrently(worker, nthreads=4)
1385+
13521386

13531387
@test.support.cpython_only
13541388
@test.support.force_not_colorized_test_class

0 commit comments

Comments
 (0)