U
    H4f ^                  #   @   s:  d Z ddlZddlZddlmZmZmZ ddlmZmZm	Z	 ddlm
Z
mZmZmZ edddddd	ddd
	e
dfeddedfeddddddddd	e
dfeddde
dfedde
dfedde
dfedde
dfedde
dfedde
dfeddde
dfed	de
dfeddedfed de
d!feddddd"e
dfedddd#e
dfeddde
dfedde
dfed$de
d%fedddd&e
dfeddd'e
dfed(d)e
dfed*d)d+d,fedde
dfed-d.ddd/d0dd1d2	e
dfed3dd2d-d"e
dfedddddd	ddd
	edfd4Zd5Zed6dd7ed8dd9d#ed8dd9d#fed6dd:ed8dd9d#ed8dd9d#fed6dd7ed8dd9d#ed8dd9d#fed6dd:ed8dd9d#ed8dd9d#fed6dd;ed8dd9d#ed8dd9d#fed6dded8dd9d#ed8dd9d#fed<dded=ded=dfed6ddeddd8dd9d>ed?d8dd9d@fed<ddeddd8dd9d>ed?d8dd9d@ff	Zed<ddedddAedBddfed<dd7edddAedBdd7fed<dd7eddedBddCfedDdd7edded<dd7fedEdd7eddedFddCfed<dded3d3dAedGddfed<dd7ed3d3dAedGdd7fed<ddeddddHedBddfed<dd7eddddHedBddfed<dd7edddIedBddfedDdd7edddIed<ddfedEdd7edddIedFddfed<dded3d3d3dHedJdd:fed<dd7ed3d3d3dHedGddCfedBdded3d3d3dHed<dd7fed<dded3d3d3dHedGddCfedddAeddddHeddddHfed3d3d3dHed<ddedGddCfeddddKed<ddedBddfedLed<ddedBddfedMed<dddfeddddNed<ddddOdedBddCdOdOdfedPed<ddddOdedBddCdOdOdfedddAeddeddddHfeddedddAeddddHfed6ddddedded6ddddfedQdRedSed6ddddfed6ddedded6ddfedQdTedSed6ddffZedddAdedddAfedddAd2ed2d2dAfdedddAedddAfd2edddAed2d2dAfdeddUdVed8dd9dWfd.eddUdVedXd2dYdWfdZedddUdKeddd[dKffZG d\d] d]ejZd^d_ Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zedlkr6ejdidm dS )nz(
Test cases for the isoduration module.
    N)	timedeltadatedatetime)Durationparse_durationISO8601Error)	D_DEFAULTD_WEEK	D_ALT_EXTduration_isoformat      	            )weeks                  )hoursdaysyears   months)minutesg      ?$   )r   P1DT12H)r   r   r   ZP11Dgz-P15DT9H36M)r   r   r    seconds)r   r   r    gffffff@ZPT2H18M)r   r    r%   )r    r%      r%   gQ86@zPT%S.%fSzPT22.220000Siii)ZP18Y9M4DT11H9M8SZP2WZP3Y6M4DT12H30M5SZP23DT23HZP4YP1MZPT1MP0.5YZPT36Hr"   z+P11Dz-P2Wz-P2.2WZ
P1DT2H3M4SZP1DT2H3MZP1DT2HZPT2HzPT2.3HZPT2H3M4SZPT3M4SZPT22SzPT22.22Sz-P2Yz-P3Y6M4DT12H30M5Sz-P1DT2H3M4SzP0018-09-04T11:09:08))zP5Y7M1DT9H45M16.72SzPT27M24.68SzP5Y7M1DT10H12M41.4SzP5Y7M1DT9H17M52.04SN)zPT28M12.73SzPT56M29.92SzPT1H24M42.65Sz-PT28M17.19SF)P3Y7M23DT5H25M0.33S	PT1H1.95SP3Y7M23DT6H25M2.28SzP3Y7M23DT4H24M58.38SN)r/   r.   r0   z-P3Y7M23DT4H24M58.38SN)P1332DT55M0.33Sr/   P1332DT1H55M2.28SzP1331DT23H54M58.38ST)r/   r1   r2   z-P1331DT23H54M58.38SFi     
              i)r   r   r   r   r       )r   r   r   r    r   r        i  i0  i4  i  r   r   r   )r   r     r   r   r   ZP1Y1M5Wr-   )r   r   r      ZP1Y1MT3HZ200802z%Y%Mr,   z%Y%m(   )r   r    )r   r   r    ii   i  c                   @   sX   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d Zdd ZdS )DurationTestz
    This class tests various other aspects of the isoduration module,
    which are not covered with the test cases listed above.
    c                 C   sH   t dd}t dd}tddd}|| | }|| | }| || dS )zB
        Adding 2 durations to a date is not associative.
        r   r#   r   r8   r   r   N)r   r   assertNotEqual)selfZdays1Zmonths1startZres1Zres2 rG   ?/tmp/pip-unpacked-wheel-giipsm8b/isodate/tests/test_duration.pytest_associative
  s    

