File manager - Edit - /opt/imunify360/venv/lib/python3.11/site-packages/simplejson/tests/__pycache__/test_subinterpreters.cpython-311.pyc
Back
� ��]j � � � d Z ddlZddlZddlmZ ddlmZ ej ej dk d� � G d� de� � � � ZdS ) z�Tests 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 �� � e Zd ZdZd� Zed� � � Zed� � � Zed� � � Zed� � � Z ed� � � Z e ej e j dk d � � d � � � � � ZdS )�TestSubinterpretersz;Test that the C extension can be loaded in subinterpreters.c � � ddl }n"# t $ r t j d� � �w xY w|� � � } |� ||� � |� |� � dS # |� |� � w xY w)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 ��/builddir/build/BUILD/imunify360-venv-2.6.3/opt/imunify360/venv/lib64/python3.11/site-packages/simplejson/tests/test_subinterpreters.py�_run_in_subinterpz%TestSubinterpreters._run_in_subinterp s� � � C� � � � � ��� C� C� C��#�$A�B�B�B� C�����%�%�'�'�� *��$�$�V�T�2�2�2��!�!�&�)�)�)�)�)��M�!�!�&�)�)�)�)���s � �&�A+ �+Bc �0 � | � d� � dS )z5Verify _speedups can be imported in a subinterpreter.z-import simplejson; simplejson.dumps({'a': 1})N�r �r s r �test_import_in_subinterpreterz1TestSubinterpreters.test_import_in_subinterpreter s) � � ���;� =� =� =� =� =� c �0 � | � d� � dS )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_subinterpreterz1TestSubinterpreters.test_encode_in_subinterpreter% s+ � � ��� � � � � � r c �0 � | � d� � dS )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_subinterpreterz1TestSubinterpreters.test_decode_in_subinterpreter4 s+ � � ��� � � � � � r c �d �� ddl �n"# t $ r t j d� � �w xY w�fd�t d� � D � � } t |� � D ] \ }}�� |d||fz � � �! |D ]}�� |� � �dS # |D ]}�� |� � �w xY w)z@Verify multiple subinterpreters can use simplejson concurrently.r Nr c �8 �� g | ]}�� � � ��S � )r )�.0�_r s �r � <listcomp>zETestSubinterpreters.test_multiple_subinterpreters.<locals>.<listcomp>H s% �� �<�<�<�a�=�'�'�)�)�<�<�<r r z] import simplejson result = simplejson.dumps({"interp": %d}) assert '"interp": %d' in result )r r r r �range� enumerater r )r �interps�ir r s @r �test_multiple_subinterpretersz1TestSubinterpreters.test_multiple_subinterpretersA s �� � C� � � � � ��� C� C� C��#�$A�B�B�B� C����<�<�<�<�5��8�8�<�<�<�� .�&�w�/�/� � � ��6��(�(�� 2� �!�f� 2 � � � � � � "� .� .���%�%�f�-�-�-�-� .� .��'� .� .���%�%�f�-�-�-�-� .���s � �'�0B �B/c � � ddl }n"# t $ r t j d� � �w xY w|� � � }|� � � } |� |d� � |� |d� � |� |� � d}|� |d� � |�|� |� � |� |� � dS # |�|� |� � |� |� � w xY w)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_independentz9TestSubinterpreters.test_subinterpreter_state_independentT sR � � C� � � � � ��� C� C� C��#�$A�B�B�B� C�����&�&�(�(���&�&�(�(�� +��$�$�W�:� <� <� <��$�$�W�:� <� <� <� �!�!�'�*�*�*��G� �$�$�W� /� � � � �"��%�%�g�.�.�.��!�!�'�*�*�*�*�*�� �"��%�%�g�.�.�.��!�!�'�*�*�*�*���s � �&�AC �.D)r � zheap types require Python 3.13+c �0 � | � d� � dS )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_typesz2TestSubinterpreters.test_subinterpreter_heap_typess s+ � � ��� � � � � � r N)�__name__� __module__�__qualname__�__doc__r r r r r r+ r/ r �skipIf�sys�version_infor2 r# r r r r s� � � � � � � F�E� *� *� *� �=� =� ��=� �� � ��� � � � �� � �.� .� ��.�$ �+� +� ��+�<