Skip to content
Prev Previous commit
Next Next commit
Add a test_capi test to verify unique configs.
Also demonstrates that subinterpreters maintain their own limit
as a feature.
  • Loading branch information
gpshead committed Sep 20, 2022
commit 86c4b6e0222fbe0ac8c697fcdf55b388c632da86
24 changes: 24 additions & 0 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,30 @@ async def foo(arg): return await arg # Py 3.5
self.assertEqual(ret, 0)
self.assertEqual(pickle.load(f), {'a': '123x', 'b': '123'})

def test_int_max_str_digits_config_is_per_interp(self):
Comment thread
gpshead marked this conversation as resolved.
Outdated
Comment thread
gpshead marked this conversation as resolved.
Outdated
code = """if 1:
import sys, _testinternalcapi

config = _testinternalcapi.get_config()
config['int_max_str_digits'] = 55555
_testinternalcapi.set_config(config)
sub_value = _testinternalcapi.get_config()['int_max_str_digits']
assert sub_value == 55555, sub_value
# Subinterpreters maintain and enforce their own limit
sys.set_int_max_str_digits(2323)
try:
int('3'*3333)
except ValueError:
pass
else:
raise AssertionError('Expected a int max str digits ValueError.')
"""
before_cfg_value = _testinternalcapi.get_config()['int_max_str_digits']
self.assertEqual(support.run_in_subinterp(code), 0,
'subinterp code failure, see stderr.')
after_cfg_value = _testinternalcapi.get_config()['int_max_str_digits']
self.assertEqual(before_cfg_value, after_cfg_value)

def test_mutate_exception(self):
"""
Exceptions saved in global module state get shared between
Expand Down