zDurationTest.test_associativec              
   C   s   |  tttddd |  ttjtddtddd |  ttjdtdd |  ttjtddddd |  ttjdtdddd |  ttjtddddd |  ttjdtdddd |  ttjtddddd |  ttjdtdddd d	S )
zE
        Test if TypError is raised with certain parameters.
        r8   r   r   z	raise excr   r?   zraise exceptiongQ	@N)	assertRaises	TypeErrorr   r   operatorsubr   addmulrE   rG   rG   rH   test_typeerror  s8    



zDurationTest.test_typeerrorc                 C   s   |  ttd dS )z7
        Test for unparseable duration string.
        z	T10:10:10N)rJ   r   r   rP   rG   rG   rH   test_parseerror.  s    zDurationTest.test_parseerrorc                 C   sh   t ddddd}| dt| | dt| t dd}| dt| t dd}| d	t| d
S )zA
        Test __repr__ and __str__ for Duration objects.
        r4   r:   z%10 years, 10 months, 10 days, 0:00:10z9isodate.duration.Duration(10, 10, 0, years=10, months=10)r   r   z0:00:00r   z1 month, 0:00:00N)r   assertEqualstrreprrE   ZdurrG   rG   rH   	test_repr4  s    

zDurationTest.test_reprc                 C   s   t ddddd}t ddddd}t ddddd}| t|t| | t|t| | t|t| | t|t| t }|| || || | t|d dS )z5
        Test __hash__ for Duration objects.
        r4   r:   r   r   N)r   rD   hashidrS   setrN   len)rE   dur1dur2Zdur3ZdurSetrG   rG   rH   	test_hashA  s    


zDurationTest.test_hashc                 C   s   |  td td |  tddd tddd |  tddd tdd | tdd tdd	 | td
d	 tdd dS )z4
        Test __neg__ for Duration objects.
        r   r   r:   r+   ir   r   ir#   m  N)rS   r   rD   r   rP   rG   rG   rH   test_negR  s    
zDurationTest.test_negc                 C   s   |  ttdd |  ttd d |  ttddd |  ttdddd |  ttd	d	d d |  ttddd d
 |  ttddd d
 tddddddd}|  t|d |  t| d dS )z;
        Test various other strftime combinations.
        r   ZP0Dr4   r'   ZPT10Sr+   r:   z-P1Y1Mr   ZP1Y1Mr   rB   r   r      iJ  )r   r   r   r   r    millisecondsr.   z-P3Y7M23DT5H25M0.33SN)rS   r   r   rV   rG   rG   rH   test_format`  s(    zDurationTest.test_formatc                 C   s.  |  tdddtddd |  tdddtdd | tdddtddd | tdddtdd | tddtdd	 | tdddtdddk | tdddtddk | tdddtdddk | tdddtddk | tddtdd	k |  tdd	tdd	 d
S )z1
        Test __eq__ and __ne__ methods.
        r   r:   r9   r   r      r   r_   r#   N)rS   r   rD   r   ZassertFalse
assertTruerP   rG   rG   rH   
test_equalt  s&    



zDurationTest.test_equalc                 C   s   t dddd}| |tdddtd | |tdddtd	 t dd
}| |tdddtd | |tdddtd | |tdddtd dS )z=
        Test conversion form Duration to timedelta.
        r   r   r4   r=   r>   ra   i  r8   i  r   <   r;   ;   r   =   N)r   rS   Ztotimedeltar   r   rV   rG   rG   rH   test_totimedelta  s    
