B
    v9aÊ  ã               @   sT   d dl mZmZ G dd„ dƒZG dd„ dƒZG dd„ deeƒZG dd	„ d	eeƒZd
S )é    )ÚPyTestÚCTestc               @   s   e Zd ZdS )ÚJSONTestObjectN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú$/usr/lib/python3.7/test_recursion.pyr      s   r   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestRecursionc             C   s˜   g }|  |¡ y|  |¡ W n tk
r0   Y nX |  d¡ g }|g}|  |¡ y|  |¡ W n tk
rr   Y nX |  d¡ g }||g}|  |¡ d S )Nz)didn't raise ValueError on list recursionz5didn't raise ValueError on alternating list recursion)ÚappendÚdumpsÚ
ValueErrorÚfail)ÚselfÚxÚyr   r   r	   Útest_listrecursion	   s$    



z TestRecursion.test_listrecursionc             C   sV   i }||d< y|   |¡ W n tk
r.   Y nX |  d¡ i }||dœ}|   |¡ d S )NZtestz)didn't raise ValueError on dict recursion)ÚaÚb)r   r   r   )r   r   r   r   r   r	   Útest_dictrecursion    s    

z TestRecursion.test_dictrecursionc             C   sd   G dd„ d| j jƒ}|ƒ }|  | t¡d¡ d|_y| t¡ W n tk
rT   Y nX |  d¡ d S )Nc               @   s   e Zd ZdZdd„ ZdS )zATestRecursion.test_defaultrecursion.<locals>.RecursiveJSONEncoderFc             S   s$   |t kr| jrt gS dS tj |¡S )Nr   )r   ÚrecurseZpyjsonÚJSONEncoderÚdefault)r   Úor   r   r	   r   1   s
    zITestRecursion.test_defaultrecursion.<locals>.RecursiveJSONEncoder.defaultN)r   r   r   r   r   r   r   r   r	   ÚRecursiveJSONEncoder/   s   r   z"JSONTestObject"Tz,didn't raise ValueError on default recursion)Újsonr   ZassertEqualÚencoder   r   r   r   )r   r   Úencr   r   r	   Útest_defaultrecursion.   s    
z#TestRecursion.test_defaultrecursionc          	   C   s”   |   t¡  |  dd d dd  ¡ W d Q R X |   t¡  |  dd d dd  ¡ W d Q R X |   t¡  |  dd d dd  ¡ W d Q R X d S )Nz{"a":i † Ú1Ú}z[1]ú[ú])ÚassertRaisesÚRecursionErrorÚloads)r   r   r   r	   Ú#test_highly_nested_objects_decodingD   s    $$z1TestRecursion.test_highly_nested_objects_decodingc          	   C   sp   g i  }}x t dƒD ]}|gd|i }}qW |  t¡ |  |¡ W d Q R X |  t¡ |  |¡ W d Q R X d S )Ni † Úk)Úranger#   r$   r   )r   ÚlÚdr   r   r   r	   Ú#test_highly_nested_objects_encodingN   s    
z1TestRecursion.test_highly_nested_objects_encodingc          	   C   s>   G dd„ d| j jƒ}|  t¡ |dd d¡ W d Q R X d S )Nc               @   s   e Zd Zdd„ ZdS )z@TestRecursion.test_endless_recursion.<locals>.EndlessJSONEncoderc             S   s   |gS )Nr   )r   r   r   r   r	   r   [   s    zHTestRecursion.test_endless_recursion.<locals>.EndlessJSONEncoder.defaultN)r   r   r   r   r   r   r   r	   ÚEndlessJSONEncoderZ   s   r,   F)Zcheck_circulary              @)r   r   r#   r$   r   )r   r,   r   r   r	   Útest_endless_recursionX   s    z$TestRecursion.test_endless_recursionN)	r   r   r   r   r   r   r&   r+   r-   r   r   r   r	   r
      s   

r
   c               @   s   e Zd ZdS )ÚTestPyRecursionN)r   r   r   r   r   r   r	   r.   c   s    r.   c               @   s   e Zd ZdS )ÚTestCRecursionN)r   r   r   r   r   r   r	   r/   d   s    r/   N)Ztest.test_jsonr   r   r   r
   r.   r/   r   r   r   r	   Ú<module>   s   [