B
    u9a2  ã               @   sH   d dl Z d dlmZ d dlZG dd„ de jƒZdd„ ZedkrDeƒ  dS )é    N)Úsupportc               @   sì   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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/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚBoolTestc             C   sJ   yG dd„ dt ƒ}W n tk
r(   Y nX |  d¡ |  ttjt d¡ d S )Nc               @   s   e Zd ZdS )z!BoolTest.test_subclass.<locals>.CN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú/usr/lib/python3.7/test_bool.pyÚC   s   r	   zbool should not be subclassabler   )ÚboolÚ	TypeErrorZfailÚassertRaisesÚintÚ__new__)Úselfr	   r   r   r   Útest_subclass
   s    
zBoolTest.test_subclassc          	   C   s^   zBt tjdƒ}tdd|d | ¡  t tjdƒ}|  | ¡ d¡ W d | ¡  t tj¡ X d S )NÚwFT)ÚfileÚrzFalse True
)	Úopenr   ÚTESTFNÚprintÚcloseÚassertEqualÚreadÚosÚremove)r   Úfor   r   r   Ú
test_print   s    zBoolTest.test_printc             C   sL   |   tdƒd¡ |   tdƒd¡ |   ttdƒƒd¡ |   ttdƒƒd¡ d S )NFÚFalseTÚTrue)r   ÚreprÚeval)r   r   r   r   Ú	test_repr    s    zBoolTest.test_reprc             C   s$   |   tdƒd¡ |   tdƒd¡ d S )NFr   Tr   )r   Ústr)r   r   r   r   Útest_str&   s    zBoolTest.test_strc             C   sD   |   tdƒd¡ |  tdƒd¡ |   tdƒd¡ |  tdƒd¡ d S )NFr   Té   )r   r   ÚassertIsNot)r   r   r   r   Útest_int*   s    zBoolTest.test_intc             C   sD   |   tdƒd¡ |  tdƒd¡ |   tdƒd¡ |  tdƒd¡ d S )NFg        Tg      ð?)r   Úfloatr&   )r   r   r   r   Ú
test_float0   s    zBoolTest.test_floatc          	   C   s>  |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   tdƒd¡ |  tdƒd¡ |   dd¡ |  dd¡ |   dd¡ |   tdƒd¡ |  tdƒd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   dd¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   dd¡ |   dd¡ |   dd¡ |  dd¡ |   d	d¡ |  d	d¡ |   d
d¡ |  d
d¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ |   dd¡ |  dd¡ xRdD ]J}xBdD ]:}|   || t|ƒ| ¡ |  || tt|ƒ| ƒ¡ q0W q&W xdD ]}xdD ]þ}|  ||@ tt|ƒt|ƒ@ ƒ¡ |  ||B tt|ƒt|ƒB ƒ¡ |  ||A tt|ƒt|ƒA ƒ¡ |   |t|ƒ@ t|ƒt|ƒ@ ¡ |  |t|ƒ@ tt|ƒt|ƒ@ ƒ¡ |   |t|ƒB t|ƒt|ƒB ¡ |  |t|ƒB tt|ƒt|ƒB ƒ¡ |   |t|ƒA t|ƒt|ƒA ¡ |  |t|ƒA tt|ƒt|ƒA ƒ¡ |   t|ƒ|@ t|ƒt|ƒ@ ¡ |  t|ƒ|@ tt|ƒt|ƒ@ ƒ¡ |   t|ƒ|B t|ƒt|ƒB ¡ |  t|ƒ|B tt|ƒt|ƒB ƒ¡ |   t|ƒ|A t|ƒt|ƒA ¡ |  t|ƒ|A tt|ƒt|ƒA ƒ¡ qŠW q|W |  ddkd¡ |  ddkd¡ |  ddk d¡ |  ddk d¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ |  ddkd¡ dg}|  ||kd¡ |  ||k	d¡ |  d|kd¡ |  d|kd¡ |  d|kd¡ |  d|kd¡ ddi}|  ||kd¡ |  ||k	d¡ |  d|kd¡ |  d|kd¡ |  d|kd¡ |  d|kd¡ |  dd¡ |  dd¡ d S )Nr   Fr%   Téÿÿÿÿéþÿÿÿé   é   g      ð?g        )FT)r   r%   r,   )r   r&   Úabsr   r
   ÚassertIs)r   ÚbÚiÚaÚxr   r   r   Ú	test_math6   sº    

