o
    .j!9                     @   s  d Z ddlZddlZddlZddlZddlZddlm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ZddlmZ dd	lmZmZmZmZmZmZmZmZmZmZmZmZ dd
lm Z  ddl!m"Z" ddl!m#Z$ ddl%m&Z& zddl'Z'W n e(y   dZ'Y nw e'duZ)e)re'j*e'	dgZ+dd gZ,dgZ-ng Z+g Z,g Z-G dd dZ.ee/j0Z1e1d Z2e1d Z3e1d Z4e1d Z5e1d Z6e1d Z7ej8deegddd Z9ej8dd Z:ej8dd d!d Z;ej8dd d"d Z<ej8dd d#d Z=ej8dd d$d Z>ej8dd d%d Z?ej8e+edej@eAde	j*g d&d'd( Z*ej8e,d)d d*d g d&d+d, ZBd-ZCd.ZDd/d0 eEe2F e3F e4F D ZGd1d0 eEe2F e3F e4F D ZHd2d0 eEe2F e3F e4F D ZId3efd4d5ZJej8eGd&d3efd6d7ZKej8eHd&d3efd8d9ZLej8eId&d3efd:d;ZMd<d0 e2F D ZNej8eNd&d=d> ZOej8d?d@ ZPej8dAdB ZQej8dCdD ZRej8dEdF ZSej8dGdH ZTej8dIdJ ZUej8dKdL ZVeVZWej8dMdN ZXej8dOdP ZYej8dQdR ZZej8dSdT Z[ej8dd d3ee"ddf fdUdVZ#ej8e-dWg d&dXdY Z\ej8d3e]fdZd[Z^ej8d3e]fd\d]Z_ej8d3e]fd^d_Z`ej8d3e]fd`daZadbdc ZbG ddde deeZcdfdg Zddhdi ZeedjdkdldmdndoZfefjge	j*dpZhdqZidrZjej8d3e]fdsdtZkej8dudvdwdx Zlej8dydz Zmej8e&jnd&d{ejod3e]fd|d}Zpej8e d&d~d Zqej8dd Zrej8d3ejsfddZtej8dd ZudS )zTest configuration    N)	Generator)datetimetimezone)PathMock)ZoneInfo)tz)AlarmAvailabilityCalendar	ComponentComponentFactoryEventLazyCalendarTimezoneTodoTypesFactoryprop
vUTCOffset)PROPERTY_NAMES)TZPtzp   )timezone_idsUTCc                 C   s   t || S N)pytzr   localizedttzname r#   M/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/conftest.py<lambda>1       r%   r   c                   @   s   e Zd ZdZddgZ	ddedee fddZd	d
 Z	dd Z
dd Zdd Zdd Zedd Zeejdedee fddZdS )
DataSourcezFA collection of parsed ICS elements (e.g calendars, timezones, events).ics.jcalFdata_source_folderparserc                 C   s   || _ || _|| _d S r   )_parser_data_source_folder	_multiple)selfr*   r+   multipler#   r#   r$   __init__?   s   
zDataSource.__init__c                    s    fdd j  D S )z(Return all the files that could be used.c                    s"   g | ]}|j   jv r|jqS r#   )suffixlower
extensionsstem).0pr/   r#   r$   
<listcomp>H   s
    z#DataSource.keys.<locals>.<listcomp>)r-   iterdirr8   r#   r8   r$   keysF   s   
zDataSource.keysc                    s   | j }d|v r|dd\}}d| g}|D ]}|| | j }| r' nq| s9t| dd| dd d|dkrF| n|   fdd}t| j	|t
| t| |S )	z;Parse a file and return the result stored in the attribute..r   z' does not exist with these extensions: z, Nr)   c                    sB    r| j j | jdn| j }| jr|S  |_|_|_|S )Nr0   )r,   	from_icalr.   	from_jcalraw_icsraw_jcalsource_file)r/   sourcer@   rA   rB   r#   r$   
get_parsedh   s   
z*DataSource.__getitem__.<locals>.get_parsed)r4   rsplitr-   is_fileAttributeErrorjoin	read_text
read_bytessetattr	__class__propertygetattr)r/   	attributer4   	extensionsource_pathrE   r#   rD   r$   __getitem__N   s,   



