a
    ¦ˆcŸ!  ã                   @   s˜   d dl Z d dlZd dlmZ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ƒZG d	d
„ d
eƒZG dd„ de jeƒZG dd„ de jƒZdS )é    N)ÚAnyÚcached_propertyÚComparisonModeÚ	HasTraitsÚPropertyÚStrc                   @   s   e Zd Zeejd�ZdS )ÚIdentityCompare©Zcomparison_modeN)Ú__name__Ú
__module__Ú__qualname__r   r   ÚidentityÚbar© r   r   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/tests/test_rich_compare.pyr      s   r   c                   @   s   e Zd Zeejd�ZdS )ÚRichComparer	   N)r
   r   r   r   r   Zequalityr   r   r   r   r   r      s   r   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 )ÚRichCompareTestsc                 C   s*   || _ || _|| _|| _|  jd7  _d S )Né   ©Úchanged_objectÚchanged_traitÚchanged_oldÚchanged_newÚchanged_count)ÚselfÚobjectÚtraitÚoldÚnewr   r   r   Úbar_changed   s
    zRichCompareTests.bar_changedc                 C   s"   d | _ d | _d | _d | _d| _d S )Nr   r   ©r   r   r   r   Úreset_change_tracker#   s
    z%RichCompareTests.reset_change_trackerc                 C   sJ   |   || j¡ |  || j¡ |   || j¡ |  || j¡ |  || j¡ d S ©N)ÚassertEqualr   ÚassertIsr   r   r   r   )r   r   r   r   r   Úcountr   r   r   Úcheck_tracker*   s
    zRichCompareTests.check_trackerc                 C   sB   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ d S ©Nr   r   ©r   Úon_trait_changer   r!   r   Úar&   ©r   ZicÚdefault_valuer   r   r   Útest_id_first_assignment1   s    z)RichCompareTests.test_id_first_assignmentc                 C   sB   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ d S r'   ©r   r)   r   r!   r   r*   r&   ©r   Zrichr,   r   r   r   Útest_rich_first_assignment;   s    z+RichCompareTests.test_rich_first_assignmentc                 C   s^   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d|| jd¡ d S r'   r(   r+   r   r   r   Útest_id_same_objectE   s    z$RichCompareTests.test_id_same_objectc                 C   s^   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d|| jd¡ d S r'   r.   r/   r   r   r   Útest_rich_same_objectR   s    z&RichCompareTests.test_rich_same_objectc                 C   s`   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d| j| jd¡ d S ©Nr   r   é   )r   r)   r   r!   r   r*   r&   Údifferent_from_ar+   r   r   r   Útest_id_different_object_   s    z)RichCompareTests.test_id_different_objectc                 C   s`   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d| j| jd¡ d S r3   )r   r)   r   r!   r   r*   r&   r5   r/   r   r   r   Útest_rich_different_objectl   s    z+RichCompareTests.test_rich_different_objectc                 C   s`   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d| j| jd¡ d S r3   )r   r)   r   r!   r   r*   r&   Ú	same_as_ar+   r   r   r   Ú test_id_different_object_same_asy   s    z1RichCompareTests.test_id_different_object_same_asc                 C   s^   t ƒ }| | jd¡ |  ¡  |j}| j|_|  |d|| jd¡ | j|_|  |d|| jd¡ d S r'   )r   r)   r   r!   r   r*   r&   r8   r/   r   r   r   Ú"test_rich_different_object_same_as†   s    z3RichCompareTests.test_rich_different_object_same_asN)r
   r   r   r   r!   r&   r-   r0   r1   r2   r6   r7   r9   r:   r   r   r   r   r      s   

r   c                   @   s    e Zd ZeZdd„ Zdd„ ZdS )ÚFooc                 C   s   | j |j kS r"   ©Úname©r   Úotherr   r   r   Ú__ne__™   s    z
Foo.__ne__c                 C   s   | j |j kS r"   r<   r>   r   r   r   Ú__eq__ž   s    z
Foo.__eq__N)r
   r   r   r   r=   r@   rA   r   r   r   r   r;   –   s   r;   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚRichCompareHasTraitsTestCasec                 C   s(   t dd�| _t dd�| _t dd�| _d S )Nr*   r<   znot a)r;   r*   r8   r5   r    r   r   r   ÚsetUp¤   s    z"RichCompareHasTraitsTestCase.setUpc                 C   sL   |   | j| j¡ |   | j| j¡ |  | jj| jj¡ |  | jj| jj¡ d S r"   )ZassertIsNotr*   r8   r5   r#   r=   ZassertNotEqualr    r   r   r   Útest_assumptions©   s    z-RichCompareHasTraitsTestCase.test_assumptionsN)r
   r   r   rC   rD   r   r   r   r   rB   £   s   rB   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚOldRichCompareTestCasec                    s8  t jdd��,}t  dt¡ G dd„ dtƒ}W d   ƒ n1 s>0    Y  |  t|ƒd¡ |d }|  |jt¡ |  	dt
