relateby-pattern 0.2.9

Core pattern data structures
Documentation
�

��}i�
��^�dZddlZddlmcmZddlZddlZd�Z	d�Z
d�Zd�Zd�Z
d�Zd	�ZdS)
z5
Tests for Pattern validation and structure analysis
�Nc�X�tjdd���}|j}d}||k}|s�tjd|fd||f��dtj��vstj|��rtj|��ndtj|��tj|��d�z}dd	|iz}ttj
|�����d
x}x}}|j}d}||k}|s�tjd|fd||f��dtj��vstj|��rtj|��ndtj|��tj|��d�z}dd	|iz}ttj
|�����d
x}x}}tj��}|j}d
}||u}|s�tjd|fd
||f��dtj��vstj|��rtj|��ndtj|��tj|��d�z}dd	|iz}ttj
|�����d
x}x}}|j}d
}||u}|s�tjd|fd||f��dtj��vstj|��rtj|��ndtj|��tj|��d�z}dd	|iz}ttj
|�����d
x}x}}d
S)zTest creating validation rules�
�d��	max_depth�max_elements)�==)z1%(py2)s
{%(py2)s = %(py0)s.max_depth
} == %(py5)s�rules��py0�py2�py5�assert %(py7)s�py7N)z4%(py2)s
{%(py2)s = %(py0)s.max_elements
} == %(py5)s)�is)z1%(py2)s
{%(py2)s = %(py0)s.max_depth
} is %(py5)s�rules2)z4%(py2)s
{%(py2)s = %(py0)s.max_elements
} is %(py5)s)�pattern_core�ValidationRulesr�
@pytest_ar�_call_reprcompare�@py_builtins�locals�_should_repr_global_name�	_saferepr�AssertionError�_format_explanationr)r
�@py_assert1�@py_assert4�@py_assert3�@py_format6�@py_format8rs       �a/Users/akollegger/Developer/gram-data/gram-rs/crates/pattern-core/tests/python/test_validation.py�test_validation_rules_creationr#s����(�2�C�H�H�H�E��?� �b� �?�b� � � � � � � � � � �?�b� � � � � � � � � � � � �5� � � � � �5� � � � � � �?� � � � �b� � � � � � � � � � � � � � � � � � � � � � � � � � � ���$��$���$�$�$�$�$�$�$�$�$�$���$�$�$�$�$�$�$�$�$�$�$�$�5�$�$�$�$�$�5�$�$�$�$�$�$��$�$�$�$��$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$��
)�
+�
+�F���#�t�#��t�#�#�#�#�#�#�#�#�#�#��t�#�#�#�#�#�#�#�#�#�#�#�#�6�#�#�#�#�#�6�#�#�#�#�#�#��#�#�#�#�t�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���&�$�&��$�&�&�&�&�&�&�&�&�&�&��$�&�&�&�&�&�&�&�&�&�&�&�&�6�&�&�&�&�&�6�&�&�&�&�&�&��&�&�&�&�$�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�&�c��tj�dtj�d��tj�d��g��}tjdd���}|�|��dS)z)Test validation passes for valid patterns�root�child1�child2�rrN)r�Pattern�pattern�pointr�validate�r+r
s  r"�test_pattern_validate_passesr/s|���"�*�*�6���"�"�8�,�,���"�"�8�,�,�4���G�

