a
    ¦ˆcP  ã                   @   s¢   d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
 G dd„ deƒZG dd„ deƒZdd	„ Zd
d„ ZG dd„ dƒZG dd„ dee jƒZG dd„ dee jƒZdS )é    N©Úreset_global_adaptation_manager)ÚBaseInstanceÚBoolÚ	HasTraitsÚInstanceÚListÚregister_factoryÚ
TraitErrorc                   @   s   e Zd ZedƒZdS )ÚFooFN)Ú__name__Ú
__module__Ú__qualname__r   Údefault© r   r   úi/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/tests/test_automatic_adaptation.pyr      s   r   c                   @   s   e Zd ZdS )ÚBarN)r   r   r   r   r   r   r   r      s   r   c                 C   s   t ƒ S ©N©r   )Úbarr   r   r   Úbar_to_foo_adapter!   s    r   c                   C   s
   t dd�S )NT)r   r   r   r   r   r   Údefault_foo%   s    r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚAutomaticAdaptationTestMixinz�
    Mixin for tests to be applied to both Instance and BaseInstance.

    Subclasses should define the class variable 'trait_under_test'.
    c                 C   s
   t ƒ  d S r   r   )Úselfr   r   r   ÚsetUp2   s    z"AutomaticAdaptationTestMixin.setUpc                 C   s,  t ƒ }|  ¡ }|  t¡� ||_W d   ƒ n1 s40    Y  |  t¡� ||_W d   ƒ n1 sd0    Y  ||_|  |j¡ ||_|  	|jt
¡ |  |jj¡ ttt t
ƒ |  t¡� ||_W d   ƒ n1 sÔ0    Y  ||_|  	|jt
¡ ||_|  	|jt
¡ ||_|  	|jt
¡ |  |jj¡ d S r   )r   Úcreate_foo_containerÚassertRaisesr
   Únot_adapting_fooÚadapting_fooÚadapting_foo_permissiveZassertIsNoneÚadapting_foo_dynamic_defaultÚassertIsInstancer   Ú
assertTruer   r	   r   ZassertFalse©r   r   Zfoo_containerr   r   r   Ú(test_instance_trait_automatic_adaptation7   s*    $$$zEAutomaticAdaptationTestMixin.test_instance_trait_automatic_adaptationc                 C   sÎ   t ƒ }|  ¡ }|  t¡� |g|_W d   ƒ n1 s60    Y  |  t¡� |g|_W d   ƒ n1 sh0    Y  ttt tƒ |  t¡� |g|_W d   ƒ n1 s¦0    Y  |g|_|  	|jd t¡ d S )Nr   )
r   r   r   r
   Únot_adapting_foo_listÚadapting_foo_listr	   r   r   r!   r#   r   r   r   Ú$test_list_trait_automatic_adaptationY   s    &&&zAAutomaticAdaptationTestMixin.test_list_trait_automatic_adaptationc                    s    | j ‰ G ‡ fdd„dtƒ}|ƒ S )Nc                       sR   e Zd Z” eƒZ” edd�Z” edd�Z” eded�Ze	eƒZ
e	” edd�ƒZdS )zGAutomaticAdaptationTestMixin.create_foo_container.<locals>.FooContainerÚyes)Úadaptr   )r)   ÚfactoryN)r   r   r   r   r   r   r   r   r    r   r%   r&   r   ©Zinstance_traitr   r   ÚFooContainers   s   ýr,   )Útrait_under_testr   )r   r,   r   r+   r   r   o   s    z1AutomaticAdaptationTestMixin.create_foo_containerN)r   r   r   Ú__doc__r   r$   r'   r   r   r   r   r   r   )   s
   "r   c                   @   s   e Zd ZdZeZdS )ÚTestAutomaticAdaptationInstancez7
    Tests for automatic adaptation with Instance.
    N)r   r   r   r.   r   r-   r   r   r   r   r/   ‚   s   r/   c                   @   s   e Zd ZdZeZdS )Ú#TestAutomaticAdaptationBaseInstancez;
    Tests for automatic adaptation with BaseInstance.
    N)r   r   r   r.   r   r-   r   r   r   r   r0   �   s   r0   )ZunittestZtraits.adaptation.apir   Z
traits.apir   r   r   r   r   r	   r
   r   r   r   r   r   ZTestCaser/   r0   r   r   r   r   Ú<module>   s   $Y
ÿ
ÿ