a
    ¦ˆc¾'  ã                   @   sr   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
 G dd„ deƒZG dd„ deƒZG d	d
„ d
ejƒZdS )z" Tests for the dynamic notifiers. é    N)Útrait_notifiers)ÚEventÚFloatÚ	HasTraitsÚListÚon_trait_changec                   @   sô   e Zd ZeZeZeZeZ	eZ
eZeZeZeZeZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd	„ ƒZedƒd
d„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS ) ÚDynamicNotifiersÚokc                 C   s   | j  d¡ d S ©NT)Úrebind_calls_0Úappend©Úself© r   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/tests/test_dynamic_notifiers.pyÚmethod_listener_0$   s    z"DynamicNotifiers.method_listener_0c                 C   s   | j  |¡ d S ©N)Úrebind_calls_1r   ©r   Únewr   r   r   Úmethod_listener_1(   s    z"DynamicNotifiers.method_listener_1c                 C   s   | j  ||f¡ d S r   )Úrebind_calls_2r   ©r   Únamer   r   r   r   Úmethod_listener_2,   s    z"DynamicNotifiers.method_listener_2c                 C   s   | j  |||f¡ d S r   )Úrebind_calls_3r   ©r   Úobjr   r   r   r   r   Úmethod_listener_30   s    z"DynamicNotifiers.method_listener_3c                 C   s   | j  ||||f¡ d S r   )Úrebind_calls_4r   ©r   r   r   Úoldr   r   r   r   Úmethod_listener_44   s    z"DynamicNotifiers.method_listener_4Úfailc                 C   s   | j  d¡ tdƒ‚d S ©Nr   Úerror©Úexceptions_fromr   Ú	Exceptionr   r   r   r   Úfailing_method_listener_0:   s    z*DynamicNotifiers.failing_method_listener_0c                 C   s   | j  d¡ tdƒ‚d S ©Né   r%   r&   r   r   r   r   Úfailing_method_listener_1?   s    z*DynamicNotifiers.failing_method_listener_1c                 C   s   | j  d¡ tdƒ‚d S ©Né   r%   r&   r   r   r   r   Úfailing_method_listener_2D   s    z*DynamicNotifiers.failing_method_listener_2c                 C   s   | j  d¡ tdƒ‚d S ©Né   r%   r&   r   r   r   r   Úfailing_method_listener_3I   s    z*DynamicNotifiers.failing_method_listener_3c                 C   s   | j  d¡ tdƒ‚d S ©Né   r%   r&   r    r   r   r   Úfailing_method_listener_4N   s    z*DynamicNotifiers.failing_method_listener_4c                 C   s   | j  d¡ d S ©Nr   ©Úprioritized_notificationsr   r   r   r   r   Úlow_priority_firstS   s    z#DynamicNotifiers.low_priority_firstc                 C   s   | j  d¡ d S )Nr+   r7   r   r   r   r   Úhigh_priority_firstV   s    z$DynamicNotifiers.high_priority_firstc                 C   s   | j  d¡ d S )Nr.   r7   r   r   r   r   Úlow_priority_secondY   s    z$DynamicNotifiers.low_priority_secondc                 C   s   | j  d¡ d S )Nr1   r7   r   r   r   r   Úhigh_priority_second\   s    z%DynamicNotifiers.high_priority_secondN)Ú__name__Ú
__module__Ú__qualname__r   r	   r#   r   Úpriority_testr   r   r   r   r   r   r'   r8   r   r   r   r   r   r"   r)   r,   r/   r2   r5   r9   r:   r;   r<   r   r   r   r   r      sD   