�(�1�2�F�F�F�E����U�����r$c��tj�dtj�dtj�dtj�d��g��g��g��}tjd���}tjtd���5|�|��d	d	d	��d	S#1swxYwYd	S)
z-Test validation fails when max depth exceededr&�child�
grandchildzgreat-grandchild��r�Validation error��matchN)	rr*r+r,r�pytest�raises�
ValueErrorr-r.s  r"�%test_pattern_validate_fails_max_depthr;!s���"�*�*�6���$�$�W�� �(�(���$�*�*�+=�>�>�8�
�
�/
�	�	�4���G�
�(�1�5�5�5�E�	��z�);�	<�	<�	<� � �������� � � � � � � � � � � � ���� � � � � � s�-C�C�Cc�4�d�td��D��}tj�d|��}tjd���}tjtd���5|�|��ddd��dS#1swxYwYdS)	z0Test validation fails when max elements exceededc�R�g|]$}tj�d|������%S)r1)rr*r,)�.0�is  r"�
<listcomp>z<test_pattern_validate_fails_max_elements.<locals>.<listcomp>5s/��K�K�K�A��$�*�*�;�1�;�;�7�7�K�K�Kr$rr&r))rr5r6N)	�rangerr*r+rr8r9r:r-)�elementsr+r
s   r"�(test_pattern_validate_fails_max_elementsrC2s���L�K��r���K�K�K�H��"�*�*�6�8�<�<�G��(�a�8�8�8�E�	��z�);�	<�	<�	<� � �������� � � � � � � � � � � � ���� � � � � � s�*B
�
B�Bc	�h�tj�dtj�dtj�d��g��tj�d��g��}|���}|j}d}||u}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��d	�z}d
d|iz}tt
j
|�����dx}x}}|j}t|t��}|�sdd
tj	��vst
j
t��rt
jt��nd
dtj	��vst
j
|��rt
j|��ndt
j|��dtj	��vst
j
t��rt
jt��ndt
j|��d�z}	tt
j
|	�����dx}}|j}t!|��}d}
||
k}|�st
jd|fd||
f��dtj	��vst
j
t ��rt
jt ��nddtj	��vst
j
|��rt
j|��ndt
j|��t
j|��t
j|
��d�z}dd|iz}
tt
j
|
�����dx}x}x}}
|j}d}||u}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��d	�z}d
d|iz}tt
j
|�����dx}x}}|j}t|t$��}|�sdd
tj	��vst
j
t��rt
jt��nd
dtj	��vst
j
|��rt
j|��ndt
j|��dtj	��vst
j
t$��rt
jt$��ndt
j|��d�z}	tt
j
|	�����dx}}|j}d}||u}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��d	�z}d
d|iz}tt
j
|�����dx}x}}|j}t|t$��}|�sdd
tj	��vst
j
t��rt
jt��nd
dtj	��vst
j
|��rt
j|��ndt
j|��dtj	��vst
j
t$��rt
jt$��ndt
j|��d�z}	tt
j
|	�����dx}}|j}d}||u}|s�t
jd|fd||f��dtj	��vst
j
|��rt
j|��ndt
j|��t
j|��d	�z}d
d|iz}tt
j
|�����dx}x}}|j}t|t$��}|�sdd
tj	��vst
j
t��rt
jt��nd
dtj	��vst
j
|��rt
j|��ndt
j|��dtj	��vst
j
t$��rt
jt$��ndt
j|��d�z}	tt
j
|	�����dx}}dS)zTest structure analysisr&�a�x�bN��is not�z3%(py2)s
{%(py2)s = %(py0)s.summary
} is not %(py5)s�analysisrrr�Rassert %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.summary
}, %(py4)s)
}�
isinstance�str�r�py1�py3�py4�py6r)�>)zL%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.summary
})
} > %(py8)s�len)rrPrQr�py8zassert %(py10)s�py10)z>%(py2)s
{%(py2)s = %(py0)s.depth_distribution
} is not %(py5)sz]assert %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.depth_distribution
}, %(py4)s)
}�list)z:%(py2)s
{%(py2)s = %(py0)s.element_counts
} is not %(py5)szYassert %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.element_counts
}, %(py4)s)
})z<%(py2)s
{%(py2)s = %(py0)s.nesting_patterns
} is not %(py5)sz[assert %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.nesting_patterns
}, %(py4)s)
})rr*r+r,�analyze_structure�summaryrrrrrrrrrMrNrU�depth_distributionrX�element_counts�nesting_patterns)r+rKrrrr r!�@py_assert2�@py_assert5�@py_format7�@py_assert7�@py_assert6�@py_format9�@py_format11s              r"�test_pattern_analyze_structurere>s�	���"�*�*�6���$�$�S�� �&�&�s�+�+�+
�	�	�	��"�"�3�'�'�	4���G��(�(�*�*�H���'�4�'��4�'�'�'�'�'�'�'�'�'�'��4�'�'�'�'�'�'�'�'�'�'�'�'�8�'�'�'�'�'�8�'�'�'�'�'�'��'�'�'�'�4�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'��&�,�:�&��,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�:�,�,�,�,�,�:�,�,�,�,�,�,�,�,�,�,�,�,�,�h�,�,�,�,�,�h�,�,�,�,�,�,�&�,�,�,�,�,�,�,�,�,�,�,��,�,�,�,�,��,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,���$�3�� � �$�1�$� �1�$�$�$�$�$�$�$�$�$�$� �1�$�$�$�$�$�$�$�$�$�$�$�$�3�$�$�$�$�$�3�$�$�$�$�$�$�$�$�$�$�$�$�$�x�$�$�$�$�$�x�$�$�$�$�$�$��$�$�$�$� �$�$�$�$�1�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$��&�2�d�2�&�d�2�2�2�2�2�2�2�2�2�2�&�d�2�2�2�2�2�2�2�2�2�2�2�2�8�2�2�2�2�2�8�2�2�2�2�2�2�&�2�2�2�2�d�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2��1�8�:�1�4�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�:�8�8�8�8�8�:�8�8�8�8�8�8�8�8�8�8�8�8�8�h�8�8�8�8�8�h�8�8�8�8�8�8�1�8�8�8�8�8�8�8�8�8�8�8�4�8�8�8�8�8�4�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8��"�.�$�.�"�$�.�.�.�.�.�.�.�.�.�.�"�$�.�.�.�.�.�.�.�.�.�.�.�.�8�.�.�.�.�.�8�.�.�.�.�.�.�"�.�.�.�.�$�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.�.��-�4�:�-�t�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�h�4�4�4�4�4�h�4�4�4�4�4�4�-�4�4�4�4�4�4�4�4�4�4�4�t�4�4�4�4�4�t�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��$�0�D�0�$�D�0�0�0�0�0�0�0�0�0�0�$�D�0�0�0�0�0�0�0�0�0�0�0�0�8�0�0�0�0�0�8�0�0�0�0�0�0�$�0�0�0�0�D�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0�0��/�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�h�6�6�6�6�6�h�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�6�6�6�6�6�6�6�6�6�6�6�6�6r$c��tjddhi���}tj�|tj�|��g��}tjd���}|�|��dS)z$Test validation for Pattern[Subject]�alice�Person��identity�labels�
propertiesr)r4N)r�Subjectr*r+r,rr-)�subjectr+r
s   r"�test_pattern_subject_validateroXs����"���z�����G��"�*�*��	�	�	#�	#�G�	,�	,�-���G�

�(�1�5�5�5�E����U�����r$c���tjddhi���}tj�|tj�|��g��}|���}|j}d}||u}|s�tjd|fd||f��dtj
��vstj|��rtj|��ndtj|��tj|��d�z}d	d
|iz}ttj|�����dx}x}}|j}t|t ��}	|	�sddtj
��vstjt��rtjt��nddtj
��vstj|��rtj|��ndtj|��d
tj
��vstjt ��rtjt ��nd
tj|	��d�z}
ttj|
�����dx}}	dS)z,Test structure analysis for Pattern[Subject]rgrhriNrHrJrKrrrrLrMrNrO)rrmr*r+r,rYrZrrrrrrrrrMrN)rnr+rKrrrr r!r^r_r`s           r"�&test_pattern_subject_analyze_structurerqkss���"���z�����G��"�*�*��	�	�	#�	#�G�	,�	,�-���G�
�(�(�*�*�H���'�4�'��4�'�'�'�'�'�'�'�'�'�'��4�'�'�'�'�'�'�'�'�'�'�'�'�8�'�'�'�'�'�8�'�'�'�'�'�'��'�'�'�'�4�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'�'��&�,�:�&��,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�:�,�,�,�,�,�:�,�,�,�,�,�,�,�,�,�,�,�,�,�h�,�,�,�,�,�h�,�,�,�,�,�,�&�,�,�,�,�,�,�,�,�,�,�,��,�,�,�,�,��,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,�,r$)�__doc__�builtinsr�_pytest.assertion.rewrite�	assertion�rewriterr8rr#r/r;rCrerorq�r$r"�<module>rxs������������������
�
�
�
�����	'�	'�	'�
�
�
� � � �"	 �	 �	 �7�7�7�4���&-�-�-�-�-r$