zDurationTest.test_totimedeltaN)__name__
__module____qualname____doc__rI   rQ   rR   rW   r^   r`   rc   rf   rj   rG   rG   rG   rH   rC     s   rC   c                    s*   G  fdddt j}t  |S )z
    Create a TestCase class for a specific test.

    This allows having a separate TestCase for each test tuple from the
    PARSE_TEST_CASES list, so that a failed test won't stop other tests.
    c                       s0   e Zd ZdZfddZ fddZdS )z/create_parsetestcase.<locals>.TestParseDurationzs
        A test case template to parse an ISO duration string into a
        timedelta or Duration object.
        c                    s   t  }| | dS )z\
            Parse an ISO duration string and compare it to the expected value.
            N)r   rS   )rE   result)durationstringexpectationrG   rH   
test_parse  s    z:create_parsetestcase.<locals>.TestParseDuration.test_parsec                    s.    r|  t  n|  t dS )z
            Take duration/timedelta object and create ISO string from it.
            This is the reverse test to test_parse.
            N)rS   r   rP   altstrrp   rq   formatrG   rH   rc     s    z;create_parsetestcase.<locals>.TestParseDuration.test_formatN)rk   rl   rm   rn   rr   rc   rG   rs   rG   rH   TestParseDuration  s   rv   unittestTestCase
TestLoaderloadTestsFromTestCase)rp   rq   ru   rt   rv   rG   rs   rH   create_parsetestcase  s    r|   c                    sL   t   t t t G  fdddtj}t |S )z
    Create a TestCase class for a specific test.

    This allows having a separate TestCase for each test tuple from the
    MATH_TEST_CASES list, so that a failed test won't stop other tests.
    c                       s@   e Zd ZdZ fddZ fddZ fddZdS )	z-create_mathtestcase.<locals>.TestMathDurationzo
        A test case template test addition, subtraction and >
        operators for Duration objects.
        c                    s   |     dS )z=
            Test operator + (__add__, __radd__)
            NrS   rP   )r\   r]   resaddrG   rH   test_add  s    z6create_mathtestcase.<locals>.TestMathDuration.test_addc                    s   |     dS )z=
            Test operator - (__sub__, __rsub__)
            Nr}   rP   )r\   r]   ressubrG   rH   test_sub  s    z6create_mathtestcase.<locals>.TestMathDuration.test_subc                    s`    fdd} fdd}dkr>|  t| |  t| n| |  | |   dS )z/
            Test operator > and <
            c                      s    kS )z Test greater than.rG   rG   r\   r]   rG   rH   dogetest  s    zGcreate_mathtestcase.<locals>.TestMathDuration.test_ge.<locals>.dogetestc                      s    k S )z Test less than.rG   rG   r   rG   rH   doletest  s    zGcreate_mathtestcase.<locals>.TestMathDuration.test_ge.<locals>.doletestN)rJ   rK   rS   )rE   r   r   )r\   r]   resgerG   rH   test_ge  s    z5create_mathtestcase.<locals>.TestMathDuration.test_geN)rk   rl   rm   rn   r   r   r   rG   r\   r]   r~   r   r   rG   rH   TestMathDuration  s   r   )r   rx   ry   rz   r{   )r\   r]   r~   r   r   r   rG   r   rH   create_mathtestcase  s    $r   c                    s(   G  fdddt j}t  |S )z
    Create a TestCase class for a specific test.

    This allows having a separate TestCase for each test tuple from the
    DATE_TEST_CASES list, so that a failed test won't stop other tests.
    c                       s0   e Zd ZdZ fddZ fddZdS )z)create_datetestcase.<locals>.TestDateCalczi
        A test case template test addition, subtraction
        operators for Duration objects.
        c                    s   |      dS z*
            Test operator +.
            Nr}   rP   durationrF   tdeltarG   rH   r     s    z2create_datetestcase.<locals>.TestDateCalc.test_addc                    s   |      dS )z*
            Test operator -.
            Nr}   rP   r   rG   rH   r     s    z2create_datetestcase.<locals>.TestDateCalc.test_subN)rk   rl   rm   rn   r   r   rG   r   rG   rH   TestDateCalc  s   r   rw   )rF   r   r   r   rG   r   rH   create_datetestcase  s    r   c                    s(   G  fdddt j}t  |S )
    Create a TestCase class for a specific test.

    This allows having a separate TestCase for each test tuple from the
    DATE_CALC_TEST_CASES list, so that a failed test won't stop other tests.
    c                       s    e Zd ZdZ fddZdS )z-create_datecalctestcase.<locals>.TestDateCalcT
        A test case template test addition operators for Duration objects.
        c                    s0   dkr|  ttj  n|    dS r   )rJ   
ValueErrorrL   rN   rS   rP   r   rq   rF   rG   rH   	test_calc!  s    z7create_datecalctestcase.<locals>.TestDateCalc.test_calcN)rk   rl   rm   rn   r   rG   r   rG   rH   r     s   r   rw   )rF   r   rq   r   rG   r   rH   create_datecalctestcase  s    r   c                    s(   G  fdddt j}t  |S )r   c                       s    e Zd ZdZ fddZdS )z+create_datemultestcase.<locals>.TestDateMulr   c                    s   |     dS )z*
            Test operator *.
            Nr}   rP   rq   operand1operand2rG   rH   test_mul:  s    z4create_datemultestcase.<locals>.TestDateMul.test_mulN)rk   rl   rm   rn   r   rG   r   rG   rH   TestDateMul5  s   r   rw   )r   r   rq   r   rG   r   rH   create_datemultestcase-  s    r   c                  C   s   t  } t D ]"\}\}}}| t|||| qtD ]}| t|  q8tD ]}| t	|  qPt
D ]}| t|  qhtD ]}| t|  q| t  t | S )z@
    Return a test suite containing all test defined above.
    )rx   Z	TestSuitePARSE_TEST_CASESitemsZaddTestr|   MATH_TEST_CASESr   DATE_TEST_CASESr   DATE_CALC_TEST_CASESr   DATE_MUL_TEST_CASESr   rz   r{   rC   )Zsuiterp   rq   ru   rt   ZtestdatarG   rG   rH   
test_suiteC  s$    
 r   c                 C   s   t  S )N)r   )loadertestspatternrG   rG   rH   
load_testsY  s    r   __main__)ZdefaultTest)rn   rx   rL   r   r   r   Zisodater   r   r   r   r	   r
   r   r   r   r   strptimer   r   ry   rC   r|   r   r   r   r   r   r   rk   mainrG   rG   rG   rH   <module>   s"    
 
   
    0










"





















































c









 &4