zDataSource.__getitem__c                 C   s   | ddd }||  v S )zkey in self.keys()r<   r   r   )rF   r;   r/   keyr#   r#   r$   __contains__x   s   zDataSource.__contains__c                 C   s   | | S r   r#   rT   r#   r#   r$   __getattr__}   s   zDataSource.__getattr__c                 C   
   t | jS r   )repr__dict__r8   r#   r#   r$   __repr__   s   
zDataSource.__repr__c                 C   s   | j | j| jddS )z'Return a list of all components parsed.Tr=   )rM   r-   r,   r8   r#   r#   r$   r0      s   zDataSource.multiplec                 C   s    t d|j | fi }|||S )zEParse all files in a folder and return a DataSource with the results.r'   )typename)clsr*   r+   new_clsr#   r#   r$   from_folder   s   
zDataSource.from_folderN)F)__name__
__module____qualname____doc__r4   r   r\   r   r1   r;   rS   rV   rW   r[   rN   r0   classmethod	functoolscacher`   r#   r#   r#   r$   r'   :   s&    
*
r'   	calendars	timezoneseventsalarmsavailabilitiestodosmodule)scopeparamsc                 C   s   t t|jS )zReturn the data source for calendar files.

    We have two ways of parsing those:
    - Immediately
    - Lazily with LazyCalendar
    )r'   r`   CALENDARS_FOLDERparam)r   requestr#   r#   r$   rh         c                 C      t ttS )z*Return the data source for calendar files.)r'   r`   rq   r   r   r#   r#   r$   lazy_calendars   s   rv   ro   c                 C   ru   r   )r'   r`   TIMEZONES_FOLDERr   r   r#   r#   r$   ri         c                 C   ru   r   )r'   r`   EVENTS_FOLDERr   r   r#   r#   r$   rj      ry   c                 C   ru   r   )r'   r`   ALARMS_FOLDERr
   r   r#   r#   r$   rk      ry   c                 C   ru   r   )r'   r`   AVAILABILITIES_FOLDERr   r   r#   r#   r$   rl      ry   c                 C   ru   r   )r'   r`   TODOS_FOLDERr   r   r#   r#   r$   rm      ry   )rp   c                 C      | j S r   rr   rs   r   r#   r#   r$   utc   s   r   c                 C   s   | j t|dS Ntzinfo)replacer	   gettzr    r#   r#   r$   r%      s    c                 C   s   | j t|dS r   )r   r   r    r#   r#   r$   r%      r&   c                 C   r~   r   r   r   r#   r#   r$   in_timezone   s   r   fuzz_testcase)zbig_bad_calendar.icszissue_104_broken_calendar.icsz!issue_1050_multiple_calendars.icszsmall_bad_calendar.icsz multiple_calendar_components.icszpr_480_summary_with_colon.icszparsing_error_in_UTC_offset.icszparsing_error.icsc                 C   s0   g | ]}|j tvr|jd v rt|j vr|j qS ))r(   r)   r]   BROKEN_SOURCE_FILESr2   FUZZ_TESTCASES_BROKEN_CALENDARSr6   filer#   r#   r$   r9          


