relateby-pattern 0.4.2

Core pattern data structures
Documentation
�

tziN/���dZddlZddlmcmZddlZddlm	Z	m
Z
mZGd�d��ZGd�d��Z
Gd�d	��ZGd
�d��ZGd�d
��ZGd�d��Zedkrejedg��dSdS)z�Edge case tests for Python pattern-core bindings.

Tests for:
- None/null value handling
- Deep nesting scenarios
- Type conversion error cases
�N)�Pattern�PatternSubject�Subjectc�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�TestNoneValueHandlingz,Test handling of None values across the API.c��tjd��}d}||u}|s�tjd|fd||f��dt	j��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj	|�����dx}}|j
}|��}|s�ddt	j��vstj|��rtj|��ndtj|��tj|��d	�z}ttj	|�����dx}}dS)
z2Pattern.point should handle None values correctly.N��is not�z%(py0)s is not %(py3)s�p��py0�py3�assert %(py5)s�py5zDassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_atomic
}()
}�r�py2�py4)r�point�
@pytest_ar�_call_reprcompare�@py_builtins�locals�_should_repr_global_name�	_saferepr�AssertionError�_format_explanation�	is_atomic)�selfr�@py_assert2�@py_assert1�@py_format4�@py_format6�@py_assert3�@py_format5s        �a/Users/akollegger/Developer/gram-data/gram-rs/crates/pattern-core/tests/python/test_edge_cases.py�test_none_as_point_valuez.TestNoneValueHandling.test_none_as_point_values|���M�$������q��}����������q��������������q������q����������������������������������{��{�{�}�}��}������������q������q�������{�����}����������������������c���tjdtjgd�����}|j}|��}d}||k}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}dd	|iz}tt	j|�����d
x}x}x}}t|�
����}t|��}	d}|	|k}
|
s�t	jd|
fd|	|f��d
t
j��vst	jt��rt	j	t��nd
dt
j��vst	j|��rt	j	|��ndt	j	|	��t	j	|��d�z}dd|iz}tt	j|�����d
x}	x}
}d
}
|
|v}	|	s�t	jd|	fd|
|f��t	j	|
��dt
j��vst	j|��rt	j	|��ndd�z}dd|iz}tt	j|�����d
x}
}	d
S)z+Pattern.pattern should handle None in list.�root)�N�test���==�zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py7)sr�rrr�py7�assert %(py9)s�py9N�)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)s�len�values�r�py1r�py6�assert %(py8)s�py8��in)z%(py1)s in %(py3)s)r9rrr�r�pattern�from_values�lengthrrrrrrrr�listr7r6)rrr!r$�@py_assert6�@py_assert5�@py_format8�@py_format10r7r �@py_assert4�@py_format7�@py_format9�@py_assert0r"r#s                r&�test_none_in_pattern_listz/TestNoneValueHandling.test_none_in_pattern_lists���O�F�G�$7�8I�8I�8I�$J�$J�K�K���x��x�x�z�z��Q��z�Q�����������z�Q�������������q������q�������x�����z�����Q�������������������������������a�h�h�j�j�!�!���6�{�{��a��{�a�����������{�a�������������s������s��������������6������6�������{�����a������������������������������t�v�~����������t�v������t������������v������v�����������������������������r(c��td��}tjtd���5|�dd��ddd��dS#1swxYwYdS)z<Subject should reject None property values with clear error.�test-idzCannot convert)�match�propN�r�pytest�raises�	TypeError�set_property�r�ss  r&�test_subject_property_with_nonez5TestNoneValueHandling.test_subject_property_with_none s����I����
�]�9�,<�
=�
=�
=�	)�	)�
�N�N�6�4�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)�	)�	)s�A�A�Ac��tjdtjgd�����}|�d���}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}d	d
|iz}tt	j|�����dx}}|j}|��}d}||k}	|	s�t	jd|	fd
||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}
dd|
iz}tt	j|�����dx}x}x}	}dS)z3Pattern.map should handle callbacks returning None.r*�r+�r-c��dS�N���xs r&�<lambda>z?TestNoneValueHandling.test_map_returning_none.<locals>.<lambda>*s���r(Nr	r�resultr
rrr-r.r0r1r3r4)
rr@rA�maprrrrrrrrrB)rrrbr r!r"r#r$rDrErFrGs            r&�test_map_returning_nonez-TestNoneValueHandling.test_map_returning_none's����O�F�G�$7�	�	�	�$B�$B�C�C�����~�~�&�&��!�!�v�T�!�!�!�!�!�!�!�!�!�!�v�T�!�!�!�!�!�!�!�!�!�!�!�!�v�!�!�!�!�!�v�!�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��}�#�}�}���#�!�#��!�#�#�#�#�#�#�#�#�#�#��!�#�#�#�#�#�#�#�#�#�#�#�#�v�#�#�#�#�#�v�#�#�#�#�#�#�}�#�#�#�#��#�#�#�#�!�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#r(c���tjdtjgd�����}|�d���}t	|t
��}|�sddt
j��vstj	t��rtj
t��nddt
j��vstj	|��rtj
|��nddt
j��vstj	t
��rtj
t
��ndtj
|��d�z}ttj|�����d	}t|��}d
}||k}|s�tjd|fd||f��d
t
j��vstj	t��rtj
t��nd
dt
j��vstj	|��rtj
|��ndtj
|��tj
|��d�z}dd|iz}	ttj|	�����d	x}x}}d	S)z<Pattern.filter should handle None values in predicate tests.r*)r+Nr-c�
�|duSr]r^r_s r&razGTestNoneValueHandling.test_filter_with_none_predicate.<locals>.<lambda>2s
��A�T�M�r(z5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}�
isinstancerbrC)rr9rrNr-��>=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)sr6r8r;r<)rr@rA�filterrgrCrrrrrrrr6r)
rrrbr$r%r rErHrIrJs
          r&�test_filter_with_none_predicatez5TestNoneValueHandling.test_filter_with_none_predicate/s[���O�F�G�$7����$E�$E�F�F�����1�1�2�2���&�$�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�z�'�'�'�'�'�z�'�'�'�'�'�'�'�'�'�'�'�'�'�&�'�'�'�'�'�&�'�'�'�'�'�'�'�'�'�'�'�'�'�$�'�'�'�'�'�$�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'��6�{�{��a��{�a�����������{�a�������������s������s��������������6������6�������{�����a�����������������������������r(N)	�__name__�
__module__�__qualname__�__doc__r'rLrXrdrkr^r(r&rr
se������6�6�������)�)�)�$�$�$� � � � � r(rc�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�TestDeepNestingz*Test patterns with deep nesting scenarios.c��d}tjd��}t|��D]}tjd|��|g��}�|j}|��}||k}|s�tjd|fd||f��dtj��vstj	|��rtj
|��ndtj
|��tj
|��dtj��vstj	|��rtj
|��ndd�z}d	d
|iz}ttj|�����dx}x}}|j
}|��}|}|s�ddtj��vstj	|��rtj
|��ndtj
|��tj
|��d
�z}	ttj|	�����dx}x}}|j}|��}d}
||
k}|s�tjd|fd||
f��dtj��vstj	|��rtj
|��ndtj
|��tj
|��tj
|
��d�z}dd|iz}ttj|�����dx}x}x}}
dS)z6Create and query deeply nested patterns (100+ levels).�d�*�level-rh)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} >= %(py6)sr�depth�rrrr:r;r<N�Hassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_atomic
}()
}rr��>)zB%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.size
}()
} > %(py7)sr1r3r4)rr�ranger@rvrrrrrrrrr�size)
rrvr�ir!r$rErIrJr#rDrFrGs
             r&�test_deeply_nested_patternsz+TestDeepNesting.test_deeply_nested_patterns<s�����M�"�����u���	3�	3�A�������q�c�2�2�A�A��w�!�w�w�y�y�!�y�E�!�!�!�!�!�!�!�!�!�!�y�E�!�!�!�!�!�!�!�!�!�!�!�!�q�!�!�!�!�!�q�!�!�!�!�!�!�w�!�!�!�!�y�!�!�!�!�!�!�!�!�!�!�!�E�!�!�!�!�!�E�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��;� �;�;�=�=� �=� � � � � � � � � � � � � � �1� � � � � �1� � � � � � �;� � � � �=� � � � � � � � � � � � � � � � � � � � � ��v��v�v�x�x��!��x�!�|����������x�!�������������q������q�������v�����x�����!�������������������������������r(c���d}tjd��}t|��D]}tjd|��|g��}�|���}d}||u}|s�tjd|fd||f��dtj��vstj	|��rtj
