relateby-pattern 0.4.2

Core pattern data structures
Documentation
�

��}i�2���dZddlZddlmcmZddlZddlm	Z	m
Z
Gd�d��ZGd�d��ZGd�d	��Z
Gd
�d��ZGd�d
��ZGd�d��Zedkrejedg��dSdS)aIntegration tests for Python pattern-core bindings.

Tests complete workflows combining multiple features:
- Pattern construction + operations + queries
- Subject manipulation + pattern operations
- Type safety + complex data structures
- Real-world use cases
�N)�Pattern�Subjectc�$�eZdZdZd�Zd�Zd�ZdS)�TestCompleteWorkflowz4Test complete workflows combining multiple features.c�&
�d�td��D��}t|��D]L\}}|�d��|�dd|����|�dd|z���Md�|D��}t	jd	t	j|����}|j}|��}d}||k}	|	s�tj	d
|	fd||f��dtj��vstj|��rtj
|��ndtj
|��tj
|��tj
|��d
�z}
dd|
iz}ttj|�����dx}x}x}	}|j}|��}|}	|	s�ddtj��vstj|��rtj
|��ndtj
|��tj
|��d�z}ttj|�����dx}x}}	|�d���}
d}|
|u}|s�tj	d|fd|
|f��dtj��vstj|
��rtj
|
��ndtj
|��d�z}dd|iz}ttj|�����dx}}|�d���}|j}|��}d}||k}	|	s�tj	d
|	fd||f��dtj��vstj|��rtj
|��ndtj
|��tj
|��tj
|��d
�z}
dd|
iz}ttj|�����dx}x}x}	}t'|�����}t+|��}d}	||	k}|s�tj	d
|fd||	f��dtj��vstjt*��rtj
t*��nddtj��vstj|��rtj
|��ndtj
|��tj
|	��d �z}d!d"|iz}ttj|�����dx}x}}	dS)#z9Complete workflow: build pattern, query it, transform it.c�2�g|]}td|������S)zuser-)r)�.0�is  �b/Users/akollegger/Developer/gram-data/gram-rs/crates/pattern-core/tests/python/test_integration.py�
<listcomp>zLTestCompleteWorkflow.test_build_query_transform_workflow.<locals>.<listcomp>s6��
�
�
��
�K�A�K�K� � �
�
�
���Person�namezUser �age�c�6�g|]}tj|����S��r�point�r	�ss  rrzLTestCompleteWorkflow.test_build_query_transform_workflow.<locals>.<listcomp>�"��7�7�7��G�M�!�$�$�7�7�7r
�root��==�zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py7)s�graph��py0�py2�py4�py7�assert %(py9)s�py9N�Hassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.is_atomic
}()
}�r r!r"c��dS�NTr��ps r�<lambda>zJTestCompleteWorkflow.test_build_query_transform_workflow.<locals>.<lambda>'s���r
��is not�z%(py0)s is not %(py3)s�adults�r �py3�assert %(py5)s�py5c��|S�Nr��xs rr,zJTestCompleteWorkflow.test_build_query_transform_workflow.<locals>.<lambda>+s��!�r
�transformed��z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)s�len�values�r �py1r2�py6�assert %(py8)s�py8)�range�	enumerate�	add_label�set_propertyr�pattern�from_values�length�
@pytest_ar�_call_reprcompare�@py_builtins�locals�_should_repr_global_name�	_saferepr�AssertionError�_format_explanation�	is_atomic�filter�map�listr=r<)�self�subjectsr
r�patternsr�@py_assert1�@py_assert3�@py_assert6�@py_assert5�@py_format8�@py_format10�@py_format6r0�@py_assert2�@py_format4r9r=�@py_assert4�@py_format7�@py_format9s                     r�#test_build_query_transform_workflowz8TestCompleteWorkflow.test_build_query_transform_workflows���
�
��1�X�X�
�
�
��
�h�'�'�	*�	*�D�A�q�
�K�K��!�!�!�
�N�N�6�;�1�;�;�/�/�/�
�N�N�5�"�q�&�)�)�)�)�7�7�h�7�7�7������(;�H�(E�(E�F�F���|�"�|�|�~�~�"��"�~��"�"�"�"�"�"�"�"�"�"�~��"�"�"�"�"�"�"�"�"�"�"�"�u�"�"�"�"�"�u�"�"�"�"�"�"�|�"�"�"�"�~�"�"�"�"��"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"��?�$�?�?�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�5�$�$�$�$�$�5�$�$�$�$�$�$�?�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$����n�n�-�-��!�!�v�T�!�!�!�!�!�!�!�!�!�!�v�T�!�!�!�!�!�!�!�!�!�!�!�!�v�!�!�!�!�!�v�!�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��i�i���,�,���!�(�!�!�#�#�(�q�(�#�q�(�(�(�(�(�(�(�(�(�(�#�q�(�(�(�(�(�(�(�(�(�(�(�(�{�(�(�(�(�(�{�(�(�(�(�(�(�!�(�(�(�(�#�(�(�(�(�q�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(��e�l�l�n�n�%�%���6�{�{��a��{�a�����������{�a�������������s������s��������������6������6�������{�����a�����������������������������r
c�
�td��}|�d��|�dd��td��}|�d��|�dd��td��}|�d��|�dd��tj|��}tj|��}tj|��}tjd	tj|||g����}|j}|��}	d
}
|	|
k}|s�tj	d|fd|	|
f��d
tj��vstj|��rtj
|��nd
tj
|��tj
|	��tj
|
��d�z}dd|iz}
ttj|
�����dx}x}	x}}
|j}|��}	d
}
|	|
k}|s�tj	d|fd|	|
f��d
tj��vstj|��rtj
|��nd
tj
|��tj
|	��tj
|
��d�z}dd|iz}
ttj|
�����dx}x}	x}}
|���}d}||k}|s�tj	d|fd||f��dtj��vstj|��rtj
|��ndtj
|��d�z}dd|iz}ttj|�����dx}}|�d���}d}||u}|s�tj	d|fd||f��dtj��vstj|��rtj
|��ndtj
|��d�z}dd|iz}ttj|�����dx}}d}|���D]}|dz
}�d}||k}|s�tj	d|fd ||f��d!tj��vstj|��rtj
|��nd!tj
|��d�z}dd|iz}ttj|�����dx}}dS)"z'Analyze a graph-like pattern structure.�alicerr�Alice�bob�Bob�charlie�Charlier�rr�networkrr$r%N��>=)zC%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.size
}()
} >= %(py7)sr�z%(py0)s >= %(py3)s�depthr1r3r4c��dSr)rr7s rr,zCTestCompleteWorkflow.test_graph_analysis_workflow.<locals>.<lambda>Qs���r
r-r/�
has_people���z%(py0)s == %(py3)s�count)rrErFrrrGrHrIrJrKrLrMrNrOrPrQ�sizerr�	any_valuer=)rVrgrirk�p_alice�p_bob�	p_charliernrYrZr[r\r]r^rrr`rar_rtrx�_s                     r�test_graph_analysis_workflowz1TestCompleteWorkflow.test_graph_analysis_workflow3s����� � ��
����!�!�!�
���6�7�+�+�+��e�n�n���
�
�h���������'�'�'��)�$�$�����(�#�#�#����V�Y�/�/�/��-��&�&���
�c�"�"���M�'�*�*�	��/�&�'�*=�w��y�>Y�*Z�*Z�[�[���~�$�~�~���$�1�$��1�$�$�$�$�$�$�$�$�$�$��1�$�$�$�$�$�$�$�$�$�$�$�$�w�$�$�$�$�$�w�$�$�$�$�$�$�~�$�$�$�$��$�$�$�$�1�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$��|�"�|�|�~�~�"��"�~��"�"�"�"�"�"�"�"�"�"�~��"�"�"�"�"�"�"�"�"�"�"�"�w�"�"�"�"�"�w�"�"�"�"�"�"�|�"�"�"�"�~�"�"�"�"��"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"��
�
������u��z����������u��������������u������u����������������������������������&�&�~�~�6�6�
�!%�%�z��%�%�%�%�%�%�%�%�%�%�z��%�%�%�%�%�%�%�%�%�%�%�%�z�%�%�%�%�%�z�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%������!�!�	�	�A��Q�J�E�E���u��z����������u��������������u������u����������������������������������r
c��dddd�dddd�dd	dd�g}g}|D]c}t|d
��}|�|d��|�d|d��|�|���dd
�|D��}t	jdt	j|����}|�d���}d}|���D]}	|dz
}�d}
||
k}|s�tj
d|fd||
f��dtj��vstj
|��rtj|��ndtj|
��d�z}dd|iz}
ttj|
�����dx}}
|j}|��}d}||k}|s�tj
d|fd||f��dtj��vstj
|��rtj|��ndtj|��tj|��tj|��d�z}dd|iz}ttj|�����dx}x}x}}|j}|��}d}||k}|s�tj
d|fd||f��d tj��vstj
|��rtj|��nd tj|��tj|��tj|��d�z}dd|iz}ttj|�����dx}x}x}}dS)!z'Transform data through multiple stages.�1�
�A)�id�value�type�2r�B�3�r�r�r�c�6�g|]}tj|����Srrrs  rrzJTestCompleteWorkflow.test_data_transformation_pipeline.<locals>.<listcomp>mrr
rc��|Sr6rr7s rr,zHTestCompleteWorkflow.test_data_transformation_pipeline.<locals>.<lambda>ts��A�r
rrurvrrw�totalr1r3r4Nrmr�datasetrr$r%r9)rrErF�appendrrGrHrTr=rJrKrLrMrNrOrPrQrI)rV�raw_datarW�itemrrXr�r9r�r�r`rYrar_rZr[r\r]r^s                   r�!test_data_transformation_pipelinez6TestCompleteWorkflow.test_data_transformation_pipeline[s�����S�1�1���S�1�1���S�1�1�
�����	�	�D���T�
�#�#�A�
�K�K��V��%�%�%�
�N�N�7�D��M�2�2�2��O�O�A�����8�7�h�7�7�7���/�&�'�*=�h�*G�*G�H�H��
�k�k�+�+�.�.�����^�^�%�%�	�	�E��Q�J�E�E���u��z����������u��������������u������u����������������������������������~�$�~�~���$�1�$��1�$�$�$�$�$�$�$�$�$�$��1�$�$�$�$�$�$�$�$�$�$�$�$�w�$�$�$�$�$�w�$�$�$�$�$�$�~�$�$�$�$��$�$�$�$�1�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$��!�(�!�!�#�#�(�q�(�#�q�(�(�(�(�(�(�(�(�(�(�#�q�(�(�(�(�(�(�(�(�(�(�(�(�{�(�(�(�(�(�{�(�(�(�(�(�(�!�(�(�(�(�#�(�(�(�(�q�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(r
N)�__name__�
__module__�__qualname__�__doc__rerr�rr
rrrsI������>�>�  �  �  �D&�&�&�P$)�$)�$)�$)�$)r
rc�$�eZdZdZd�Zd�Zd�ZdS)�TestRealWorldScenariosz Test real-world usage scenarios.c�V�td��}|�d��|�dd��td��}|�d��|�dd��|�d	d
��td��}|�d��|�dd
��|�d	d��tj|��}tj|��}tjdtj||g����}tj|��}tjdtj||g����}|j}	|	��}
d}|
|k}|s�tj	d|fd|
|f��dtj��vstj|��rtj
|��ndtj
|	��tj
|
��tj
|��d�z}
dd|
iz}ttj|�����dx}	x}
x}}|j}	|	��}
|
}|s�ddtj��vstj|��rtj
|��ndtj
|	��tj
|
��d�z}ttj|�����dx}	x}
}|���}d}||k}	|	s�tj	d|	fd||f��dtj��vstj|��rtj
|��ndtj
|��d�z}dd |iz}ttj|�����dx}	}dS)!z%Model a configuration tree structure.zconfig-root�Config�versionz1.0z	config-db�DatabaseConfig�host�	localhost�porti8z
config-api�	APIConfigz0.0.0.0i�r�rr�config_treerr$r%Nr&r'rurorqrrr1r3r4)rrErFrrrGrHrIrJrKrLrMrNrOrPrQrRrr)rVr�db�api�
db_pattern�api_pattern�children�root_patternr�rYrZr[r\r]r^r_rrr`ras                   r�test_configuration_treez.TestRealWorldScenarios.test_configuration_tree�s����}�%�%�����x� � � ����)�U�+�+�+��[�
!�
!��
���%�&�&�&�
�����,�,�,�
�����%�%�%��l�#�#���
�
�k�"�"�"������+�+�+������&�&�&��]�2�&�&�
��m�C�(�(���?�6�7�+>�
�K�?X�+Y�+Y�Z�Z���}�T�*�*���o�f�g�.A�<�QY�BZ�.[�.[�\�\���!�(�!�!�#�#�(�q�(�#�q�(�(�(�(�(�(�(�(�(�(�#�q�(�(�(�(�(�(�(�(�(�(�(�(�{�(�(�(�(�(�{�(�(�(�(�(�(�!�(�(�(�(�#�(�(�(�(�q�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(��(�*�(�(�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�;�*�*�*�*�*�;�*�*�*�*�*�*�(�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�*�
�!�!�#�#����u��z����������u��������������u������u����������������������������������r
c�*�g}td��D]x}td|����}|�d��|�d|dz��|�d|dzdkrd	nd
��|�|���yd�|D��}tjdtj|����}|j}|��}d}||k}	|	s�tj
d
|	fd||f��dtj��vstj
|��rtj|��ndtj|��tj|��tj|��d�z}
dd|
iz}ttj|�����dx}x}x}	}|�d���}d}
||
u}|s�tj
d|fd||
f��dtj��vstj
|��rtj|��ndtj|
��d�z}dd|iz}ttj|�����dx}}
|�dd���}d}
||
k}|s�tj
d
|fd||
f��dtj��vstj
|��rtj|��ndtj|
��d�z}dd|iz}ttj|�����dx}}
dS)zProcess a sequence of events.r�zevent-�Event�	timestamp��r�r�r�
UserAction�SystemEventc�6�g|]}tj|����Srr)r	�es  rrzDTestRealWorldScenarios.test_event_log_processing.<locals>.<listcomp>�s"��;�;�;�q�'�-��*�*�;�;�;r
rrr�	event_logrr$r%Nc��dSr)rr7s rr,zBTestRealWorldScenarios.test_event_log_processing.<locals>.<lambda>�s��d�r
r-r/�filteredr1r3r4c��|dzS�Nrur��accr8s  rr,zBTestRealWorldScenarios.test_event_log_processing.<locals>.<lambda>�s
���q��r
�rwrx)rCrrErFr�rrGrHrIrJrKrLrMrNrOrPrQrS�fold)rV�eventsr
�event�event_patternsr�rYrZr[r\r]r^r�r`rar_rxs                 r�test_event_log_processingz0TestRealWorldScenarios.test_event_log_processing�s������r���	!�	!�A��L�Q�L�L�)�)�E��O�O�G�$�$�$����{�A��H�5�5�5����v�q�1�u��z�z�|�|�}�U�U�U��M�M�%� � � � �<�;�F�;�;�;���O�F�G�,?��,O�,O�P�P�	���'���!�!�'�R�'�!�R�'�'�'�'�'�'�'�'�'�'�!�R�'�'�'�'�'�'�'�'�'�'�'�'�y�'�'�'�'�'�y�'�'�'�'�'�'��'�'�'�'�!�'�'�'�'�R�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'��#�#�N�N�3�3��#�#�x�t�#�#�#�#�#�#�#�#�#�#�x�t�#�#�#�#�#�#�#�#�#�#�#�#�x�#�#�#�#�#�x�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#����q�"8�"8�9�9����u��{����������u��������������u������u����������������������������������r
c���td��}|�d��|�dd��|�dd��td��}|�d��|�dd��|�dd	��td
��}|�d��|�dd��tj|��tj|��tj|��g}tjd
tj|����}|j}|��}d}||k}	|	s�tj	d|	fd||f��dtj��vstj|��rtj
|��ndtj
|��tj
|��tj
|��d�z}
dd|
iz}ttj|�����dx}x}x}	}d}|���D]}
|dz
}�d}||k}|s�tj	d|fd||f��dtj��vstj|��rtj
|��ndtj
|��d�z}dd|iz}ttj|�����dx}}dS)z'Model a small knowledge graph fragment.�python�Languager�Python�paradigmzmulti-paradigm�rust�Rust�systemszweb-dev�DomainzWeb Developmentrrmrr�knowledge_graphrr$r%Nrrurvrw�entity_countr1r3r4)rrErFrrrGrHrIrJrKrLrMrNrOrPrQr=)rVr�r��web�entitiesr�rYrZr[r\r]r^r�r~r`rar_s                 r�test_knowledge_graph_fragmentz4TestRealWorldScenarios.test_knowledge_graph_fragment�s����"�"������$�$�$����F�H�-�-�-����J�(8�9�9�9��v�������z�"�"�"����&�&�)�)�)����*�i�0�0�0��i� � ���
�
�h��������!2�3�3�3�
�M�&�!�!��M�$����M�#���
��
"�/�&�'�2E�h�2O�2O�P�P���%�,�%�%�'�'�,�1�,�'�1�,�,�,�,�,�,�,�,�,�,�'�1�,�,�,�,�,�,�,�,�,�,�,�,��,�,�,�,�,��,�,�,�,�,�,�%�,�,�,�,�'�,�,�,�,�1�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,��� �'�'�)�)�	�	�A��A��L�L� � �|�q� � � � � � � � � � �|�q� � � � � � � � � � � � �|� � � � � �|� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � r
N)r�r�r�r�r�r�r�rr
rr�r��sH������*�*�#�#�#�J���8!!�!!�!!�!!�!!r
r�c��eZdZdZd�Zd�ZdS)�TestComonadWorkflowz/Test comonad operations in realistic scenarios.c	���gd�}d�|D��}tjdtj|����}|���}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}d	d
|iz}tt	j|�����dx}}|�d���}	d}|	|u}|s�t	jd|fd|	|f��dt
j��vst	j|	��rt	j	|	��ndt	j	|��d�z}d	d
|iz}tt	j|�����dx}}|	j
}|��}
|j
}|��}|
|k}
|
�st	jd
|
fd|
|f��dt
j��vst	j|	��rt	j	|	��ndt	j	|��t	j	|
��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��d�z}dd|iz}tt	j|�����dx}x}
x}
x}}dS)z9Use comonad operations for context-aware transformations.�rur�rmrvrc�6�g|]}tj|����Srr)r	�vs  rrzITestComonadWorkflow.test_context_aware_transformation.<locals>.<listcomp>�s"��5�5�5��G�M�!�$�$�5�5�5r
rNr-r/�focusr1r3r4c�*�|���Sr6)�extractr*s rr,zGTestComonadWorkflow.test_context_aware_transformation.<locals>.<lambda>�s��Q�Y�Y�[�[�r
�extendedr�zz%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s.length
}()
}�sequence�r r!r"r@rB�py10�assert %(py12)s�py12�rrGrHr�rJrKrLrMrNrOrPrQ�extendrI)rVr=rXr�r�r`rYrar_r�rZ�@py_assert7�@py_assert9r\�@py_format11�@py_format13s                r�!test_context_aware_transformationz5TestComonadWorkflow.test_context_aware_transformation�sQ��!����5�5�f�5�5�5���?�6�7�+>�x�+H�+H�I�I��� � �"�"�� � �u�D� � � � � � � � � � �u�D� � � � � � � � � � � � �u� � � � � �u� � � � � � �D� � � � � � � � � � � � � � � � � � � � � � � � � ��?�?�#8�#8�9�9��#�#�x�t�#�#�#�#�#�#�#�#�#�#�x�t�#�#�#�#�#�#�#�#�#�#�#�#�x�#�#�#�#�#�x�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���5��� � �5�H�O�5�O�O�$5�$5�5� �$5�5�5�5�5�5�5�5�5�5�5� �$5�5�5�5�5�5�5�5�5�5�5�5�5�x�5�5�5�5�5�x�5�5�5�5�5�5��5�5�5�5� �5�5�5�5�5�5�5�5�5�5�5�H�5�5�5�5�5�H�5�5�5�5�5�5�O�5�5�5�5�$5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5�5r
c	�x�tjdtjgd�����}|���}d}||u}|s�t	jd|fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��d�z}dd	|iz}tt	j|�����dx}}|�d
���}|j
}|��}|j
}	|	��}
||
k}|�st	jd|fd||
f��d
t
j��vst	j|��rt	j	|��nd
t	j	|��t	j	|��dt
j��vst	j|��rt	j	|��ndt	j	|	��t	j	|
��d�z}dd|iz}
tt	j|
�����dx}x}x}x}	}
dS)z'Use comonad for sliding window pattern.r)r�r��r��#�(Nr-r/�currentr1r3r4c��|Sr6rr*s rr,zBTestComonadWorkflow.test_sliding_window_analysis.<locals>.<lambda>	s��a�r
rr��result�time_seriesr�r�r�r�)rVr�r�r`rYrar_r�rZr�r�r\r�r�s              r�test_sliding_window_analysisz0TestComonadWorkflow.test_sliding_window_analysis�sy���o�f�g�.A�B^�B^�B^�._�._�`�`���%�%�'�'��"�"�w�d�"�"�"�"�"�"�"�"�"�"�w�d�"�"�"�"�"�"�"�"�"�"�"�"�w�"�"�"�"�"�w�"�"�"�"�"�"�d�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"��#�#�K�K�0�0���}�6�}�}���6�+�"4�6�"4�"4�"6�"6�6��"6�6�6�6�6�6�6�6�6�6�6��"6�6�6�6�6�6�6�6�6�6�6�6�6�v�6�6�6�6�6�v�6�6�6�6�6�6�}�6�6�6�6��6�6�6�6�6�6�6�6�6�6�6�+�6�6�6�6�6�+�6�6�6�6�6�6�"4�6�6�6�6�"6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6r
N)r�r�r�r�r�r�rr
rr�r��s8������9�9�6�6�6�"7�7�7�7�7r
r�c��eZdZdZd�Zd�ZdS)�TestCombinationOperationsz$Test pattern combination operations.c�,�tjdtjgd�����}tjdtjgd�����}|�|��}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}
}	|j
}|��}|j
}
|
��}|j
}|��}t||��}||k}
|
�s�t	jd|
fd||f��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��dt
j��vst	jt��rt	j	t��nddt
j��vst	j|��rt	j	|��ndt	j	|
��t	j	|��dt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��t	j	|��d�z}dd|iz}tt	j|�����dx}x}x}
x}
x}x}x}}dS)z&Merge multiple patterns using combine.r)rur�rm)rvrr:Nr-r/�combinedr1r3r4r��>)zB%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.size
}()
} > %(py7)srr$r%ro)z�%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} >= %(py18)s
{%(py18)s = %(py6)s(%(py11)s
{%(py11)s = %(py9)s
{%(py9)s = %(py7)s.length
}()
}, %(py16)s
{%(py16)s = %(py14)s
{%(py14)s = %(py12)s.length
}()
})
}�max�p1�p2)r r!r"r@r#r%�py11r��py14�py16�py18zassert %(py20)s�py20)rrGrH�combinerJrKrLrMrNrOrPrQryrIr�)rVr�r�r�r`rYrar_rZr[r\r]r^�@py_assert8�@py_assert10�@py_assert13�@py_assert15�@py_assert17�@py_format19�@py_format21s                    r�test_merge_patternsz-TestCombinationOperations.test_merge_patternssI��
�_�V�W�%8����%C�%C�
D�
D��
�_�V�W�%8����%C�%C�
D�
D���:�:�b�>�>��#�#�x�t�#�#�#�#�#�#�#�#�#�#�x�t�#�#�#�#�#�#�#�#�#�#�#�#�x�#�#�#�#�#�x�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�
�}�"�}�}���"��"���"�"�"�"�"�"�"�"�"�"���"�"�"�"�"�"�"�"�"�"�"�"�x�"�"�"�"�"�x�"�"�"�"�"�"�}�"�"�"�"��"�"�"�"��"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"�"���A��� � �A��	�A�	�	���A�R�Y�A�Y�Y�[�[�A�C��[�$A�$A�A� �$A�A�A�A�A�A�A�A�A�A�A� �$A�A�A�A�A�A�A�A�A�A�A�A�A�x�A�A�A�A�A�x�A�A�A�A�A�A��A�A�A�A� �A�A�A�A�A�A�A�A�A�A�A�C�A�A�A�A�A�C�A�A�A�A�A�A�A�A�A�A�A�A�A��A�A�A�A�A��A�A�A�A�A�A�	�A�A�A�A��A�A�A�A�A�A�A�A�A�A�A�R�A�A�A�A�A�R�A�A�A�A�A�A�Y�A�A�A�A�[�A�A�A�A�$A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�Ar
c�V�td��}|�d��td��}|�d��tj|��}tj|��}|�|��}d}||u}|s�tjd|fd||f��dtj��vstj	|��rtj
|��ndtj
|��d	�z}d
d|iz}	ttj|	�����dx}}dS)z%Combine patterns containing subjects.zsubj-1�Type1zsubj-2�Type2Nr-r/r�r1r3r4)
rrErrr�rJrKrLrMrNrOrPrQ)
rV�s1�s2r�r�r�r`rYrar_s
          r�test_combine_with_subjectsz4TestCombinationOperations.test_combine_with_subjects s5��
�X�
�
��
���W����
�X�
�
��
���W����
�]�2�
�
��
�]�2�
�
���:�:�b�>�>��#�#�x�t�#�#�#�#�#�#�#�#�#�#�x�t�#�#�#�#�#�#�#�#�#�#�#�#�x�#�#�#�#�#�x�#�#�#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#r
N)r�r�r�r�rr
rr
rr�r�
s;������.�.�B�B�B� $�$�$�$�$r
r�c��eZdZdZd�Zd�ZdS)�TestErrorRecoveryz*Test error handling in complete workflows.c���g}td��D]>}td|����}|�d��|�|���?d�|D��}t	jdt	j|����}	|�d���}d}||u}|s�tj	d|fd	||f��d
tj��vstj|��rtj
|��nd
tj
|��d�z}	dd
|	iz}
ttj|
�����dx}}dS#t $�r+}t#|��}t%|��}d}
||
k}|s�tj	d|fd||
f��dtj��vstjt$��rtj
t$��nddtj��vstj|��rtj
|��ndtj
|��tj
|
��d�z}dd|iz}ttj|�����dx}x}}
Yd}~dSd}~wwxYw)z1Handle failures in part of a workflow gracefully.rzsubj-�Itemc�6�g|]}tj|����Srrrs  rrzCTestErrorRecovery.test_partial_failure_recovery.<locals>.<listcomp>;rr
rc��|Sr6rr7s rr,zATestErrorRecovery.test_partial_failure_recovery.<locals>.<lambda>As��1�r
Nr-r/r�r1r3r4rr�)z/%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py6)sr<�	error_msgr>rArB)rCrrEr�rrGrHrTrJrKrLrMrNrOrPrQ�	Exception�strr<)rVrWr
rrXr�r�r`rYrar_r�rr\rbrcrds                 r�test_partial_failure_recoveryz/TestErrorRecovery.test_partial_failure_recovery2s������q���	�	�A������$�$�A�
�K�K������O�O�A�����7�7�h�7�7�7���/�&�'�*=�h�*G�*G�H�H��	&��[�[���-�-�F�!%�%�6��%�%�%�%�%�%�%�%�%�%�6��%�%�%�%�%�%�%�%�%�%�%�%�6�%�%�%�%�%�6�%�%�%�%�%�%��%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%���	&�	&�	&��A���I��y�>�>�%�A�%�>�A�%�%�%�%�%�%�%�%�%�%�>�A�%�%�%�%�%�%�%�%�%�%�%�%�3�%�%�%�%�%�3�%�%�%�%�%�%�%�%�%�%�%�%�%�y�%�%�%�%�%�y�%�%�%�%�%�%�>�%�%�%�%�A�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�%�����	&���s�B9E�I6�D I1�1I6c��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}}|j}|��}|}|s�ddt
j��vst	j|��rt	j	|��ndt	j	|��t	j	|��d�z}tt	j|�����d
x}x}}t|�����}	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|
�����d
x}
x}}|�d���}|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*Validate data structure before processing.rr�rrrr+rr$r%Nr&r'r:r;r<r=r>rArBc��|dzS�Nr�rr7s rr,z<TestErrorRecovery.test_validation_workflow.<locals>.<lambda>Vs
���Q��r
r�)rrGrHrIrJrKrLrMrNrOrPrQrRrUr=r<rT)rVr+rYrZr[r\r]r^r_r=r`rbrcrdr�s               r�test_validation_workflowz*TestErrorRecovery.test_validation_workflowHs��
�O�F�G�$7����$H�$H�I�I���x��x�x�z�z��Q��z�Q�����������z�Q�������������q������q�������x�����z�����Q�������������������������������;� �;�;�=�=� �=� � � � � � � � � � � � � � �1� � � � � �1� � � � � � �;� � � � �=� � � � � � � � � � � � � � � � � � � � � ��a�h�h�j�j�!�!���6�{�{��a��{�a�����������{�a�������������s������s��������������6������6�������{�����a���������������������������������'�'���}�#�}�}���#�!�#��!�#�#�#�#�#�#�#�#�#�#��!�#�#�#�#�#�#�#�#�#�#�#�#�v�#�#�#�#�#�v�#�#�#�#�#�#�}�#�#�#�#��#�#�#�#�!�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#r
N)r�r�r�r�rrrr
rrr/s8������4�4�&�&�&�,$�$�$�$�$r
rc��eZdZdZd�Zd�ZdS)�TestPerformanceScenariosz(Test performance in realistic scenarios.c�x	�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���}	|	j}|��}||k}|s�t
jd|fd||f��dtj	��vst
j
|	��rt
j|	��ndt
j|��t
j|��dtj	��vst
j
|��rt
j|��ndd�z}dd	|iz}tt
j
|�����d
x}x}}|�d
���}
t!|
��}||k}|�st
jd|fd||f��dtj	��vst
j
t ��rt
jt ��nddtj	��vst
j
|
��rt
j|
��ndt
j|��dtj	��vst
j
|��rt
j|��ndd�z}
dd|
iz}tt
j
|�����d
x}}|�dd���}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)z$Process a large dataset efficiently.r�rr)zE%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.length
}()
} == %(py6)srGry�r r!r"r@rArBNc��|dzSrrr7s rr,zHTestPerformanceScenarios.test_large_dataset_processing.<locals>.<lambda>hs
���A��r
�doubledc��|dzdkS)Nr�rrr7s rr,zHTestPerformanceScenarios.test_large_dataset_processing.<locals>.<lambda>ls���Q��!��r
)�<=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} <= %(py5)sr<�evens)r r?r2r4zassert %(py7)sr#rc��|dzSr�rr�s  rr,zHTestPerformanceScenarios.test_large_dataset_processing.<locals>.<lambda>ps
��s�Q�w�r
ru)z%(py0)s == (%(py2)s + %(py4)s)r�r')rUrCrrGrHrIrJrKrLrMrNrOrPrQrTrSr<r�)rVry�datarGrYrZr\rcrdrr!r`rbr_r]r�s                r�test_large_dataset_processingz6TestPerformanceScenarios.test_large_dataset_processing]s�����E�$�K�K� � ���/�&�'�*=�d�*C�*C�D�D���~�'�~�~���'��4�'�'�'�'�'�'�'�'�'�'��4�'�'�'�'�'�'�'�'�'�'�'�'�w�'�'�'�'�'�w�'�'�'�'�'�'�~�'�'�'�'��'�'�'�'�'�'�'�'�'�'�'�4�'�'�'�'�'�4�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'��+�+�o�o�.�.���~�'�~�~���'��4�'�'�'�'�'�'�'�'�'�'��4�'�'�'�'�'�'�'�'�'�'�'�'�w�'�'�'�'�'�w�'�'�'�'�'�'�~�'�'�'�'��'�'�'�'�'�'�'�'�'�'�'�4�'�'�'�'�'�4�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'����3�3�4�4���5�z�z�!�z�T�!�!�!�!�!�!�!�!�!�!�z�T�!�!�!�!�!�!�!�!�!�!�!�!�s�!�!�!�!�!�s�!�!�!�!�!�!�!�!�!�!�!�!�!�5�!�!�!�!�!�5�!�!�!�!�!�!�z�!�!�!�!�!�!�!�!�!�!�!�T�!�!�!�!�!�T�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!����Q� 6� 6�7�7�� � ��q�� �u�� � � � � � � � � � �u�� � � � � � � � � � � � �u� � � � � �u� � � � � � � � � � � � � �� � � � � �� � � � � � �q� � � � � � � � � � � � � � � � � � � � � � � � � � � � � r
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}}|�
��}	d}
|	|
u}|s�tjd|fd
|	|
f��dtj��vstj	|	��rtj
|	��ndtj
|
��d�z}dd|iz}ttj|�����dx}}
dS)z.Traverse deeply nested structures efficiently.�2�*zlevel-ro)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.depth
}()
} >= %(py6)sr+rrrrArBNr-r/r�r1r3r4)rrrCrGrrrJrKrLrMrNrOrPrQr�)
rVrrr+r
rYrZr\rcrdr�r`rar_s
             r�test_deep_structure_traversalz6TestPerformanceScenarios.test_deep_structure_traversalss>�����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�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!��	�	���� � �u�D� � � � � � � � � � �u�D� � � � � � � � � � � � �u� � � � � �u� � � � � � �D� � � � � � � � � � � � � � � � � � � � � � � � � � � r
N)r�r�r�r�r$r(rr
rrrZs8������2�2�!�!�!�,
!�
!�
!�
!�
!r
r�__main__z-v)r��builtinsrL�_pytest.assertion.rewrite�	assertion�rewriterJ�pytest�pattern_corerrrr�r�r�rrr��main�__file__rr
r�<module>r2s������������������
�
�
�
�)�)�)�)�)�)�)�)�q)�q)�q)�q)�q)�q)�q)�q)�he!�e!�e!�e!�e!�e!�e!�e!�P 7� 7� 7� 7� 7� 7� 7� 7�F$�$�$�$�$�$�$�$�D($�($�($�($�($�($�($�($�V&!�&!�&!�&!�&!�&!�&!�&!�R�z����F�K��4� �!�!�!�!�!��r