(    $ $ $ $ $ 0zBoolTest.test_mathc             C   s‚   |   ttdd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  td	ƒd¡ |  tƒ d¡ d S )
Né*   é
   Tr%   r*   r   FZhelloÚ )r   r   r
   r/   )r   r   r   r   Útest_convert£   s    zBoolTest.test_convertc          	   C   s&   |   td¡ tdd W d Q R X d S )Nzkeyword argumentr6   )r3   )ZassertRaisesRegexr   r
   )r   r   r   r   Útest_keyword_args­   s    zBoolTest.test_keyword_argsc             C   sD   |   dd d¡ |   dd d¡ |   dd d¡ |   dd d¡ d S )Nz%dFÚ0TÚ1z%x)r   )r   r   r   r   Útest_format±   s    zBoolTest.test_formatc             C   s(   |   tg dƒd¡ |   tg dƒd¡ d S )NÚappendTZwobbleF)r/   Úhasattr)r   r   r   r   Útest_hasattr·   s    zBoolTest.test_hasattrc             C   s$   |   ttƒd¡ |   tdƒd¡ d S )NTr%   F)r/   ÚcallableÚlen)r   r   r   r   Útest_callable»   s    zBoolTest.test_callablec             C   sp   |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ |   tdtƒd¡ d S )NTFr%   r   )r/   Ú
isinstancer
   r   )r   r   r   r   Útest_isinstance¿   s    zBoolTest.test_isinstancec             C   s(   |   tttƒd¡ |   tttƒd¡ d S )NTF)r/   Ú
issubclassr
   r   )r   r   r   r   Útest_issubclassÇ   s    zBoolTest.test_issubclassc             C   s(   |   di kd¡ |   dddikd¡ d S )Nr%   FT)r/   )r   r   r   r   Útest_containsË   s    zBoolTest.test_containsc             C   sŒ  |   d d¡d¡ |   d d¡d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d	 ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d
 ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ |   d	 ¡ d¡ |   d 	¡ d¡ |   d 	¡ d¡ |   d	 
¡ d¡ |   d 
¡ d¡ |   d d¡d¡ |   d d¡d¡ d S )NZxyzÚzTr3   FZxyz0123z@#$%Z0123ZXYZú õ   Â u   ã€€ÚX)r/   ÚendswithÚisalnumÚisalphaÚisdigitÚislowerÚ	isdecimalÚ	isnumericÚisspaceÚistitleÚisupperÚ
startswith)r   r   r   r   Útest_stringÏ   s0    zBoolTest.test_stringc             C   sp   |   dd¡ |  dt¡ |  dd¡ |   dd¡ |  dt¡ |  dd¡ |   dd¡ |  dt¡ |  dd¡ d S )Nr%   Tr   F)r   ZassertNotIsInstancer
   r/   )r   r   r   r   Útest_booleané   s    zBoolTest.test_booleanc          	   C   sH   z4t tjdƒ}|  |jd¡ | ¡  |  |jd¡ W d t tj¡ X d S )Nr   FT)r   r   r   r/   Úclosedr   r   r   )r   Úfr   r   r   Útest_fileclosedö   s    zBoolTest.test_fileclosedc             C   s8   x2t ttttttttt	t
gD ]}|  t |ƒd¡ qW d S )NT)r
   ÚcomplexÚdictr(   r   ÚlistÚobjectÚsetr#   ÚtupleÚtyper/   )r   Útr   r   r   Ú
test_typesÿ   s    zBoolTest.test_typesc             C   sö   dd l }|  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | g d¡d¡ |  | dgd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ d S )Nr   Fr%   T)Úoperatorr/   ÚtruthÚnot_ÚcontainsÚltÚis_Úis_not)r   re   r   r   r   Útest_operator  s    zBoolTest.test_operatorc             C   s<   dd l }|  | | d¡¡d¡ |  | | d¡¡d¡ d S )Nr   TF)Úmarshalr/   ÚloadsÚdumps)r   rm   r   r   r   Útest_marshal  s    zBoolTest.test_marshalc          	   C   sX   dd l }xJt|jd ƒD ]8}|  | | d|¡¡d¡ |  | | d|¡¡d¡ qW d S )Nr   r%   TF)ÚpickleÚrangeZHIGHEST_PROTOCOLr/   rn   ro   )r   rq   Úprotor   r   r   Útest_pickle  s    zBoolTest.test_picklec             C   s   dd l }|  |jdddd¡ |  |jdddd¡ |  |jdddd¡ |  |jdddd¡ |  |jdddd	¡ |  |jdddd
¡ d S )Nr   T)Zprotocols   I01
.Fs   I00
.r%   r,   s   €ˆ.s   €‰.)rq   r   ro   )r   rq   r   r   r   Útest_picklevalues  s    zBoolTest.test_picklevaluesc                s–   ‡ fdd„}G dd„ dt ƒ}||ƒ ƒ G dd„ dt ƒ}||ƒ ƒ G dd„ dtƒ}||ƒ ƒ G d	d
„ d
tƒ}||ƒ ƒ G dd„ dƒ}ˆ  tt|ƒ ¡ d S )Nc                s   ˆ   tt| ¡S )N)r   r   r
   )Úo)r   r   r   Ú<lambda>-  ó    z/BoolTest.test_convert_to_bool.<locals>.<lambda>c               @   s   e Zd Zdd„ ZdS )z*BoolTest.test_convert_to_bool.<locals>.Fooc             S   s   | S )Nr   )r   r   r   r   Ú__bool__/  s    z3BoolTest.test_convert_to_bool.<locals>.Foo.__bool__N)r   r   r   ry   r   r   r   r   ÚFoo.  s   rz   c               @   s   e Zd Zdd„ ZdS )z*BoolTest.test_convert_to_bool.<locals>.Barc             S   s   dS )NZYesr   )r   r   r   r   ry   4  s    z3BoolTest.test_convert_to_bool.<locals>.Bar.__bool__N)r   r   r   ry   r   r   r   r   ÚBar3  s   r{   c               @   s   e Zd Zdd„ ZdS )z*BoolTest.test_convert_to_bool.<locals>.Bazc             S   s   | S )Nr   )r   r   r   r   ry   9  s    z3BoolTest.test_convert_to_bool.<locals>.Baz.__bool__N)r   r   r   ry   r   r   r   r   ÚBaz8  s   r|   c               @   s   e Zd Zdd„ ZdS )z+BoolTest.test_convert_to_bool.<locals>.Spamc             S   s   dS )Nr%   r   )r   r   r   r   ry   ?  s    z4BoolTest.test_convert_to_bool.<locals>.Spam.__bool__N)r   r   r   ry   r   r   r   r   ÚSpam>  s   r}   c               @   s   e Zd Zdd„ ZdS )z+BoolTest.test_convert_to_bool.<locals>.Eggsc             S   s   dS )Nr*   r   )r   r   r   r   Ú__len__D  s    z3BoolTest.test_convert_to_bool.<locals>.Eggs.__len__N)r   r   r   r~   r   r   r   r   ÚEggsC  s   r   )r_   r   r   Ú