|��ndtj
|��d�z}d	d
|iz}ttj|�����dx}}dS)z6Comonad extract should work on deeply nested patterns.�2�coreruNr	r�	extractedr
rr)
rrr{r@�extractrrrrrrrr)	rrvrr}r�r r!r"r#s	         r&�test_deep_nesting_with_extractz.TestDeepNesting.test_deep_nesting_with_extractKs�����M�&�!�!���u���	3�	3�A�������q�c�2�2�A�A��I�I�K�K�	� $�$�y��$�$�$�$�$�$�$�$�$�$�y��$�$�$�$�$�$�$�$�$�$�$�$�y�$�$�$�$�$�y�$�$�$�$�$�$��$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$r(c	�z�d}tjd��}t|��D]}tj||g��}�|�d���}d}||u}|s�tjd|fd||f��dtj��vstj	|��rtj
|��ndtj
|��d�z}d	d
|iz}ttj|�����dx}}|j
}|��}	|j
}
|
��}|	|k}|�stjd|fd|	|f��dtj��vstj	|��rtj
|��ndtj
|��tj
|	��d
tj��vstj	|��rtj
|��nd
tj
|
��tj
|��d�z}
dd|
iz}ttj|�����dx}x}	x}x}
}dS)z-Map should traverse deeply nested structures.�r+c�:�t|t��r|dzn|S�Nr[�rg�intr_s r&raz<TestDeepNesting.test_deep_nesting_with_map.<locals>.<lambda>^s��*�Q��*<�*<�!C��Q���!�r(Nr	rrbr
rrr.)zx%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} == %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s.depth
}()
}r)rrrr:r<�py10zassert %(py12)s�py12)rrr{r@rcrrrrrrrrrv)rrvrr}rbr r!r"r#r$�@py_assert7�@py_assert9rE�@py_format11�@py_format13s               r&�test_deep_nesting_with_mapz*TestDeepNesting.test_deep_nesting_with_mapVsv�����M�!�����u���	(�	(�A����A�3�'�'�A�A����C�C�D�D��!�!�v�T�!�!�!�!�!�!�!�!�!�!�v�T�!�!�!�!�!�!�!�!�!�!�!�!�v�!�!�!�!�!�v�!�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��|�*�|�|�~�~�*���*�����*�~��*�*�*�*�*�*�*�*�*�*�~��*�*�*�*�*�*�*�*�*�*�*�*�v�*�*�*�*�*�v�*�*�*�*�*�*�|�*�*�*�*�~�*�*�*�*�*�*�*�*�*�*�*��*�*�*�*�*��*�*�*�*�*�*��*�*�*�*��*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*r(c��d}tt|����}tjdtj|����}|j}|��}||k}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��dtj	��vst
j
|��rt
j|��ndd�z}dd	|iz}tt
j
|�����d
x}x}}t|�����}	t|	��}
d}||z}|
|k}
|
�s0t
jd|
fd|
|f��d
tj	��vst
j
t��rt
jt��nd
dtj	��vst
j
|	��rt
j|	��ndt
j|
��dtj	��vst
j
|��rt
j|��ndt
j|��d�z}dd|iz}tt
j
|�����d
x}
x}
x}}d
S)z4Pattern with many sibling elements (1000+ elements).��r*r.�zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py6)sr�widthrwr;r<Nr+)z<%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == (%(py5)s + %(py7)s)r6r7)rr9rrr2zassert %(py10)sr�)rCr{rr@rArBrrrrrrrrr7r6)rr��elementsrr!r$rErIrJr7r rD�@py_assert8rHr�s               r&�test_very_wide_patternz&TestDeepNesting.test_very_wide_patternbs�������e���%�%���O�F�G�$7��$A�$A�B�B���x�"�x�x�z�z�"�z�U�"�"�"�"�"�"�"�"�"�"�z�U�"�"�"�"�"�"�"�"�"�"�"�"�q�"�"�"�"�"�q�"�"�"�"�"�"�x�"�"�"�"�z�"�"�"�"�"�"�"�"�"�"�"�U�"�"�"�"�"�U�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"��a�h�h�j�j�!�!���6�{�{�'�a�'�e�a�i�'�{�i�'�'�'�'�'�'�'�'�'�'�{�i�'�'�'�'�'�'�'�'�'�'�'�'�s�'�'�'�'�'�s�'�'�'�'�'�'�'�'�'�'�'�'�'�6�'�'�'�'�'�6�'�'�'�'�'�'�{�'�'�'�'�'�'�'�'�'�'�'�e�'�'�'�'�'�e�'�'�'�'�'�'�a�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'r(c���	��	fd��	�	d��}|j}|��}|}|s�ddtj��vstj|��rtj|��ndtj|��tj|��d�z}t
tj|�����dx}x}}|j}|��}d}||k}|s�tj	d|fd	||f��dtj��vstj|��rtj|��ndtj|��tj|��tj|��d
�z}dd|iz}t
tj|�����dx}x}x}}|j
}|��}d}||k}|s�tj	d
|fd||f��dtj��vstj|��rtj|��ndtj|��tj|��tj|��d
�z}dd|iz}t
tj|�����dx}x}x}}dS)z"Pattern with both depth and width.c�����dkrtjd��S��fd�td��D��}tjd���|��S)Nrrtc�,��g|]}��dz
����S)r+r^)�.0�_�create_level�depth_remainings  ��r&�
<listcomp>zTTestDeepNesting.test_deep_and_wide_pattern.<locals>.create_level.<locals>.<listcomp>us(���M�M�M�a���_�q�%8�9�9�M�M�Mr(�
ru)rrr{r@)r��childrenr�s` �r&r�z@TestDeepNesting.test_deep_and_wide_pattern.<locals>.create_levelrs\�����!�#�#��}�R�(�(�(�M�M�M�M�M�5��9�9�M�M�M�H��?�#=�O�#=�#=�x�H�H�Hr(�rxrrNr�r.r0r1r3r4rh)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} >= %(py7)s)rrrrrrrrrBrrv)
rrr!r$rEr#rDrFrGr�s
         @r&�test_deep_and_wide_patternz*TestDeepNesting.test_deep_and_wide_patternos����	I�	I�	I�	I�	I�
�L��O�O���;� �;�;�=�=� �=� � � � � � � � � � � � � � �1� � � � � �1� � � � � � �;� � � � �=� � � � � � � � � � � � � � � � � � � � � ��x��x�x�z�z��R��z�R�����������z�R�������������q������q�������x�����z�����R�������������������������������w��w�w�y�y��A��y�A�~����������y�A�������������q������q�������w�����y�����A�������������������������������r(N)	rlrmrnror~r�r�r�r�r^r(r&rqrq9se������4�4�
�
�
�	%�	%�	%�
+�
+�
+�(�(�(�����r(rqc�<�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�TestTypeConversionErrorsz!Test type conversion error cases.c���tjdtjgd�����}	|�d��}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}d	d
|iz}tt	j|�����dx}}dS#ttf$rYdSwxYw)z:Pattern.map should handle non-callable objects gracefully.r*rZznot a functionNr	rrbr
rr)rr@rArcrrrrrrrrrT�AttributeError�rrrbr r!r"r#s       r&�test_invalid_callback_typez3TestTypeConversionErrors.test_invalid_callback_type�s(���O�F�G�$7�	�	�	�$B�$B�C�C��	��U�U�+�,�,�F�!%�%�6��%�%�%�%�%�%�%�%�%�%�6��%�%�%�%�%�%�%�%�%�%�%�%�6�%�%�%�%�%�6�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%���>�*�	�	�	��D�D�	�����B8C%�%C:�9C:c��tjdtjgd�����}d�}	|�|��}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}d	d
|iz}tt	j|�����dx}}dS#tttf$rYdSwxYw)z>Pattern.map should propagate Python exceptions from callbacks.r*rZc� �td���)Nz
Test error)�
ValueErrorr_s r&�bad_callbackzNTestTypeConversionErrors.test_callback_raising_exception.<locals>.bad_callback�s���\�*�*�*r(Nr	rrbr
rr)rr@rArcrrrrrrrrr��RuntimeError�	Exception)rrr�rbr r!r"r#s        r&�test_callback_raising_exceptionz8TestTypeConversionErrors.test_callback_raising_exception�s8���O�F�G�$7�	�	�	�$B�$B�C�C��	+�	+�	+�	��U�U�<�(�(�F�!%�%�6��%�%�%�%�%�%�%�%�%�%�6��%�%�%�%�%�%�%�%�%�%�%�%�6�%�%�%�%�%�6�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%���L�)�4�	�	�	��D�D�	���s�B8C(�(D�Dc��td��}tjt��5|�dd��ddd��dS#1swxYwYdS)z/Subject.set_property should validate key types.rN�{�valueNrQrVs  r&�test_invalid_property_key_typez7TestTypeConversionErrors.test_invalid_property_key_type�s����I�����]�9�
%�
%�	)�	)�
�N�N�3��(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)�	)�	)s�A
�
A�Ac��tjt��5tjd��ddd��dS#1swxYwYdS)z0Pattern.from_values should validate input types.z
not a listN)rRrSrTrrA�rs r&�#test_pattern_from_invalid_list_typez<TestTypeConversionErrors.test_pattern_from_invalid_list_type�s����]�9�
%�
%�	.�	.����-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�<�A�Ac��tjt��5td��ddd��dS#1swxYwYdS)z2Subject constructor should validate identity type.i90N)rRrSrTrr�s r&�"test_subject_invalid_identity_typez;TestTypeConversionErrors.test_subject_invalid_identity_type�s����]�9�
%�
%�	�	��E�N�N�N�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�7�;�;c��tjdtjgd�����}d�}	|�d|��}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d	�z}d
d|iz}tt	j|�����dx}}dS#ttf$rYdSwxYw)z:Pattern.fold should handle type mismatches in accumulator.r*rZc��|dkrdn||zS)Nr�stringr^)�accr`s  r&�bad_foldzMTestTypeConversionErrors.test_fold_with_invalid_accumulator.<locals>.bad_fold�s��"�a�x�x�8�8�S�1�W�4r(rNr	rrbr
rr)rr@rA�foldrrrrrrrrrTr�)rrr�rbr r!r"r#s        r&�"test_fold_with_invalid_accumulatorz;TestTypeConversionErrors.test_fold_with_invalid_accumulator�s8���O�F�G�$7�	�	�	�$B�$B�C�C��	5�	5�	5�
	��V�V�A�x�(�(�F�!%�%�6��%�%�%�%�%�%�%�%�%�%�6��%�%�%�%�%�%�%�%�%�%�%�%�6�%�%�%�%�%�6�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%���<�(�	�	�	��D�D�	���s�B9C)�)C>�=C>c���tjdtjgd�����}	|�d��}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}dd	|iz}tt	j|�����dx}}dS#ttf$rYdSwxYw)