r   c                   @   s$   e Zd ZdZeZdd„ Zdd„ ZdS )ÚUnhashableDynamicNotifiersz9 Class that cannot be used as a key in a dictionary.
    c                 C   s
   t ƒ ‚d S r   ©ÚNotImplementedErrorr   r   r   r   Ú__hash__f   s    z#UnhashableDynamicNotifiers.__hash__c                 C   s
   t ƒ ‚d S r   rB   r   r   r   r   Ú__eq__i   s    z!UnhashableDynamicNotifiers.__eq__N)r=   r>   r?   Ú__doc__r   Úa_listrD   rE   r   r   r   r   rA   `   s   rA   c                   @   sd   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚTestDynamicNotifiersc                 C   s   g | _ t | j¡ d S r   )Ú
exceptionsr   Zpush_exception_handlerÚ_handle_exceptionr   r   r   r   ÚsetUpq   s    zTestDynamicNotifiers.setUpc                 C   s   t  ¡  d S r   )r   Zpop_exception_handlerr   r   r   r   ÚtearDownu   s    zTestDynamicNotifiers.tearDownc                 C   s   | j  ||||f¡ d S r   )rI   r   r    r   r   r   rJ   z   s    z&TestDynamicNotifiers._handle_exceptionc                 C   sš   t dd�}d|_|  t|jƒd¡ ddg}|  ||j¡ ddg}|  ||j¡ |ddf|ddfg}|  ||j¡ |dddf|dddfg}|  ||j¡ d S )Nr.   )r	   r1   )r	   r.   )r	   r1   r	   r   )	r   r	   ÚassertEqualÚlenr   r   r   r   r   )r   r   Ú
expected_1Ú
expected_2Ú
expected_3Ú
expected_4r   r   r   Útest_dynamic_notifiers_methods   s    
z3TestDynamicNotifiers.test_dynamic_notifiers_methodsc                 C   s>   t ƒ }d|_|  g d¢|j¡ |  |dddfgd | j¡ d S )Nr+   ©r   r+   r.   r1   r4   r#   r   é   )r   r#   ÚassertCountEqualr'   rM   rI   )r   r   r   r   r   Ú&test_dynamic_notifiers_methods_failing‘   s    z;TestDynamicNotifiers.test_dynamic_notifiers_methods_failingc                    s"  g ‰ ‡ fdd„}g ‰‡fdd„}g ‰‡fdd„}g ‰‡fdd„}g ‰‡fd	d
„}t ƒ }| |d¡ | |d¡ | |d¡ | |d¡ | |d¡ d|_d|_ddg}|  |ˆ ¡ ddg}|  |ˆ¡ ddg}	|  |	ˆ¡ |ddf|ddfg}
|  |
ˆ¡ |dddf|dddfg}|  |ˆ¡ d S )Nc                      s   ˆ   d¡ d S )Nr   ©r   r   )Úcalls_0r   r   Úfunction_listener_0›   s    zRTestDynamicNotifiers.test_dynamic_notifiers_functions.<locals>.function_listener_0c                    s   ˆ   | f¡ d S r   rX   ©r   )Úcalls_1r   r   Úfunction_listener_1    s    zRTestDynamicNotifiers.test_dynamic_notifiers_functions.<locals>.function_listener_1c                    s   ˆ   | |f¡ d S r   rX   ©r   r   )Úcalls_2r   r   Úfunction_listener_2¥   s    zRTestDynamicNotifiers.test_dynamic_notifiers_functions.<locals>.function_listener_2c                    s   ˆ   | ||f¡ d S r   rX   ©r   r   r   )Úcalls_3r   r   Úfunction_listener_3ª   s    zRTestDynamicNotifiers.test_dynamic_notifiers_functions.<locals>.function_listener_3c                    s   ˆ   | |||f¡ d S r   rX   ©r   r   r!   r   )Úcalls_4r   r   Úfunction_listener_4¯   s    zRTestDynamicNotifiers.test_dynamic_notifiers_functions.<locals>.function_listener_4r	   r.   r1   r   )ç       @)ç      @)r	   rg   )r	   rh   rg   rh   g        )r   r   r	   rM   )r   rZ   r]   r`   rc   rf   r   Z
expected_0rO   rP   rQ   rR   r   )rY   r\   r_   rb   re   r   Ú test_dynamic_notifiers_functions˜   s8    z5TestDynamicNotifiers.test_dynamic_notifiers_functionsc                 C   s¤   t ƒ }tddgƒ}tddgƒ}| |jd¡ |j|jddd� | |jd¡ |j|jddd� d |_t|jd d… ƒ}t|jdd … ƒ}|  	||¡ |  	||¡ d S )Nr+   r1   r   r.   r@   T)Úpriority)
r   Úsetr   r9   r:   r;   r<   r@   r8   ZassertSetEqual)r   r   Zexpected_highZexpected_lowÚhighÚlowr   r   r   Útest_priority_notifiers_firstÌ   s     ÿÿz2TestDynamicNotifiers.test_priority_notifiers_firstc                    sÊ   t ƒ }g ‰ ‡ fdd„}‡ fdd„}‡ fdd„}‡ fdd„}‡ fd	d
„}| |d¡ | |d¡ | |d¡ | |d¡ | |d¡ d|_|  g d¢ˆ ¡ |  g d¢|j¡ |  |dddfgd | j¡ d S )Nc                      s   ˆ   d¡ tdƒ‚d S r$   ©r   r(   r   ©r'   r   r   Úfailing_function_listener_0é   s    
zbTestDynamicNotifiers.test_dynamic_notifiers_functions_failing.<locals>.failing_function_listener_0c                    s   ˆ   d¡ tdƒ‚d S r*   ro   r[   rp   r   r   Úfailing_function_listener_1í   s    
zbTestDynamicNotifiers.test_dynamic_notifiers_functions_failing.<locals>.failing_function_listener_1c                    s   ˆ   d¡ tdƒ‚d S r-   ro   r^   rp   r   r   Úfailing_function_listener_2ñ   s    
zbTestDynamicNotifiers.test_dynamic_notifiers_functions_failing.<locals>.failing_function_listener_2c                    s   ˆ   d¡ tdƒ‚d S r0   ro   ra   rp   r   r   Úfailing_function_listener_3õ   s    
zbTestDynamicNotifiers.test_dynamic_notifiers_functions_failing.<locals>.failing_function_listener_3c                    s   ˆ   d¡ tdƒ‚d S r3   ro   rd   rp   r   r   Úfailing_function_listener_4ù   s    
zbTestDynamicNotifiers.test_dynamic_notifiers_functions_failing.<locals>.failing_function_listener_4r#   r+   rT   r   é
   )r   r   r#   rM   rV   r'   rI   )r   r   rq   rr   rs   rt   ru   r   rp   r   Ú(test_dynamic_notifiers_functions_failingä   s     z=TestDynamicNotifiers.test_dynamic_notifiers_functions_failingc                    s^   dd l }dd„ }tƒ }| |d¡ g ‰ ‡ fdd„}| ||¡}~|  ˆ dg¡ |  |ƒ ¡ d S )Nr   c                   S   s   d S r   r   r   r   r   r   Úlistener  s    zKTestDynamicNotifiers.test_object_can_be_garbage_collected.<locals>.listenerr	   c                    s   ˆ   d¡ d S r
   rX   ©Úweakref©Zobj_collectedr   r   Úobj_collected_callback  s    zYTestDynamicNotifiers.test_object_can_be_garbage_collected.<locals>.obj_collected_callbackT)rz   r   r   ÚrefrM   ÚassertIsNone©r   rz   rx   r   r|   Zobj_weakrefr   r{   r   Ú$test_object_can_be_garbage_collected  s    z9TestDynamicNotifiers.test_object_can_be_garbage_collectedc                    sl   dd l }dd„ }tƒ }| |d¡ |j tƒ ¡ g ‰ ‡ fdd„}| ||¡}~|  ˆ dg¡ |  |ƒ ¡ d S )Nr   c                   S   s   d S r   r   r   r   r   r   rx   -  s    zVTestDynamicNotifiers.test_unhashable_object_can_be_garbage_collected.<locals>.listenerz	a_list:okc                    s   ˆ   d¡ d S r
   rX   ry   r{   r   r   r|   :  s    zdTestDynamicNotifiers.test_unhashable_object_can_be_garbage_collected.<locals>.obj_collected_callbackT)rz   rA   r   rG   r   r}   rM   r~   r   r   r{   r   Ú/test_unhashable_object_can_be_garbage_collected'  s    zDTestDynamicNotifiers.test_unhashable_object_can_be_garbage_collectedc                 C   s"   t  ¡  tƒ  |  t  ¡ d¡ d S r6   )ÚgcZcollectr   rM   r   r   r   r   Ú2test_creating_notifiers_dont_create_cyclic_garbageF  s    zGTestDynamicNotifiers.test_creating_notifiers_dont_create_cyclic_garbageN)r=   r>   r?   rK   rL   rJ   rS   rW   ri   rn   rw   r€   r�   rƒ   r   r   r   r   rH   m   s   4'rH   )rF   r‚   ZunittestZtraitsr   Z
traits.apir   r   r   r   r   r   rA   ZTestCaserH   r   r   r   r   Ú<module>   s   M