a
    ¦ˆc·  ã                   @   sº   d Z ddlZddlmZ ddlmZmZmZ G dd„ deƒZg Z	dd„ Z
g Zd	d
„ Zg Zdd„ Zg Zdd„ Zg Zdd„ Zg Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ dejƒZdS )a0   Tests for the extended notifiers.

The "extended notifiers" are set up internally when using extended traits, to
add/remove traits listeners when one of the intermediate traits changes.

For example, in a listener for the extended trait `a.b`, we need to add/remove
listeners to `a:b` when `a` changes.
é    N)Útrait_notifiers)ÚFloatÚ	HasTraitsÚListc                       sŒ   e Zd Z‡ fdd„ZeZeZeZeZ	eZ
eZeZe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‡  ZS )ÚExtendedNotifiersc                    sz   | j | j| j| j| jg}|D ]}| j|ddd� q| j| j| j| j	| j
g}|D ]}| j|ddd� qNtƒ jf i |¤Ž d S )NÚokÚextended©ÚdispatchÚfail)Úmethod_listener_0Úmethod_listener_1Úmethod_listener_2Úmethod_listener_3Úmethod_listener_4Ú_on_trait_changeÚfailing_method_listener_0Úfailing_method_listener_1Úfailing_method_listener_2Úfailing_method_listener_3Úfailing_method_listener_4ÚsuperÚ__init__)ÚselfÚtraitsZok_listenersZlistenerZfail_listeners©Ú	__class__© úg/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/tests/test_extended_notifiers.pyr      s"    ûûzExtendedNotifiers.__init__c                 C   s   | j  d¡ d S ©NT)Úrebind_calls_0Úappend©r   r   r   r   r   B   s    z#ExtendedNotifiers.method_listener_0c                 C   s   | j  |¡ d S ©N)Úrebind_calls_1r!   ©r   Únewr   r   r   r   E   s    z#ExtendedNotifiers.method_listener_1c                 C   s   | j  ||f¡ d S r#   )Úrebind_calls_2r!   ©r   Únamer&   r   r   r   r   H   s    z#ExtendedNotifiers.method_listener_2c                 C   s   | j  |||f¡ d S r#   )Úrebind_calls_3r!   ©r   Úobjr)   r&   r   r   r   r   K   s    z#ExtendedNotifiers.method_listener_3c                 C   s   | j  ||||f¡ d S r#   )Úrebind_calls_4r!   ©r   r,   r)   Úoldr&   r   r   r   r   N   s    z#ExtendedNotifiers.method_listener_4c                 C   s   | j  d¡ tdƒ‚d S ©Nr   Úerror©Úexceptions_fromr!   Ú	Exceptionr"   r   r   r   r   S   s    z+ExtendedNotifiers.failing_method_listener_0c                 C   s   | j  d¡ tdƒ‚d S ©Né   r1   r2   r%   r   r   r   r   W   s    z+ExtendedNotifiers.failing_method_listener_1c                 C   s   | j  d¡ tdƒ‚d S ©Né   r1   r2   r(   r   r   r   r   [   s    z+ExtendedNotifiers.failing_method_listener_2c                 C   s   | j  d¡ tdƒ‚d S ©Né   r1   r2   r+   r   r   r   r   _   s    z+ExtendedNotifiers.failing_method_listener_3c                 C   s   | j  d¡ tdƒ‚d S ©Né   r1   r2   r.   r   r   r   r   c   s    z+ExtendedNotifiers.failing_method_listener_4)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r    r$   r'   r*   r-   r3   r   r   r   r   r   r   r   r   r   r   Ú__classcell__r   r   r   r   r      s&   r   c                   C   s   t  d¡ d S r   )Úcalls_0r!   r   r   r   r   Úfunction_listener_0l   s    rB   c                 C   s   t  | ¡ d S r#   )Úcalls_1r!   ©r&   r   r   r   Úfunction_listener_1s   s    rE   c                 C   s   t  | |f¡ d S r#   )Úcalls_2r!   ©r)   r&   r   r   r   Úfunction_listener_2z   s    rH   c                 C   s   t  | ||f¡ d S r#   )Úcalls_3r!   ©r,   r)   r&   r   r   r   Úfunction_listener_3�   s    rK   c                 C   s   t  | |||f¡ d S r#   )Úcalls_4r!   ©r,   r)   r/   r&   r   r   r   Úfunction_listener_4ˆ   s    rN   c                   C   s   t  d¡ tdƒ‚d S r0   r2   r   r   r   r   Úfailing_function_listener_0‘   s    
rO   c                 C   s   t  d¡ tdƒ‚d S r5   r2   rD   r   r   r   Úfailing_function_listener_1–   s    
rP   c                 C   s   t  d¡ tdƒ‚d S r7   r2   rG   r   r   r   Úfailing_function_listener_2›   s    
rQ   c                 C   s   t  d¡ tdƒ‚d S r9   r2   rJ   r   r   r   Úfailing_function_listener_3    s    
rR   c                 C   s   t  d¡ tdƒ‚d S r;   r2   rM   r   r   r   Úfailing_function_listener_4¥   s    
rS   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S )ÚTestExtendedNotifiersc                 C   s   g | _ t | j¡ d S r#   )Ú
exceptionsr   Zpush_exception_handlerÚ_handle_exceptionr"   r   r   r   ÚsetUp®   s    zTestExtendedNotifiers.setUpc                 C   s   t  ¡  d S r#   )r   Zpop_exception_handlerr"   r   r   r   ÚtearDown²   s    zTestExtendedNotifiers.tearDownc                 C   s   | j  ||||f¡ d S r#   )rU   r!   r.   r   r   r   rV   ·   s    z'TestExtendedNotifiers._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 )Nr8   )r   r:   ©r   r8   ©r   r:   r   r   )	r   r   ÚassertEqualÚlenr    r$   r'   r*   r-   )r   r,   Ú
expected_1Ú
expected_2Ú
expected_3Ú
expected_4r   r   r   Útest_extended_notifiers_methods¼   s    
z5TestExtendedNotifiers.test_extended_notifiers_methodsc                 C   s>   t ƒ }d|_|  g d¢|j¡ |  |dddfgd | j¡ d S )Nr6   ©r   r6   r8   r:   r<   r   r   é   )r   r   ÚassertCountEqualr3   r[   rU   ©r   r,   r   r   r   Ú'test_extended_notifiers_methods_failingÎ   s    z=TestExtendedNotifiers.test_extended_notifiers_methods_failingc                 C   s  t  ¡  t ¡  t ¡  t ¡  t ¡  tƒ }|jtddd� |jt	ddd� |jt
ddd� |jtddd� |jtddd� d|_d|_ddg}|  |t ¡ ddg}|  |t¡ ddg}|  |t¡ |ddf|ddfg}|  |t¡ |dd	df|dddfg}|  |t¡ d S )
Nr   r   r	   r8   r:   TrY   rZ   r   )rA   ÚclearrC   rF   rI   rL   r   r   rB   rE   rH   rK   rN   r   r[   )r   r,   Z
expected_0r]   r^   r_   r`   r   r   r   Ú!test_extended_notifiers_functionsÕ   s.    z7TestExtendedNotifiers.test_extended_notifiers_functionsc                 C   s–   t ƒ }t ¡  |jtddd� |jtddd� |jtddd� |jtddd� |jtddd� d|_	|  
g d¢|j¡ |  |dddfgd | j¡ d S )Nr   r   r	   r6   rb   r   é
   )r   r3   rg   r   rO   rP   rQ   rR   rS   r   rd   r[   rU   re   r   r   r   Ú)test_extended_notifiers_functions_failingö   s(    ÿÿÿÿÿz?TestExtendedNotifiers.test_extended_notifiers_functions_failingN)
r=   r>   r?   rW   rX   rV   ra   rf   rh   rj   r   r   r   r   rT   ª   s   !rT   )Ú__doc__Zunittestr   r   Z
traits.apir   r   r   r   rA   rB   rC   rE   rF   rH   rI   rK   rL   rN   r3   rO   rP   rQ   rR   rS   ZTestCaserT   r   r   r   r   Ú<module>   s*   P