B
    u9az  ã               @   sh   d Z ddlZddlmZ e d¡ZG dd„ dejƒZG dd„ deƒZ	G d	d
„ d
eƒZ
edkrde ¡  dS )z=
Test implementation of the PEP 509: dictionary versionning.
é    N)ÚsupportÚ	_testcapic               @   s   e Zd 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dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚDictVersionTestsc             C   s   t ƒ | _d | _d S )N)ÚsetÚseen_versionsÚdict)Úself© r	   ú'/usr/lib/python3.7/test_dict_version.pyÚsetUp   s    zDictVersionTests.setUpc             C   s(   t  |¡}|  || j¡ | j |¡ d S )N)r   Údict_get_versionZassertNotInr   Úadd)r   ÚmydictÚversionr	   r	   r
   Úcheck_version_unique   s    
z%DictVersionTests.check_version_uniquec             O   s   |||Ž}|   |¡ |S )N)r   )r   r   ÚmethodÚargsÚkwÚresultr	   r	   r
   Úcheck_version_changed   s    

z&DictVersionTests.check_version_changedc             O   s<   t  |¡}| j |¡ |||Ž}t  |¡}|  ||d¡ |S )Nzversion changed)r   r   r   r   ZassertEqual)r   r   r   r   r   Zversion1r   Zversion2r	   r	   r
   Úcheck_version_dont_change   s    


z*DictVersionTests.check_version_dont_changec             O   s   | j ||Ž}|  |¡ |S )N)Ú	type2testr   )r   r   r   Údr	   r	   r
   Únew_dict(   s    
zDictVersionTests.new_dictc             C   s6   |   ¡ }|   ¡ }|   ¡ }| j dd}| j ddd}d S )NÚx)r   Úy)r   r   )r   )r   Zempty1Zempty2Zempty3Z	nonempty1Z	nonempty2r	   r	   r
   Útest_constructor-   s
    z!DictVersionTests.test_constructorc             C   s*   | j ddd}|  ||j¡}|  |¡ d S )Né   é   )ÚaÚb)r   r   Úcopyr   )r   r   Úd2r	   r	   r
   Ú	test_copy7   s    zDictVersionTests.test_copyc             C   sT   |   ¡ }|  ||jdd¡ |  ||jdd¡ |  ||jdd¡ |  ||jdd¡ d S )Nr   r   r   r   )r   r   Ú__setitem__)r   r   r	   r	   r
   Útest_setitem?   s
    zDictVersionTests.test_setitemc             C   sd   t ƒ }|  ¡ }|  ||jd|¡ |  ||jd|¡ | j||j|d | j|d}|  ||j|¡ d S )NÚkey)r&   )Úobjectr   r   r$   Úupdate)r   Úvaluer   r"   r	   r	   r
   Útest_setitem_same_valueJ   s    z(DictVersionTests.test_setitem_same_valuec             C   s”   G dd„ dƒ}|ƒ }|ƒ }|   ||k¡ |  ||k¡ |  ¡ }|  ||jd|¡ |  ||jd|¡ | j||j|d | j|d}|  ||j|¡ d S )Nc               @   s   e Zd Zdd„ ZdS )z8DictVersionTests.test_setitem_equal.<locals>.AlwaysEqualc             S   s   dS )NTr	   )r   Úotherr	   r	   r
   Ú__eq__^   s    z?DictVersionTests.test_setitem_equal.<locals>.AlwaysEqual.__eq__N)Ú__name__Ú
__module__Ú__qualname__r,   r	   r	   r	   r
   ÚAlwaysEqual]   s   r0   r&   )r&   )Z
assertTrueZassertFalser   r   r$   r(   )r   r0   Úvalue1Úvalue2r   r"   r	   r	   r
   Útest_setitem_equal\   s    z#DictVersionTests.test_setitem_equalc             C   s0   |   ¡ }|  ||jdd¡ |  ||jdd¡ d S )Nr&   r1   r2   )r   r   Ú
setdefaultr   )r   r   r	   r	   r
   Útest_setdefaultt   s    z DictVersionTests.test_setdefaultc             C   s6   | j dd}|  ||jd¡ |  || jt|jd¡ d S )Nr)   )r&   r&   )r   r   Ú__delitem__r   ÚassertRaisesÚKeyError)r   r   r	   r	   r
   Útest_delitem}   s    zDictVersionTests.test_delitemc             C   s6   | j dd}|  ||jd¡ |  || jt|jd¡ d S )Nr)   )r&   r&   )r   r   Úpopr   r7   r8   )r   r   r	   r	   r
   Útest_pop‡   s    zDictVersionTests.test_popc             C   s2   | j dd}|  ||j¡ |  || jt|j¡ d S )Nr)   )r&   )r   r   Úpopitemr   r7   r8   )r   r   r	   r	   r
   Útest_popitem‘   s    zDictVersionTests.test_popitemc             C   sL   | j dd}|  ||j¡ | j||jdd | j dd}|  ||j|¡ d S )Nr)   )r&   z	new valuezvalue 3)r   r   r(   r   )r   r   r"   r	   r	   r
   Útest_update›   s
    zDictVersionTests.test_updatec             C   s,   | j dd}|  ||j¡ |  ||j¡ d S )Nr)   )r&   )r   r   Úclearr   )r   r   r	   r	   r
   Ú
test_clear§   s    zDictVersionTests.test_clearN)r-   r.   r/   r   r   r   r   r   r   r   r   r#   r%   r*   r3   r5   r9   r;   r=   r>   r@   r	   r	   r	   r
   r      s"   
	


r   c               @   s   e Zd ZdS )ÚDictN)r-   r.   r/   r	   r	   r	   r
   rA   ±   s   rA   c               @   s   e Zd ZeZdS )ÚDictSubtypeVersionTestsN)r-   r.   r/   rA   r   r	   r	   r	   r
   rB   µ   s   rB   Ú__main__)Ú__doc__ZunittestZtestr   Úimport_moduler   ZTestCaser   r   rA   rB   r-   Úmainr	   r	   r	   r
   Ú<module>   s   
 &