o
    .jED                     @   s(  d dl Z d dlZd dlZd dlmZmZ d dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Z d'd( Z!d)d* Z"d+d, Z#d-d. Z$d/d0 Z%d1d2 Z&d3d4 Z'd5d6 Z(d7d8 Z)ej*+d9g d:Z,e,d;d< Z-e,d=d> Z.d?d@ Z/dAdB Z0ej1dCdD Z2dEdF Z3dGdH Z4dIdJ Z5dKdL Z6dMdN Z7dOdP Z8dQdR Z9dSdT Z:dUdV Z;dWdX Z<dYdZ Z=d[d\ Z>ej*+d]e j?g d^d_d`dadb Z@ej*+dcddgdedf ZAdS )g    N)datetime	timedelta)prop)Calendar)	Component)Event)Journal)tzid_from_dtc                 C   s   | sJ |   s
J dS )zCA component is like a dictionary with extra methods and attributes.N)is_emptycalendar_component r   R/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_unit_cal.pytest_cal_Component   s   r   c                 C   sR   d| d< |   r
J | tddiksJ ddg| d< | tddgddks'J dS )	z|Every key defines a property.A property can consist of either a
    single item. This can be set with a single value...
    z-//max m//icalendar.mxm.dk/prodidPRODIDMax M	RasmussenATTENDEE)r   r   N)r
   r   r   r   r   r    test_nonempty_calendar_component   s   r   c                 C   s   |  dddg |  dd |  dd |  dddg | tdtdtdtdtdtdtdgiks>J d	S )
zadd multiple values to a property.

    If you use the add method you don't have to considder if a value is
    a list or not.
    attendeeztest@test.comztest2@test.comzmaxm@mxm.dkztest@example.dkztest3@test.comztest4@test.comr   N)addr   r   vCalAddress)event_componentr   r   r   test_add_multiple_values&   s   r   c                 C   s8   |  dd | d tdksJ | ddksJ dS )z(You can get the values back directly ...r   z-//my product//N)r   r   vTextdecodedcr   r   r   test_get_content_directlyD   s   r   c                 C   s   |  dddks
J dS )z/With default values for non existing propertiesversionz
No VersionN)r   r   r   r   r   test_get_default_valueL   s   r!   c                 C   s:   |  dtdddtdddg t| dtjsJ d S )Nrdatei           )r   r   
isinstancer   r   	vDDDListsr   r   r   r   test_default_list_exampleQ   s    r(   c                 C   s    |  dd |  dksJ dS )z7The component can render itself in the RFC 5545 format.r   r   s0   BEGIN:VCALENDAR
ATTENDEE:Max M
END:VCALENDAR
N)r   to_icalr   r   r   r   test_render_componentV   s   r*   c                 C   s   |   dksJ dS )z-Check the ical string of the event component.sk   BEGIN:VEVENT
DTEND:20000102T000000
DTSTART:20000101T000000
SUMMARY:A brief history of time
END:VEVENT
Nr)   filled_event_componentr   r   r   test_nested_component_event_ics_   s   r.   c                 C   s    | j tddddgksJ dS )zXComponents can be nested, so You can add a subcomponent. Eg a calendar
    holds events.20000102T00000020000101T000000A brief history of time)DTENDDTSTARTSUMMARYN)subcomponentsr   r   r-   r   r   r   test_nested_componentsh   s   r7   c                 C   s"   dd |   D ddgksJ dS )z9We can walk over nested componentes with the walk method.c                 S      g | ]}|j qS r   name.0ir   r   r   
<listcomp>x       z7test_walk_filled_calendar_component.<locals>.<listcomp>	VCALENDARVEVENTNwalkr6   r   r   r   #test_walk_filled_calendar_componentv   s   "rD   c                 C   s@   dd |  dD dgksJ dd |  dD dgksJ dS )zYWe can also just walk over specific component types, by filtering
    them on their name.c                 S   r8   r   r9   r;   r   r   r   r>   ~   r?   z$test_filter_walk.<locals>.<listcomp>rA   c                 S   s   g | ]}|d  qS dtstartr   r;   r   r   r   r>      s    r0   NrB   r6   r   r   r   test_filter_walk{   s   rG   c                  C   s~   t  d } dd|   d|   d }t|}| }t|| d ks%J |d jdks.J td	d
 |dd D s=J dS )z?Deeply nested input should not exceed Python's recursion limit.2   zBEGIN:VCALENDAR
zBEGIN:X-DEEP
zEND:X-DEEP
zEND:VCALENDAR
   r   r@   c                 s   s    | ]}|j d kV  qdS )zX-DEEPNr9   )r<   	componentr   r   r   	<genexpr>       z=test_walk_handles_deeply_nested_components.<locals>.<genexpr>N)sysgetrecursionlimitr   	from_icalrC   lenr:   all)depthicalcalendarwalkedr   r   r   *test_walk_handles_deeply_nested_components   s   
"rV   c              	   C   s:   |  dd |  ddtdfddddd	d
gksJ dS )zOWe can enumerate property items recursively with the property_items
    method.r   r   BEGIN	   VCALENDARr   rX      VEVENTr2   r/   r3   r0   r4   r1   ENDr[   r`   rY   Nr   property_itemsr   r   r6   r   r   r   test_recursive_property_items   s   rd   c                 C   s4   |  dd | jddddtdfdgksJ dS )	z>We can also enumerate property items just under the component.r   r   F	recursiverW   r   ra   Nrb   r6   r   r   r   test_flat_property_items   s   
