U
    
W[                     @   s   d Z ddlmZ zddlmZ W n ek
r8   dZY nX ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ d	d
 Zdd Zdd ZG dd de	ZdS )z(
Tests for L{twisted.python._tzhelper}.
    )environ)tzsetN)FixedOffsetTimeZone)TestCaseSkipTest)	timedelta)mktimec                 C   s2   z
t | W S  tk
r,   td| Y nX dS )z
    Call L{mktime_real}, and if it raises L{OverflowError}, catch it and raise
    SkipTest instead.

    @param t9: A time as a 9-item tuple.
    @type t9: L{tuple}

    @return: A timestamp.
    @rtype: L{float}
    z-Platform cannot construct time zone for {0!r}N)mktime_realOverflowErrorr   format)Zt9 r   C/usr/lib/python3/dist-packages/twisted/python/test/test_tzhelper.pyr      s    
r   c                 C   sH   t dkrdS | dkr6z
td= W q> tk
r2   Y q>X n| td< t   dS )zR
    Set time zone.

    @param name: a time zone name
    @type name: L{str}
    NTZ)r   r   KeyError)namer   r   r   setTZ0   s    
r   c                    s"   t dd | j fdd}dS )z
    Add cleanup hooks to a test case to reset timezone to original value.

    @param testCase: the test case to add the cleanup to.
    @type testCase: L{unittest.TestCase}
    r   Nc                      s   t   d S )N)r   r   ZtzInr   r   resetTZN   s    zaddTZCleanup.<locals>.resetTZ)r   getZ
addCleanup)ZtestCaser   r   r   r   addTZCleanupE   s    r   c                   @   s   e Zd ZdZdd ZdS )FixedOffsetTimeZoneTestsz+
    Tests for L{FixedOffsetTimeZone}.
    c                    sX   t dkrtd fdd}t  |ddd |ddd	 |d
dd |ddd dS )z
        Test that timezone attributes respect the timezone as set by the
        standard C{TZ} environment variable and L{tzset} API.
        Nz:Platform cannot change timezone; unable to verify offsets.c                    s   t |  td}td}t|}t|} ||d|  ||d|  ||td  ||td dd } |	|||  |	||| d S )N)	i        r   r   r            )	i  r      r   r   r      r   r   zUTC{0}r   c                 S   sf   t | dkst| d }t| dd }t| dd }|dkrN| }| }n|dksZtt||dS )N   r   r      -+)hoursminutes)lenAssertionErrorintr   )offsetZsignr"   r#   r   r   r   timeDeltaFromOffsetx   s    zZFixedOffsetTimeZoneTests.test_tzinfo.<locals>.testForTimeZone.<locals>.timeDeltaFromOffset)
r   r   r   ZfromLocalTimeStampZassertEqualtznamer   Zdstr   Z	utcoffset)r   ZexpectedOffsetDSTZexpectedOffsetSTDZlocalDSTZlocalSTDZtzDSTZtzSTDr(   selfr   r   testForTimeZonec   s0    

z=FixedOffsetTimeZoneTests.test_tzinfo.<locals>.testForTimeZonezUTC+00z+0000zEST+05EDT,M4.1.0,M10.5.0z-0400z-0500zCEST-01CEDT,M4.1.0,M10.5.0z+0200z+0100zCST+06z-0600)r   r   r   )r+   r,   r   r*   r   test_tzinfoY   s    -z$FixedOffsetTimeZoneTests.test_tzinfoN)__name__
__module____qualname____doc__r-   r   r   r   r   r   T   s   r   )r1   osr   timer   ImportErrorZtwisted.python._tzhelperr   Ztwisted.trial.unittestr   r   Zdatetimer   r   r	   r   r   r   r   r   r   r   <module>   s   
