o
    b                     @   s   d Z ddlmZ zddlmZ W n ey   dZY nw eZddlmZ ddlm	Z
 ddlmZ ddlmZ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)	timedelta)mktime)FixedOffsetTimeZone)SkipTestTestCasec                 C   s(   zt | W S  ty   td| w )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 )mktime_realOverflowErrorr   )t9 r   C/usr/lib/python3/dist-packages/twisted/python/test/test_tzhelper.pyr      s
   
r   c                 C   sD   t du rdS | du rztd= W n ty   Y nw | 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   setTZ.   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   tzInr   r   resetTZK   s   zaddTZCleanup.<locals>.resetTZ)r   get
addCleanup)testCaser   r   r   r   addTZCleanupB   s   r   c                   @   s   e Zd ZdZdd ZdS )FixedOffsetTimeZoneTestsz+
    Tests for L{FixedOffsetTimeZone}.
    c                    sX   t du 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   UTCr   c                 S   sf   t | dksJ | d }t| dd }t| dd }|dkr'| }| }n|dks-J t||dS )N   r   r      -+)hoursminutes)lenintr   )offsetsignr&   r'   r   r   r   timeDeltaFromOffsetl   s   zZFixedOffsetTimeZoneTests.test_tzinfo.<locals>.testForTimeZone.<locals>.timeDeltaFromOffset)	r   r   r   fromLocalTimeStampassertEqualtznamedstr   	utcoffset)r   expectedOffsetDSTexpectedOffsetSTDlocalDSTlocalSTDtzDSTtzSTDr,   selfr   r   testForTimeZone]   s    

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   )r9   r:   r   r8   r   test_tzinfoU   s   %z$FixedOffsetTimeZoneTests.test_tzinfoN)__name__
__module____qualname____doc__r;   r   r   r   r   r   P   s    r   )r?   osr   timer   _tzsetImportErrordatetimer   r   r	   twisted.python._tzhelperr   twisted.trial.unittestr   r   r   r   r   r   r   r   r   <module>   s    