U
    H4fy                     @   s   d Z ddlZddlZddlmZmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 edd	d
ddddeedfedd	d
ddddeedfeddd	ddddddfeddd	ddddddffZ
dd Zdd Zdd Zedkrejdd  dS )!z$
Test cases for the isodate module.
    N)datetime	timedelta)strftime)LOCAL)DT_EXT_COMPLETE)tzinfoi              z2012-12-25T13:30:00+10:00i  z1999-12-25T13:30:00+11:00
         .   i: z%Y-%m-%dT%H:%M:%S.%fz2012-10-12T08:29:46.069178iD
 z2012-10-12T08:29:46.691780c                    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
    TEST_CASES list, so that a failed test won't stop other tests.
    c                       s8   e Zd ZdZdd Zdd Zdd Z fdd	Zd
S )z!create_testcase.<locals>.TestDatezC
        A test case template to test ISO date formatting.
        c              	   S   sR   | j d |}|jdk rd}nd}|j|j|j|j|j|j|j|j|f	}t	
|S )zp
            mock time.localtime so that it always returns a time_struct with
            tm_idst=1
            	localtimei     r   )ORIGtm_yeartm_montm_mdaytm_hourtm_mintm_sectm_wdaytm_ydaytimestruct_time)selfZsecsttdst r    ;/tmp/pip-unpacked-wheel-giipsm8b/isodate/tests/test_strf.pylocaltime_mockD   s    
    z0create_testcase.<locals>.TestDate.localtime_mockc                 S   sh   i | _ tj| j d< tj| j d< tj| j d< tj| j d< tddt_tddt_tjtj t_| jt_d S )N	STDOFFSET	DSTOFFSETDSTDIFFr   i  )secondsi  )	r   r   r#   r$   r%   r   r   r   r"   r   r    r    r!   setUpT   s    z'create_testcase.<locals>.TestDate.setUpc                 S   s4   | j d t_| j d t_| j d t_| j d t_d S )Nr#   r$   r%   r   )r   r   r#   r$   r%   r   r   r'   r    r    r!   tearDownb   s    z*create_testcase.<locals>.TestDate.tearDownc                    s2   dkr|  tt  n| t  dS )z}
            Take date object and create ISO string from it.
            This is the reverse test to test_parse.
            N)assertRaisesAttributeErrorr   assertEqualr'   dtexpectationformatr    r!   test_formati   s    z-create_testcase.<locals>.TestDate.test_formatN)__name__
__module____qualname____doc__r"   r(   r)   r1   r    r-   r    r!   TestDate>   s
   r6   )unittestZTestCaseZ
TestLoaderZloadTestsFromTestCase)r.   r0   r/   r6   r    r-   r!   create_testcase6   s    7r8   c                  C   s.   t  } tD ]\}}}| t||| q| S )z<
    Construct a TestSuite instance for all test cases.
    )r7   Z	TestSuite
TEST_CASESZaddTestr8   )Zsuiter.   r0   r/   r    r    r!   
test_suitex   s    r:   c                 C   s   t  S )N)r:   )loadertestspatternr    r    r!   
load_tests   s    r>   __main__)ZdefaultTest)r5   r7   r   r   r   Zisodater   r   r   r   r9   r8   r:   r>   r2   mainr    r    r    r!   <module>   s6   B