r9   c                 C   0   g | ]}|j tvr|jd krt|j vr|j qS )r(   r   r   r#   r#   r$   r9      r   c                 C   r   )r)   r   r   r#   r#   r$   r9      r   returnc                 C   sD   |j }td| | ||fD ]}||v r||   S qtd| d)Nzexample file:zCould not find file r<   )rr   print
ValueError)rh   ri   rj   rs   rB   datar#   r#   r$   get_source_file  s   
r   c                 C      t ||||S )zqAn example file.

    source_file.raw_ics - bytes if .ics file
    source_file.raw_jcal - str if .jcal file

    r   r   rh   ri   rj   rs   r#   r#   r$   rB   
  rt   rB   c                 C   r   )z[An example .ica file.

    source_file.raw_ics - bytes
    source_file.raw_jcal - None
    r   r   r#   r#   r$   ics_file     r   c                 C   r   )zZAn example .jcal file.

    source_file.raw_ics - None
    source_file.raw_jcal - str
    r   r   r#   r#   r$   	jcal_file  r   r   c                 C   s   g | ]
}t t|v r|qS r#   )r   str)r6   rU   r#   r#   r$   r9   )  s
    c                 C   r~   )zClusterfuzz calendars.r   rs   r#   r#   r$   fuzz_v1_calendar_path0     r   c                   C      t  S zReturn a new types factory.)r   r#   r#   r#   r$   types_factory6  r   r   c                   C   r   r   r   r#   r#   r#   r$   component_factory<  r   r   c                 c   s"    d| j d< dV  | j d dS )zMap x_sometime to timetimez
X-SOMETIMEN)	types_mappop)r   r#   r#   r$   
x_sometimeB  s   
r   c                   C   r   )zReturn a new component factory.r   r#   r#   r#   r$   factoryJ  r   r   c                   c   s    dt _d V  dt _d S )NTF)r   ignore_exceptionsr#   r#   r#   r$   vUTCOffset_ignore_exceptionsP  s   
r   c                 C      t  }d|_|S )zReturn an event component.VEVENTr   r]   r   cr#   r#   r$   event_componentW     r   c                 C   r   )Return an empty component.)r   r   r#   r#   r$   r   _  r   r   c                 C   r   )r   	VCALENDARr   r   r#   r#   r$   calendar_componenth  r   r   c                  c   s    t j} dt _dV  | t _dS )z*Remove validation for new() of components.FN)r   _validate_new)valuer#   r#   r$   dont_validate_newp  s
   
r   c                 C   s>   t dd}d|_|jdddd |jdd	dd || |S )
zBReturn an event with some values and add it to calendar_component.zA brief history of time)summaryr   dtend20000102T000000r   )encodedtstart20000101T000000)r   r]   addadd_component)r   r   er#   r#   r$   filled_event_componenty  s   

r   c                 C   s   t  }d|d< |S )NzChair, Table, "Room: 42"	resources)r   r   r#   r#   r$   calendar_with_resources  s   r   c                 c   s    t |  t V  t   dS )zThe timezone provider.N)_tzpuseuse_defaulttzp_namer#   r#   r$   r     s   
r   zoneinfoc                 C   rX   )zThis is annother timezone provider.

    The purpose here is to cross test: pytz <-> zoneinfo.
    tzp as parameter makes sure we test the cross product.
    )r   rr   r   r#   r#   r$   	other_tzp  s   
r   c                 C   s   |   sJ |S )z+Skip tests that are not running under pytz.)	uses_pytz)r   r   r#   r#   r$   	pytz_only     r   c                 C   s   |   sJ |S )z/Skip tests that are not running under zoneinfo.)uses_zoneinfo)r   rs   r   r#   r#   r$   zoneinfo_only  r   r   c                 C      | dksJ | S )zDo not run tests with pytz.r   r#   r   r#   r#   r$   no_pytz  r   r   c                 C   r   )zDo not run tests with zoneinfo.r   r#   r   r#   r#   r$   no_zoneinfo  r   r   c                 C   s   d| j v rGtdg }d| j v rdg}d| j v rt}d| j v r'd| j v r'J ddD ]}d| | j v r<||v r<|| q)| jd|dd	 d
S d
S )a  Parametrize without skipping:

    tzp_name will be parametrized according to the use of
    - pytz_only
    - zoneinfo_only
    - no_pytz
    - no_zoneinfo

    See https://docs.pytest.org/en/6.2.x/example/parametrize.html#deferring-the-setup-of-parametrized-resources
    r   r   r   r   z,Use pytz_only or zoneinfo_only but not both!)r   r   no_rn   rw   N)fixturenamesPYTZ_TZPremoveparametrize)metafunc	tzp_namesr]   r#   r#   r$   pytest_generate_tests  s    





