3
dc!                 @   s   d dl 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Z	G d	d
 d
eZ
G dd deZG dd deZG dd deZG dd deZG dd de jZdS )    N)	HasTraitsInstanceStrAnyPropertyc               @   s   e Zd ZeZdS )FooN)__name__
__module____qualname__r   s r   r   9/tmp/pip-build-7vycvbft/traits/traits/tests/test_clone.pyr      s   r   c               @   s$   e Zd ZeZeZdd Zdd ZdS )ClassWithAnyc             C   s   | j S )N)_x)selfr   r   r   _get_x   s    zClassWithAny._get_xc             C   s
   || _ d S )N)r   )r   xr   r   r   _set_x   s    zClassWithAny._set_xN)	r   r	   r
   r   r   r   r   r   r   r   r   r   r   r      s   r   c               @   s(   e Zd ZeZeeZdd Zdd Z	dS )ClassWithInstancec             C   s   | j S )N)r   )r   r   r   r   r   #   s    zClassWithInstance._get_xc             C   s
   || _ d S )N)r   )r   r   r   r   r   r   &   s    zClassWithInstance._set_xN)
r   r	   r
   r   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 )ClassWithClassAttributezclass defined nameN)r   r	   r
   namer   Zfoor   r   r   r   r   *   s   r   c               @   s   e Zd ZeZdS )BazAnyN)r   r	   r
   r   otherr   r   r   r   r   /   s   r   c               @   s   e Zd ZeZdS )BarAnyN)r   r	   r
   r   r   r   r   r   r   r   3   s   r   c               @   s0   e Zd ZedZeeZeeZeeddZdS )BazInstanceBarInstanceref)copyN)	r   r	   r
   r   r   r   uniquesharedr   r   r   r   r   r   7   s   r   c               @   s4   e Zd ZedddZeeZeeZeeddZdS )r   r   r   )r   N)	r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   I   s   r   c               @   sH   e Zd 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 )CloneTestCasez Test cases for traits clone c             C   sB   t  }t }d|_||_|jddd}| jt|jt|d d S )Nzthe falldeep)traitsr   zFoo x not cloned)r   r   r   r   clone_traitsassertNotEqualid)r   bfbcr   r   r   test_anya   s    zCloneTestCase.test_anyc             C   sB   t  }t }d|_||_|jddd}| jt|jt|d d S )Nzthe fr!   r"   )r#   r   zFoo x not cloned)r   r   r   r   r$   r%   r&   )r   r'   r(   r)   r   r   r   test_instancel   s    zCloneTestCase.test_instancec             C   sd   d}t  }| j||j t  }| j||j | j||j d}||_| j||j | j||j dS )a5   This test demonstrates a problem with Traits objects with class
        attributes.  A change to the value of a class attribute via one
        instance causes the attribute to be removed from other instances.

        AttributeError: 'ClassWithClassAttribute' object has no attribute
        'name'
        zclass defined namez&name class attribute changed via cloneN)r   ZassertEqualr   )r   r   cc2s2r   r   r   test_class_attribute_missingw   s    	z*CloneTestCase.test_class_attribute_missingc             C   sN   t  }t }||_||_|j }| j|| | j|j| | j|jj| d S )N)r   r   r   r$   assertIsNotassertIs)r   barbazbar_copyr   r   r   test_Any_circular_references   s    z*CloneTestCase.test_Any_circular_referencesc             C   sb   t  }t }||_||_|jdd}| j|| | j|j| | j|jj| | j|jj| d S )Nr"   )r   )r   r   r   r$   r0   r1   )r   r2   r3   r4   r   r   r   !test_Any_circular_references_deep   s    z/CloneTestCase.test_Any_circular_references_deepc       	      C   s  t dd}t dd}t dd}t dd}t }||_||_||_t }||_||_||_||_||_|j }| j|| | j|j| | j|j|j | j|j|j | j	|j| |j}| j|j|j | j	|j| | j|j| | j	|j| | j|j|j | j	|j|j d S )Nr   )r   zbar.foor   z
baz.unique)
r   r   r   r   r   r   r   r$   r0   r1   )	r   r   
bar_uniquer   
baz_uniquer3   r2   baz_copyr4   r   r   r   !test_Instance_circular_references   s6    



z/CloneTestCase.test_Instance_circular_referencesc       	      C   s  t dd}t dd}t dd}t dd}t }||_||_||_t }||_||_||_||_||_|jdd}| j|| | j|j| | j|j|j | j|j|j |j}| j|j|j | j	|j|j | j	|j| | j|j| | j	|j| | j|j|j | j	|j|j d S )Nr   )r   zbar.foor   z
baz.uniquer"   )r   )
r   r   r   r   r   r   r   r$   r0   r1   )	r   r   r7   r   r8   r3   r2   r9   r4   r   r   r   &test_Instance_circular_references_deep   s6    



z4CloneTestCase.test_Instance_circular_references_deepN)r   r	   r
   __doc__r*   r+   r/   r5   r6   r:   r;   r   r   r   r   r    ^   s   4r    )ZunittestZ
traits.apir   r   r   r   r   r   r   r   r   r   r   r   r   ZTestCaser    r   r   r   r   <module>   s   