
    4j                         S r SSKrSSKrSSKJr  SSKJr  \R                  " \R                  S:  S5       " S S\5      5       rg)	zTests that verify the C extension works in subinterpreters.

Subinterpreters became usable for third-party C extensions in
Python 3.12 (PEP 684). On 3.13+ the extension uses per-module state
and heap types so that each interpreter gets its own copy.
    N)TestCase)skip_if_speedups_missing)      z$subinterpreters require Python 3.12+c                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\\R                  " \R                  S	:  S
5      S 5       5       rSrg)TestSubinterpreters   z;Test that the C extension can be loaded in subinterpreters.c                      SSK nUR	                  5       n UR                  X15        UR                  U5        g! [         a    [        R                  " S5      ef = f! UR                  U5        f = f)z-Helper to run code in a fresh subinterpreter.r   N_interpreters not available_interpretersImportErrorunittestSkipTestcreate
run_stringdestroy)selfcoder   interps       d/root/lseg-credit/backend/venv/lib/python3.13/site-packages/simplejson/tests/test_subinterpreters.py_run_in_subinterp%TestSubinterpreters._run_in_subinterp   sr    	C  %%'	*$$V2!!&)  	C##$ABB	C !!&)s   : A !AA1c                 &    U R                  S5        g)z5Verify _speedups can be imported in a subinterpreter.z-import simplejson; simplejson.dumps({'a': 1})Nr   r   s    r   test_import_in_subinterpreter1TestSubinterpreters.test_import_in_subinterpreter   s     	;	=    c                 &    U R                  S5        g)z4Verify encoding works correctly in a subinterpreter.ay  
import simplejson
assert simplejson.dumps(None) == 'null'
assert simplejson.dumps(True) == 'true'
assert simplejson.dumps(False) == 'false'
assert simplejson.dumps(42) == '42'
assert simplejson.dumps(3.14) == '3.14'
assert simplejson.dumps("hello") == '"hello"'
assert simplejson.dumps([1, 2, 3]) == '[1, 2, 3]'
assert simplejson.dumps({"a": 1}, sort_keys=True) == '{"a": 1}'
Nr   r   s    r   test_encode_in_subinterpreter1TestSubinterpreters.test_encode_in_subinterpreter%   s     	 
  
	r   c                 &    U R                  S5        g)z4Verify decoding works correctly in a subinterpreter.a  
import simplejson
assert simplejson.loads('null') is None
assert simplejson.loads('true') is True
assert simplejson.loads('42') == 42
assert simplejson.loads('"hello"') == 'hello'
assert simplejson.loads('[1, 2, 3]') == [1, 2, 3]
assert simplejson.loads('{"a": 1}') == {"a": 1}
Nr   r   s    r   test_decode_in_subinterpreter1TestSubinterpreters.test_decode_in_subinterpreter4   s     	   	r   c                 x    SSK n[	        S5       Vs/ s H  o!R                  5       PM     nn [        U5       H  u  pEUR                  USXD4-  5        M     U H  nUR                  U5        M     g! [         a    [        R                  " S5      ef = fs  snf ! U H  nUR                  U5        M     f = f)z@Verify multiple subinterpreters can use simplejson concurrently.r   Nr   r   z]
import simplejson
result = simplejson.dumps({"interp": %d})
assert '"interp": %d' in result
)	r   r   r   r   ranger   	enumerater   r   )r   r   _interpsir   s         r   test_multiple_subinterpreters1TestSubinterpreters.test_multiple_subinterpretersA   s    	C  498<8a'')8<		.&w/	(( 2 	f	2  0 "%%f- "  	C##$ABB	C< "%%f- "s   A4 B*B 4!BB9c                     SSK nUR	                  5       nUR	                  5       n UR                  US5        UR                  US5        UR                  U5        SnUR                  US5        Ub  UR                  U5        UR                  U5        g! [         a    [        R                  " S5      ef = f! Ub  UR                  U5        UR                  U5        f = f)z<Verify destroying one subinterpreter doesn't affect another.r   Nr   z(import simplejson; simplejson.dumps([1])z(import simplejson; simplejson.dumps([2])z
import simplejson
assert simplejson.dumps({"still": "works"}) == '{"still": "works"}'
assert simplejson.loads('{"still": "works"}') == {"still": "works"}
r   )r   r   interp1interp2s       r   %test_subinterpreter_state_independent9TestSubinterpreters.test_subinterpreter_state_independentT   s    	C   &&(&&(	+$$W:<$$W:< !!'*G $$W /  "%%g.!!'*1  	C##$ABB	C, "%%g.!!'*s   B A	B: !B7:'C!)r      zheap types require Python 3.13+c                 &    U R                  S5        g)z3Verify types are heap types inside subinterpreters.z
from simplejson._speedups import make_scanner, make_encoder
# Py_TPFLAGS_HEAPTYPE = 1 << 9
assert make_scanner.__flags__ & (1 << 9), "Scanner should be heap type"
assert make_encoder.__flags__ & (1 << 9), "Encoder should be heap type"
Nr   r   s    r   test_subinterpreter_heap_types2TestSubinterpreters.test_subinterpreter_heap_typess   s    
 	   	r    N)__name__
__module____qualname____firstlineno____doc__r   r   r   r!   r$   r,   r1   r   skipIfsysversion_infor5   __static_attributes__r7   r   r   r   r      s     F
* = =
   
 
 . .$ + +< __S%%/688 r   r   )	r<   r>   r   r   simplejson.tests._helpersr   r=   r?   r   r7   r   r   <module>rB      sO       > 
!!G+79m( m9mr   