r   c                   @   s   e Zd ZdZdd ZdS )DoctestZoneInfoz+Constent ZoneInfo representation for tests.c                 C   s   d| j dS )NzZoneInfo(key=))rU   r8   r#   r#   r$   r[     s   zDoctestZoneInfo.__repr__N)ra   rb   rc   rd   r[   r#   r#   r#   r$   r     s    r   c                  G   s$   dd | D } t dd | D   dS )zdoctest printc                 S   s$   g | ]}t |tr|d n|qS )zUTF-8)
isinstancebytesdecoder6   argr#   r#   r$   r9     s   $ z!doctest_print.<locals>.<listcomp>c                 s   s,    | ]}t | d dddV  qdS )z

N)r   stripr   r   r#   r#   r$   	<genexpr>  s   * z doctest_print.<locals>.<genexpr>N)r   )argsr#   r#   r$   doctest_print  s   r   c                 O   s"   | dkrt S t| g|R i |S )zIReplace the import mechanism to skip the whole doctest if we import pytz.r   )r   
__import__)r]   r   kwr#   r#   r$   doctest_import  s   r   i                 r   z$d755cef5-2311-46ed-a0e1-6733c9e15c63z#-//collective//icalendar//7.0.0//ENc                   C      t S )z!The UID that tests always create.)UID_DEFAULTr#   r#   r#   r$   test_uid  s   r   T)autousec                    s>   t jtdd | t d fdd | tdtdd  dS )	zYCreate a fixed test environment for the functions that are time and randomness dependent.   )versionuuid4c                      s    S r   r#   r#   uidr#   r$   r%         zfixed_env.<locals>.<lambda>_utc_nowc                   S   r   r   )NOW_UTCr#   r#   r#   r$   r%     r   N)uuidUUIDr   rL   r   staticmethod)monkeypatchr#   r   r$   	fixed_env  s   r   c                 C   s`   |  tjdt | tdt ddlm} | |dtd ddl	m
} | |dt d	tiS )
z,Modify the environment to make doctests run.r   r   r   )ZONEINFOr   r   )calendarDEFAULT_PRODIDr   )setitemsysmodulesr   rL   r   icalendar.timezone.zoneinfor  r   icalendar.calr  r  r   )r   r  r  r#   r#   r$   env_for_doctest  s   r	  rs   c                 C   r~   )zxReturn a timezone id to be used with pytz or zoneinfo.

    This goes through all the different timezones possible.
    r   r   r#   r#   r$   tzid  s   r
  c                 C   r~   )z@Names of property types that occur as a property of a component.r   r   r#   r#   r$   v_prop_name  r   r  c                 C   s
   t t| S )z7Property types that occur as a property of a component.)rO   r   )r  r#   r#   r$   v_prop  s   
r  c                 C   s   |   d S )Nr   )examples)r  r#   r#   r$   v_prop_example"  ry   r  c                   C   r   )zA mock.r   r#   r#   r#   r$   mock'  r   r  )vrd   rf   	itertoolsr  r   r   collections.abcr   r   r   pathlibr   unittest.mockr   r   pytestdateutilr	   	icalendarr
   r   r   r   r   r   r   r   r   r   r   r   icalendar.tests.datar   icalendar.timezoner   r   r    r   r   ImportErrorHAS_PYTZr   PYTZ_UTCPYTZ_IN_TIMEZONEr   r'   __file__parentHERErq   rx   rz   r{   r|   r}   fixturerh   rv   ri   rj   rk   rl   rm   r   r   r   r   r   chainr:   SOURCE_FILES	ICS_FILES
JCAL_FILESr   rB   r   r   FUZZ_V1r   r   r   r   r   r   r   r   compr   r   r   r   r   r   r   r   r   r   r   r   r   r   NOWr   r   r   r  r   r   r	  TZIDSFixtureRequestr
  r  r  	VPROPERTYr  r  r#   r#   r#   r$   <module>   s8   8
V


















	


		















	

	