|jƒ¡ t d	¡\}}}|  	||j¡ |ƒ }g ‰ | ‡ fd
d„d¡ g d¢}|  tˆ ƒd¡ ||_|  tˆ ƒd¡ ||_|  tˆ ƒd¡ g d¢|_|  tˆ ƒd¡ g d¢|_|  tˆ ƒd¡ d S )NT©ÚrecordÚalwaysc                   @   s   e Zd Zedd�ZdS )zFOldRichCompareTestCase.test_rich_compare_false.<locals>.OldRichCompareF©Zrich_compareN©r
   r   r   r   r   r   r   r   r   ÚOldRichCompare¶   s   rK   r   r   ú+'rich_compare' metadata has been deprecatedÚ.c                      s
   ˆ   d ¡S r"   ©Úappendr   ©Úeventsr   r   Ú<lambda>Ç   ó    z@OldRichCompareTestCase.test_rich_compare_false.<locals>.<lambda>r   ©r   r4   é   r4   ©é   é   é   rU   ©ÚwarningsÚcatch_warningsÚsimplefilterÚDeprecationWarningr   r#   Úlenr$   ÚcategoryZassertInÚstrÚmessager
   Ú
rpartitionÚfilenamer)   r   ©r   Z	warn_msgsrK   Zwarn_msgÚ_Zthis_moduleZold_compareZ	some_listr   rP   r   Útest_rich_compare_false²   s2    .þ

z.OldRichCompareTestCase.test_rich_compare_falsec                    s8  t jdd��,}t  dt¡ G dd„ dtƒ}W d   ƒ n1 s>0    Y  |  t|ƒd¡ |d }|  |jt¡ |  	dt
|jƒ¡ t d	¡\}}}|  	||j¡ |ƒ }g ‰ | ‡ fd
d„d¡ g d¢}|  tˆ ƒd¡ ||_|  tˆ ƒd¡ ||_|  tˆ ƒd¡ g d¢|_|  tˆ ƒd¡ g d¢|_|  tˆ ƒd¡ d S )NTrF   rH   c                   @   s   e Zd Zedd�ZdS )zEOldRichCompareTestCase.test_rich_compare_true.<locals>.OldRichCompareTrI   NrJ   r   r   r   r   rK   Ù   s   rK   r   r   rL   rM   c                      s
   ˆ   d ¡S r"   rN   r   rP   r   r   rR   ê   rS   z?OldRichCompareTestCase.test_rich_compare_true.<locals>.<lambda>r   rT   rV   r4   rZ   re   r   rP   r   Útest_rich_compare_trueÕ   s2    .þ

z-OldRichCompareTestCase.test_rich_compare_truec                    sV   G dd„ dt ƒ}|ƒ }g ‰ | ‡ fdd„d¡ d|_ˆ  ¡  d|_|  tˆ ƒd¡ d S )Nc                   @   s.   e Zd Zedd�Zeejd�Ze	dd„ ƒZ
dS )zLOldRichCompareTestCase.test_rich_compare_with_cached_property.<locals>.Modelr=   )Z
depends_onr	   c                 S   s   | j S r"   )Ztrait_namesr    r   r   r   Ú
_get_value   s    zWOldRichCompareTestCase.test_rich_compare_with_cached_property.<locals>.Model._get_valueN)r
   r   r   r   Úvaluer   r   Únoner=   r   ri   r   r   r   r   ÚModelü   s   
rl   c                      s
   ˆ   d ¡S r"   rN   r   rP   r   r   rR     rS   zOOldRichCompareTestCase.test_rich_compare_with_cached_property.<locals>.<lambda>rj   ÚAr   )r   r)   r=   Úclearr#   r_   )r   rl   Úinstancer   rP   r   Ú&test_rich_compare_with_cached_propertyø   s    z=OldRichCompareTestCase.test_rich_compare_with_cached_propertyN)r
   r   r   rg   rh   rp   r   r   r   r   rE   ±   s   ##rE   )Zunittestr[   Z
traits.apir   r   r   r   r   r   r   r   r   r;   ZTestCaserB   rE   r   r   r   r   Ú<module>   s    {