rg   c                 C   s   | j ddg dksJ dS )zFlat enumeration on the event.Fre   )rZ   r\   r]   r^   r_   N)rc   r,   r   r   r   test_flat_property_items_2   s   rh   c                  C   s"   t  } d| d< |  dksJ dS )zGText fields which span multiple mulitple lines require proper indentingzParagraph one

Paragraph twodescriptionsL   BEGIN:VCALENDAR
DESCRIPTION:Paragraph one\n\nParagraph two
END:VCALENDAR
Nr   r)   r   r   r   r   test_indent   s
   rk   c                 C   s(   | t ddiks
J |  dksJ dS )z{INLINE properties have their values on one property line. Note the
    double quoting of the value with a colon in it.
    	RESOURCESzChair, Table, "Room: 42"sF   BEGIN:VCALENDAR
RESOURCES:Chair\, Table\, "Room: 42"
END:VCALENDAR
Nrj   calendar_with_resourcesr   r   r   test_INLINE_properties   s   
ro   c                 C      | j dddg dksJ dS )zXThe inline values must be handled by the get_inline() and
    set_inline() methods.
    	resourcesr   decode)ChairTablezRoom: 42N
get_inlinerm   r   r   r   test_get_inline   s   rx   c                 C   rp   )zThese can also be decodedrq   rI   rr   )s   Chairs   Tables   Room: 42Nrv   rm   r   r   r   test_get_inline_decoded   s   ry   c                 C   sB   | j dg ddd | d dksJ | jdddg dksJ dS )	zYou can set them directly ...rq   )AListofzsome, recourcesrI   encodezA,List,of,"some, recources"r   rr   N)
set_inlinerw   rm   r   r   r   test_set_inline   s
   