ValueErrorr
   )r   Zcheckrz   r{   r|   r}   r   r   )r   r   Útest_convert_to_bool)  s    



zBoolTest.test_convert_to_boolc             C   s,   |   t dd¡d¡ |   t dd¡d¡ d S )Ns           ZbigFs   abcdÚlittleT)r/   r
   Ú
from_bytes)r   r   r   r   Útest_from_bytesH  s    zBoolTest.test_from_bytesc                sœ   x–dD ]Ž‰ G ‡ fdd„dƒ}yt |ƒ ƒ W q tk
r’ } zJyt|ƒ ƒ W n6 tk
r€ } z|  t|ƒt|ƒ¡ W d d }~X Y nX W d d }~X Y qX qW d S )N)Zillegalr*   l        c                   s   e Zd Z‡ fdd„ZdS )z!BoolTest.test_sane_len.<locals>.Ac                s   ˆ S )Nr   )r   )Úbadvalr   r   r~   Q  s    z)BoolTest.test_sane_len.<locals>.A.__len__N)r   r   r   r~   r   )r…   r   r   ÚAP  s   r†   )r
   Ú	ExceptionrA   r   r#   )r   r†   Ze_boolZe_lenr   )r…   r   Útest_sane_lenL  s    
zBoolTest.test_sane_lenc             C   s@   G dd„ dƒ}|   tt|ƒ ¡ G dd„ dƒ}|   tt|ƒ ¡ d S )Nc               @   s   e Zd ZdZdS )z BoolTest.test_blocked.<locals>.AN)r   r   r   ry   r   r   r   r   r†   \  s   r†   c               @   s   e Zd Zdd„ ZdZdS )z BoolTest.test_blocked.<locals>.Bc             S   s   dS )Nr6   r   )r   r   r   r   r~   a  s    z(BoolTest.test_blocked.<locals>.B.__len__N)r   r   r   r~   ry   r   r   r   r   ÚB`  s   r‰   )r   r   r
   )r   r†   r‰   r   r   r   Útest_blocked[  s    zBoolTest.test_blockedc             C   s„   |   djd¡ |   djd¡ |  tdjƒt¡ |  tdjƒt¡ |   djd¡ |   djd¡ |  tdjƒt¡ |  tdjƒt¡ d S )NTr%   r   F)r   ÚrealÚimagr/   rb   r   )r   r   r   r   Útest_real_and_imagf  s    zBoolTest.test_real_and_imagN)r   r   r   r   r   r"   r$   r'   r)   r4   r8   r9   r<   r?   rB   rD   rF   rG   rW   rX   r[   rd   rl   rp   rt   ru   r   r„   rˆ   rŠ   r   r   r   r   r   r      s8   m
	
r   c               C   s   t  t¡ d S )N)r   Zrun_unittestr   r   r   r   r   Ú	test_mainp  s    rŽ   Ú__main__)ZunittestZtestr   r   ZTestCaser   rŽ   r   r   r   r   r   Ú<module>   s     j