U
    j                     @   sv  d Z zddlZddlmZ W n ek
r4   dZY nX ddlZddlZddlmZ ddlZddl	m
Z
mZ ddlmZ ddlmZmZ erejZe e gZdd	gZng Ze gZd	gZejd
eee  ejdedd Zejdejejejgejdedee
dedddddgdd Zdd Zdd Zdd Zdd  Z ejd!ed"d# Z!d$d% Z"dS )&znThis tests the switch to different timezone implementations.

These are mostly located in icalendar.timezone.
    N)PYTZ)datetime)MONTHLYrrule)
_tzicalvtz)ZONEINFOzoneinfopytzr   tz_nametzp_c                 C   s4   | dkrt   || s0t|jj d|  dS )z,Make sure that all timezones are understood.)ZFactory	localtimez should know N)pytestskipZknows_timezone_idAssertionError	__class____name__)r
   r    r   R/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/tests/test_pytz_zoneinfo_integration.pytest_timezone_names_are_known    s    r   funcobjid     
      TfreqcountZdtstartcachec                 C   s   | | dS )z/Check that we can serialize and copy timezones.Nr   )r   tzpr   r   r   r   test_can_pickle_timezone-   s    
r!   c                  C   s6   t tdtddddd} tt| t| ks2tdS )z<When we copy an rrule, we want it to be the same after this.r   r   r   r   Tr   N)r   r   r   strcopydeepcopyr   )rr   r   r   test_copied_rrule_is_the_same:   s    r&   c                 C   s   |dk|   kstdS z-We want the default implementation to switch.r	   N)	uses_pytzr   )r    tzp_namer   r   r   test_tzp_properly_switches@   s    r*   c                 C   s   |dkst |  st dS r'   )r   r(   )r    r)   Z	pytz_onlyr   r   r   test_tzp_is_pytz_onlyE   s    r+   c                 C   sN   |  |j | d}|| dks(t|  |j || dksJtddS )z>Make sure we do not cache the timezones twice and change them.custom_Pacific/FijizCache is not replaced.N)cache_timezone_componentpacific_fijitimezoner   )r    	timezonesZtzp1r   r   r   test_cache_reuse_timezone_cacheK   s
    
r1   new_tzp_namec                 C   sF   |  |j | d}| | |  |j | d}||k	sBtdS )zLMake sure we do not reuse the timezones created when we switch the provider.r,   N)r-   r.   r/   user   )r    r0   r2   Ztz1Ztz2r   r   r   *test_cache_is_emptied_when_tzp_is_switchedT   s    


r4   c              	   C   s`   d}t t}| | W 5 Q R X |jjd }d| d|ksDtd|ksPtd|ks\tdS )z#Check that the provider name is OK.Zinvalid_providerr   zUnknown provider .r   r	   N)r   Zraises
ValueErrorr3   valueargsr   )r    Zprovideremessager   r   r   test_invalid_name_   s    r;   )#__doc__r	   Zicalendar.timezone.pytzr   ImportErrorr#   pickler   r   Zdateutil.rruler   r   Zdateutil.tz.tzr   Zicalendar.timezone.zoneinfor   r   Zall_timezonesZPYTZ_TIMEZONESZTZP_ZNEW_TZP_NAMEmarkZparametrizelistZavailable_timezonesr   dumpsr$   r!   r&   r*   r+   r1   r4   r;   r   r   r   r   <module>   sP   

 		