z-Pattern.extend should validate callback type.r*rZNr	rrbr
rr)rr@rA�extendrrrrrrrrrTr�r�s       r&�test_extend_with_non_functionz6TestTypeConversionErrors.test_extend_with_non_function�s%���O�F�G�$7�	�	�	�$B�$B�C�C��	��X�X�d�^�^�F�!%�%�6��%�%�%�%�%�%�%�%�%�%�6��%�%�%�%�%�%�%�%�%�%�%�%�6�%�%�%�%�%�6�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%���>�*�	�	�	��D�D�	���r�N)rlrmrnror�r�r�r�r�r�r�r^r(r&r�r��s�������+�+������� )�)�)�.�.�.�������"����r(r�c�$�eZdZdZd�Zd�Zd�ZdS)�TestMemoryAndLimitsz"Test memory management and limits.c��d}tt|����}tjdtj|����}|j}|��}||k}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��dtj	��vst
j
|��rt
j|��ndd�z}dd	|iz}tt
j
|�����d
x}x}}d}	|���D]}
|	dz
}	�d}||z}|	|k}|s�t
jd|fd
|	|f��dtj	��vst
j
|	��rt
j|	��nddtj	��vst
j
|��rt
j|��ndt
j|��d�z}dd|iz}tt
j
|�����d
x}x}}d
S)z7Create a very large pattern and verify memory handling.i'r*r.r�rr|rwr;r<Nrr+)z%(py0)s == (%(py2)s + %(py4)s)�countrzassert %(py7)sr2)rCr{rr@rArBrrrrrrrrr7)
rr|r�rr!r$rErIrJr�r�r#rFs
             r&�test_large_pattern_creationz/TestMemoryAndLimits.test_large_pattern_creation�s�������d���$�$���O�F�G�$7��$A�$A�B�B���x�!�x�x�z�z�!�z�T�!�!�!�!�!�!�!�!�!�!�z�T�!�!�!�!�!�!�!�!�!�!�!�!�q�!�!�!�!�!�q�!�!�!�!�!�!�x�!�!�!�!�z�!�!�!�!�!�!�!�!�!�!�!�T�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��������	�	�A��Q�J�E�E� � ��q�� �u�� � � � � � � � � � �u�� � � � � � � � � � � � �u� � � � � �u� � � � � � � � � � � � � �� � � � � �� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � � � r(c��ddz}tjdtj|gdz����}|j}|��}d}||k}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}d	d