r   c                 C   s`   d| d< | j dddg dksJ | j ddd}t|d d ts#J t|d d ts.J d S )NzM19970308T160000Z/PT3H,19970308T200000Z/PT1H,19970308T230000Z/19970309T000000Zfreebusyr   rr   )z19970308T160000Z/PT3Hz19970308T200000Z/PT1Hz!19970308T230000Z/19970309T000000ZrI   )rw   r&   r   r   )r   r   r   r   r   test_inline_free_busy_inline   s   r   c                 C   s   |  d|tddddddd |  dtdddddd |  d|tdddd	ddd |  d
|tdddddd |   }d|v sKJ d|v sQJ d|v sWJ d|v s]J dS )zTest the for timezone correctness: dtstart should preserve it's
    timezone, created, dtstamp and last-modified must be in UTC.
    rF   i  
   r   zEurope/Viennacreated   dtstamp   zlast-modified   s*   DTSTART;TZID=Europe/Vienna:20101010T100000s   CREATED:20101010T120000Zs   DTSTAMP:20101010T120000Zs   LAST-MODIFIED:20101010T160000ZN)r   localizer   localize_utcr)   
splitlines)comptzplinesr   r   r   test_cal_Component_add  s   "" r   c                 C   sL   |  dd | j dddd td}|  d| | d dd|gks$J dS )z0Already encoded values should not be re-encoded.ATTACHmeyouFr}   usN)r   r   vBinary)r   binaryr   r   r   "test_cal_Component_add_no_reencode  s
   
r   c                 C   s2   | j dddddd |   }d|v sJ dS )	zTest the for timezone correctness: dtstart should preserve it's
    timezone, crated, dtstamp and last-modified must be in UTC.
    zX-TEST-PROPztryout.val1val2)prop1prop2)
parameterss)   X-TEST-PROP;PROP1=val1;PROP2=val2:tryout.N)r   r)   r   )r   r   r   r   r   )test_cal_Component_add_property_parameter  s   r   )component_nameproperty_name))rA   r3   )rA   r2   )rA   zRECURRENCE-ID)VTODODUEc                 C   sH   d|  d }||d 7 }|d|  7 }t |}t|| jdks"J dS )BCheck for proper handling of TZID parameter of datetime propertiesBEGIN:
z;TZID=America/Denver:20120404T073000
END:zAmerica/DenverN)r   rO   r	   dtr   r   r   component_strrJ   r   r   r   test_cal_Component_from_ical1  s
   
r   c                 C   sF   d|  d }||d 7 }|d|  7 }t |}|| jjdu s!J dS )r   r   r   :r   N)r   rO   r   tzinfor   r   r   r   test_cal_Component_from_ical_2;  s
   
r   c                  C   sd   g d} t d| }|  }|| ksJ t|t| ks"J |jdd }|| ks0J d S )N)   BEGIN:VEVENTs   DTSTART:19970714T170000Zs   DTEND:19970715T035959Zs   SUMMARY:Bastille Day Party
   END:VEVENT   
Fsorted)r   rO   joinr)   r   setr   rJ   
sorted_strpreserved_strr   r   r   )test_cal_Component_to_ical_property_orderE  s   r   c                  C   s|   g d} t d| }|  }|d | d ksJ |d dks$J |d | d ks.J |jdd }|| ks<J d S )	N)r   s(   X-FOOBAR;C=one;A=two;B=three:helloworld.r   r   r   rI   s(   X-FOOBAR;A=two;B=three;C=one:helloworld.   Fr   )r   rO   r   r)   r   r   r   r   r   *test_cal_Component_to_ical_parameter_orderW  s   r   c                    s   G  fddd}|S )Nc                       sR   e Zd Z Zded< e Zded< e Zded< eddZ	e	
e e	
e dS )z!repr_example.<locals>.ReprExamplevalue1key1VALUE1)r   N)__name__
__module____qualname__rJ   r   rT   r   eventr   nestedadd_componentr   r   r   r   ReprExamplej  s    

r   r   )r   r   r   r   r   repr_exampleh  s   r   c                 C   s   t dt| jsJ dS )z"Test correct class representation.z#Component\({u?'KEY1': u?'value1'}\)N)rematchstrrJ   r   r   r   r   test_repr_componentx     r   c                 C      t dt| jsJ d S )Nz#VCALENDAR\({u?'KEY1': u?'value1'}\))r   r   r   rT   r   r   r   r   test_repr_calendar}     r   c                 C   r   )Nz VEVENT\({u?'KEY1': u?'value1'}\))r   r   r   r   r   r   r   r   test_repr_event  r   r   c                 C   s2   | j | j t| j tdt| jsJ dS )z#Representation of nested ComponentszComponent\({u?'KEY1': u?'VALUE1'}, Component\({u?'KEY1': u?'value1'}\), VCALENDAR\({u?'KEY1': u?'value1'}, VEVENT\({u?'KEY1': u?'value1'}\)\)\)N)rT   r   r   printr   r   r   r   r   r   r   r   test_nested_components_2  s   
r   c                 C   s&   | d }|dd}|  dksJ dS )z)Check the events in the component factoryrA   19700101rE   s,   BEGIN:VEVENT
DTSTART:19700101
END:VEVENT
Nr+   )factoryrJ   r   r   r   r   test_component_factory_VEVENT  s   
r   c                 C   s   |  dtjjksJ dS )z#Check the VCALENDAR in the factory.r@   N)get	icalendarcalr   )r   r   r   r    test_component_factory_VCALENDAR  r   r   c               
   C   sj   t  } d| d< d| d< t }d|d< d|d< |d	td
ddddd | | | jd  dks3J dS )z7Setting up a minimal calendar component looks like thisz -//My calendar product//mxm.dk//r   z2.0r    z Python meeting about calendaringsummary42uidrF   i        r   se   BEGIN:VEVENT
SUMMARY:Python meeting about calendaring
DTSTART:20050404T080000
UID:42
END:VEVENT
N)r   r   r   r   r   r5   r)   )r   r   r   r   r   .test_minimal_calendar_component_with_one_event  s   
r   c                 C   s2   | j j}t|dksJ tdd |D sJ dS )z2Calendar.journals returns all VJOURNAL components.r   c                 s   s    | ]}t |tV  qd S N)r&   r   )r<   jr   r   r   rK     rL   z2test_calendar_journals_property.<locals>.<genexpr>N)rfc_7986_imagejournalsrP   rQ   )	calendarsr   r   r   r   test_calendar_journals_property  s   r   c                 C   s*   dd | j dD }|ddgksJ dS )Parsing a complete calendar from a string will silently ignore wrong
    events but adding the error information to the component's 'errors'
    attribute. The error in the following is the third EXDATE: it has an
    empty DATE.
    c                 S   s   g | ]}|d    qS )DESCRIPTIONr+   r<   er   r   r   r>     s    zItest_calendar_with_parsing_errors_includes_all_events.<locals>.<listcomp>rA   s   Perfectly OK events   Wrong eventNparsing_errorrC   )r   event_descriptionsr   r   r   5test_calendar_with_parsing_errors_includes_all_events  s   
r   c                 C   s,   dd | j dD }|g dggksJ dS )r   c                 S   r8   r   )errorsr   r   r   r   r>     r?   zOtest_calendar_with_parsing_errors_has_an_error_in_one_event.<locals>.<listcomp>rA   )EXDATEz)Expected datetime, date, or time. Got: ''Nr   )r   r   r   r   r   ;test_calendar_with_parsing_errors_has_an_error_in_one_event  s   r   c                 C   s8   t t | jj W d   dS 1 sw   Y  dS )z1If components are damaged, we raise an exception.N)pytestraises
ValueErrorparsing_error_in_UTC_offsetr5   )r   r   r   r   test_cal_strict_parsing  s   
"r   c                 C   s   | j  | j jksJ dS )zMIf we diable the errors, we should be able to put the calendar back together.N)r   r)   raw_ics)r   vUTCOffset_ignore_exceptionsr   r   r   test_cal_ignore_errors_parsing  s   r   )rT   other_calendar)%issue_156_RDATE_with_PERIOD_TZID_khal'issue_156_RDATE_with_PERIOD_TZID_khal_2)issue_178_custom_component_contains_other'issue_178_custom_component_inside_otherissue_526_calendar_with_events(issue_526_calendar_with_different_events$issue_526_calendar_with_event_subsetr   )repeatc                 C   s(   | | | | k}||k}||ksJ d S r   r   )r   rT   r   r   are_calendars_equalare_calendars_actually_equalr   r   r   test_comparing_calendars  s   r  )rT   shuffeled_calendar)r   (issue_526_calendar_with_shuffeled_eventsc                 C   s0   | | j | | j ksJ | | | | ksJ d S r   )r5   )r   rT   r  r   r   r   Ctest_calendars_with_same_subcomponents_in_different_order_are_equal  s   r  )B	itertoolsr   rM   r   r   r   r   r   icalendar.cal.calendarr   icalendar.cal.componentr   icalendar.cal.eventr   icalendar.cal.journalr   icalendar.timezoner	   r   r   r   r   r!   r(   r*   r.   r7   rD   rG   rV   rd   rg   rh   rk   ro   rx   ry   r   r   r   r   r   markparametrize	comp_propr   r   r   r   fixturer   r   r   r   r   r   r   r   r   r   r   r   r   productr  r  r   r   r   r   <module>   s    			

	
	
	
	

	
	