|iz}tt	j|�����dx}x}x}}t|�
����}	d�|	D��}
t|
��}d
}||k}|s�t	jd|fd||f��dt
j��vst	jt��rt	j	t��nddt
j��vst	j|
��rt	j	|
��ndt	j	|��t	j	|��d�z}
dd|
iz}tt	j|�����dx}x}}|
d
}t|��}d}||k}|s�t	jd|fd||f��dt
j��vst	jt��rt	j	t��ndt	j	|��t	j	|��t	j	|��d�z}d	d
|iz}tt	j|�����dx}x}x}}dS)z&Pattern with very large string values.r`i��r*r�r.r0rr1r3r4Nc�b�g|],}t|t���t|��dk�*|��-S)r�)rg�strr6)r��vs  r&r�zGTestMemoryAndLimits.test_pattern_with_large_strings.<locals>.<listcomp>�s2��R�R�R�a�Z��3�-?�-?�R�C��F�F�T�M�M��M�M�Mr(rry�z/%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py6)sr6�large_valuesr8r;r<)z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)sr?)r�large_stringrr!r$rDrErFrGr7r�r rHrIrJs               r&�test_pattern_with_large_stringsz3TestMemoryAndLimits.test_pattern_with_large_strings�s{���V�|���O�F�G�$7����8K�$L�$L�M�M���x��x�x�z�z��R��z�R�����������z�R�������������q������q�������x�����z�����R�������������������������������a�h�h�j�j�!�!��R�R�6�R�R�R���<� � �$�1�$� �1�$�$�$�$�$�$�$�$�$�$� �1�$�$�$�$�$�$�$�$�$�$�$�$�s�$�$�$�$�$�s�$�$�$�$�$�$�$�$�$�$�$�$�$�<�$�$�$�$�$�<�$�$�$�$�$�$� �$�$�$�$�1�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$���?�-�s�?�#�#�-�v�-�#�v�-�-�-�-�-�-�-�-�-�-�#�v�-�-�-�-�-�-�-�-�-�-�-�-�s�-�-�-�-�-�s�-�-�-�-�-�-�?�-�-�-�-�#�-�-�-�-�v�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-�-r(c���tjd��}tjd|g��}|j}|��}d}||k}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}dd	|iz}tt	j|�����d
x}x}x}}|j}|��}d}||k}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}dd	|iz}tt	j|�����d
x}x}x}}d
S)z>Verify patterns don't allow cyclic references (if applicable).r+r[rs)�<)zC%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} < %(py7)s�p2r1r3r4N)zB%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.size
}()
} < %(py7)s)
rrr@rvrrrrrrrrr|)	r�p1r�r!r$rDrErFrGs	         r&� test_cyclic_reference_preventionz4TestMemoryAndLimits.test_cyclic_reference_prevention�s%���]�1�
�
��
�_�Q���
%�
%���x��x�x�z�z��C��z�C�����������z�C�������������r������r�������x�����z�����C�������������������������������w��w�w�y�y��3��y�3�����������y�3�������������r������r�������w�����y�����3�������������������������������r(N)rlrmrnror�r�r�r^r(r&r�r��sG������,�,�!�!�!�.�.�.�	�	�	�	�	r(r�c��eZdZdZd�Zd�ZdS)�TestConcurrencyAndThreadSafetyz9Test thread safety if patterns are shared across threads.c�^�tjdtjgd�����}|�d���}t	|�����}t	|�����}gd�}||k}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��d�z}d	d
|iz}tt
j
|�����dx}}|d}	d
}
|	|
k}|slt
jd|fd|	|
f��t
j|	��t
j|
��d�z}dd|iz}tt
j
|�����dx}	x}}
dS)z?Patterns should be immutable (operations create new instances).r*rZc�:�t|t��r|dzn|Sr�r�r_s r&razJTestConcurrencyAndThreadSafety.test_pattern_immutability.<locals>.<lambda>s��z�!�S�'9�'9�@�a�!�e�e�q�r()r*r+r[r-r.)z%(py0)s == %(py3)s�v1r
rrNr+r[)z%(py1)s == %(py4)s)r9rzassert %(py6)sr:)rr@rArcrCr7rrrrrrrr)
rr�r�r��v2r r!r"r#rKr$r%rIs
             r&�test_pattern_immutabilityz8TestConcurrencyAndThreadSafety.test_pattern_immutabilitys���
�_�V�W�%8����%C�%C�
D�
D��
�V�V�@�@�
A�
A���"�)�)�+�+�
�
��
�"�)�)�+�+�
�
��'�&�&�&�r�&�&�&�&�&�&�&�&�&�&�&�r�&�&�&�&�&�&�&�&�&�&�&�&�&�r�&�&�&�&�&�r�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&��!�u����u��z����������u�������u����������������������������������r(c�f�td��}|�d��|�dd��tj|��}|�d��|�dd��|���}d}||u}|s�t
jd|fd	||f��d
tj	��vst
j
|��rt
j|��nd
t
j|��d�z}dd
|iz}tt
j
|�����dx}}dS)z5Subject mutations should not affect copied instances.r,�Label1�keyr��Label2�modifiedNr	r�
subject_valuer
rr)r�	add_labelrUrrr�rrrrrrrr)r�s1r�r�r r!r"r#s        r&�test_subject_mutation_isolationz>TestConcurrencyAndThreadSafety.test_subject_mutation_isolationsD��
�V�_�_��
���X����
����w�'�'�'��
!�"�
%�
%��	���X����
����z�*�*�*�
�
�
���
�$(�(�}�D�(�(�(�(�(�(�(�(�(�(�}�D�(�(�(�(�(�(�(�(�(�(�(�(�}�(�(�(�(�(�}�(�(�(�(�(�(�D�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(r(N)rlrmrnror�r�r^r(r&r�r��s8������C�C����)�)�)�)�)r(r�c��eZdZdZd�Zd�ZdS)�TestErrorMessagesz-Test that error messages are Python-friendly.c��tjdtjgd�����}	|�d��dS#t$�r}t|��}g}d}|j}|��}||v}|}	|sd}
|j}|��}|
|v}
|
}	|	�s�tjd|fd||f��tj	|��dtj��vstj|��rtj	|��ndtj	|��tj	|��d	�z}d
d|iz}|�
|��|s�tjd|
fd|
|f��tj	|
��dtj��vstj|��rtj	|��ndtj	|��tj	|��d
�z}dd|iz}|�
|��tj|d��iz}dd|iz}ttj|�����dx}	x}x}x}x}x}x}
x}
x}}Yd}~dSd}~wwxYw)z8Type errors should have clear, Python-friendly messages.r*rZr��callable�functionr=)zD%(py3)s in %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = %(py5)s.lower
}()
}�	error_msg)rrr2r4z%(py11)s�py11)zJ%(py14)s in %(py20)s
{%(py20)s = %(py18)s
{%(py18)s = %(py16)s.lower
}()
})�py14�py16�py18�py20z%(py22)s�py22r+zassert %(py25)s�py25N)rr@rArcrTr��lowerrrrrrr�append�_format_booloprr)rr�er�r!r rDr�rHrK�@py_assert13�@py_assert17�@py_assert19�@py_assert15rG�@py_format12�@py_format21�@py_format23�@py_format24�@py_format26s                    r&�test_type_error_message_qualityz1TestErrorMessages.test_type_error_message_quality%s����O�F�G�$7�	�	�	�$B�$B�C�C��	V�
�E�E�#�J�J�J�J�J���	V�	V�	V��A���I�U�U�:�U���U���!2�!2�U�:�!2�2�U�U�U�U�U�j�U�I�O�U�O�O�DU�DU�U�j�DU�6U�U�U�U�U�U�U�U�U�U�U�U�:�!2�U�U�U�U�U�:�U�U�U�U�U�U�U�U�U�U�U��U�U�U�U�U��U�U�U�U�U�U��U�U�U�U�!2�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�j�DU�U�U�U�U�U�j�U�U�U�U�U�U�U�U�U�U�U�I�U�U�U�U�U�I�U�U�U�U�U�U�O�U�U�U�U�DU�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�U�����	V���s�A�I�
HI�Ic�d�	td��}d}||u}|s�tjd|fd||f��dtj��vstj|��rtj|��ndtj|��d�z}dd|iz}ttj|�����dx}}dS#ttf$�r�}t|��}t|��}d	}||k}	|	s�tjd
|	fd||f��dtj��vstjt��rtjt��ndd
tj��vstj|��rtj|��nd
tj|��tj|��d�z}
dd|
iz}ttj|�����dx}x}	}d}|j
}	|	��}
||
v}|s�tjd|fd||
f��tj|��d
tj��vstj|��rtj|��nd
tj|	��tj|
��d�z}dd|iz}ttj|�����dx}x}x}	}
d}|j
}	|	��}
||
v}|s�tjd|fd||
f��tj|��d
tj��vstj|��rtj|��nd
tj|	��tj|
��d�z}dd|iz}ttj|�����dx}x}x}	}
Yd}~dSd}~wwxYw)z5Validation errors should provide actionable feedback.�Nr	rrWr
rrrryr�r6r�r8r;r<�unwrap)�not in)zH%(py1)s not in %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py3)s.lower
}()
})r9rrr2r3r4�panic)rrrrrrrrrr�r�r�r6r�)rrWr r!r"r#r�r�rErHrIrJrKrDrFrGs                r&�test_validation_error_clarityz/TestErrorMessages.test_validation_error_clarity0s7��
	4�����A� � �1�D�=� � � � � � � � � �1�D� � � � � � � � � � � � �1� � � � � �1� � � � � � �D� � � � � � � � � � � � � � � � � � � � � � � � � � � ���L�)�	4�	4�	4��A���I��y�>�>�%�A�%�>�A�%�%�%�%�%�%�%�%�%�%�>�A�%�%�%�%�%�%�%�%�%�%�%�%�3�%�%�%�%�%�3�%�%�%�%�%�%�%�%�%�%�%�%�%�y�%�%�%�%�%�y�%�%�%�%�%�%�>�%�%�%�%�A�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%��4�9�?�4�?�?�#4�#4�4�8�#4�4�4�4�4�4�4�4�4�4�4�8�#4�4�4�4�4�4�8�4�4�4�4�4�4�4�4�4�4�4�9�4�4�4�4�4�9�4�4�4�4�4�4�?�4�4�4�4�#4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4�4��3�)�/�3�/�/�"3�"3�3�7�"3�3�3�3�3�3�3�3�3�3�3�7�"3�3�3�3�3�3�7�3�3�3�3�3�3�3�3�3�3�3�)�3�3�3�3�3�)�3�3�3�3�3�3�/�3�3�3�3�"3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�����
	4���s�B2B6�6N/�KN*�*N/N)rlrmrnrorrr^r(r&r�r�"s;������7�7�	V�	V�	V�4�4�4�4�4r(r��__main__z-v)ro�builtinsr�_pytest.assertion.rewrite�	assertion�rewriterrR�pattern_corerrrrrqr�r�r�r�rl�main�__file__r^r(r&�<module>rs������������������
�
�
�
�9�9�9�9�9�9�9�9�9�9�) �) �) �) �) �) �) �) �XD�D�D�D�D�D�D�D�NP�P�P�P�P�P�P�P�f'�'�'�'�'�'�'�'�T")�")�")�")�")�")�")�")�J4�4�4�4�4�4�4�4�>�z����F�K��4� �!�!�!�!�!��r(