o
    .j`                     @  s  d Z ddlmZ ddlZddlmZmZmZ ddlmZ ddl	Z	ddl
mZmZmZmZmZmZmZmZmZ ddd	Ze	jeegddd Ze	jedddddedddedddddeddgddd Zdd Zdd Zdd Zdd  Ze	jeeeegdd!d" Zd#d$ Zd%d& Ze Ze deddddd e deddddd' e!e" Z#e Z$e$ d(ed)d*d*ed)d+d*f eeZ%ee#Z&ee$Z'e	j()d,ee#e$e%e&e'gd-d. Z*d/d0 Z+e	jeddddd'eddd1edddd2deddgdd3d4 Z,d5d6 Z-d7d8 Z.d9d: Z/d;d< Z0e	je-e0e.e/gdd=d> Z1d?d@ Z2dAdB Z3e	j()dCd(dDgdEdF Z4ddKdLZ5ddMdNZ6ddOdPZ7e	je5e6e7gddQdI Z8dRdS Z9e Z:e: d(edTd*d*dUdV e: dDedTd*d* e Z;e; dDedTd*d*dUdV e; d(edTd*d* e Z<e< dDedTd*d*dUdV e< d(edTd*d*dUdV e< dWed*dX e Z=e= d(edTd*d* e= dWed*dY e Z>e> d(edTd*d*dUdV e> dZedTd*d* e Z?e? dZedTd*d*dUdV e? d(edTd*d* e Z@e@ dZedTd*d*dUdV e@ d(edTd*d*dUdV e@ dWed*dX e ZAeA d(edTd*d* eA dWed*dY e	j()d[e:d\fe;d\fe<d]fe=d^fe>d_fe?d_fe@d`feAd^fge	j()dCdadbgdcdd ZBdedf ZCdgdh ZDdidj ZEdkdl ZFdmdn ZGdodp ZHdqdr ZIe ZJe ZKeK dWed*dY e ZLe ZMeM dWed*dY e	j()dseJeLge	j()dCg dtdudv ZNe	j()dweKeMgdxdy ZOe	j()dzeP ed*dXedTdUd{dUdVed*dXfge	j()d|edafedbfed(fedDfedafedbfed(fedafedbfed(fedZfgd}d~ ZQdddZRe	j()dzeP dedTdUd{dUdVed*dXfedd+d+edd+d+gdd ZSdd ZTdd ZUe	j()dd(edTdUd{dUdVfdDedTdUd{dUdVfdWed*dXfgZVeVdd ZWeVdd ZXe	j()dCg ddd ZYdd ZZe	j()dCg de	j()daedTdUd{dUdVedTdUd{edTdUd{dUdVeddgdd Z[e	j()dCdadbgdd Z\dd Z]e	j()dde!ddfdeddXdfdeddXdfgdd Z^dd Z_dd Z`dd Zadd Zbe	j()dddde!de!de!de!de!dfffddeddXfdffdeddXfddffgdd Zcdd Zded*dYZedd Zfdd Zge	j()dddde!dfffddeddXfdffdeddXfddffge	j()dIeddXeege	j()dd*dgdd Zhe	j()dzeP ddedTd*d*ge	j()deegddĄ ZidS )zqThis tests the properties of components and their types.

See https://github.com/collective/icalendar/issues/662
    )annotationsN)datedatetime	timedelta)ZoneInfo)	AlarmEventIncompleteComponentInvalidCalendarJournalTodo	vDatetime	vDDDTypes	vDuration	componentEvent | Todopropstrreturnc                 C  s   t | tr| dkrdS |S )z]Translate the end property.

    This allows us to run the same tests on Event and Todo.
    DTENDDUE)
isinstancer   upper)r   r    r   h/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_issue_662_component_properties.pyr      s   )paramsc                 C  s   |   S )zThe event to test.paramrequestr   r   r   start_end_component%   s   r    i              zEurope/Paris)tzinfoc                 C     ||| j  | j S )zStart of the event.r   )r   set_component_startr    r   r   r   dtstart+      	r(   c                 C  s2   t | }t||d< |   | t| | dS )*Create the event with the __init__ method.r(   N)dictr   clearupdatetype)r   startdr   r   r   _set_component_start_init8   s   r1   c                 C  
   || _ dS z+Create the event with the dtstart property.NDTSTARTr   r/   r   r   r   _set_component_dtstart@      
r7   c                 C  r2   r3   r/   r6   r   r   r   _set_component_start_attrE   r8   r:   c                 C  s@   |  d| |   }t| |   | t| | dS )z)Create the event with the start property.r(   N)addto_icaldecodeprintr,   r-   r.   	from_ical)r   r/   icsr   r   r   _set_component_start_icsJ   s
   rA   c                 C     | j S zCreate a new event.r   r   r   r   r   r'   S      
r'   c                 C  s   | |j ksJ dS zTest the start of events.Nr4   r(   r    r   r   r   test_component_dtstart`      rG   c                 C     |j | ksJ dS rE   r9   rF   r   r   r   test_event_starte   rH   rJ      r5   i        invalid_eventc                 C  sf   t t | j W d   n1 sw   Y  t t | j W d   dS 1 s,w   Y  dS )"Check that we get the right error.N)pytestraisesr
   r/   r5   )rN   r   r   r   test_multiple_dtstartu   s   "rR   c                 C  sD   | j du sJ tt | j W d   dS 1 sw   Y  dS )zDTSTART is optional.

    The following is REQUIRED if the component
    appears in an iCalendar object that doesn't
    specify the "METHOD" property; otherwise, it
    is OPTIONAL; in any case, it MUST NOT occur
    more than once.
    N)r5   rP   rQ   r	   r/   r    r   r   r   test_no_dtstart   s   	"rT         c                 C  r&   )zend of the event.r   )r   set_component_endr    r   r   r   dtend   r)   rX   c                 C  s8   t | }t||t| d< |   | t| | dS )r*   rX   N)r+   r   r   r,   r-   r.   )r   endr0   r   r   r   _set_component_end_init   s   rZ   c                 C  s   t | t| d| dS ))Create the event with the dtend property.r   N)setattrr   r   rY   r   r   r   _set_component_end_property   s   r^   c                 C  r2   )r[   NrY   r]   r   r   r   _set_component_end_attr   r8   r`   c                 C  sF   |  t| d| |   }t| |   | t| | dS )z'Create the event with the end property.r   N)	r;   r   r<   r=   r>   r,   r-   r.   r?   )r   rY   r@   r   r   r   _set_component_end_ics   s
   ra   c                 C  rB   rC   r   r   r   r   r   rW      rD   rW   c                 C  s    t |d}t||| ksJ dS )Test the end of events.r   N)r   getattr)rX   r    attrr   r   r   test_component_end_property   s   
re   c                 C  rI   )rb   Nr_   )rX   r    r   r   r   test_component_end   rH   rf   rd   r   c                 C  s4   t | |}t| | t| |d u sJ t| | d S N)r   delattrrc   )r    r(   rX   rd   r   r   r   test_delete_attr   s   

ri   eventr   durationr   c                 C     t || d< dS zSet the vDDDTypes valueDURATIONN)r   rj   rk   r   r   r   _set_duration_vdddtypes      rp   c                 C  s   |  d| dS rm   )r;   ro   r   r   r   _set_duration_add   rq   rr   c                 C  rl   rm   )r   ro   r   r   r   _set_duration_vduration   rq   rs   c                 C  s.   t |tr
tddntdd}|| | |S )z... events have a DATE value type for the "DTSTART" property ...
    If such a "VEVENT" has a "DURATION"
    property, it MUST be specified as a "dur-day" or "dur-week" value.
    rL   hoursrM   days)r   r   r   r   )r    r(   r   rk   r   r   r   rk      s   	c                 C  s*   | j | j }||ksJ | j|ksJ dS )z'Check calculation of end with duration.N)rY   r/   rk   )r    r(   rk   durr   r   r   test_start_and_duration   s   ry     
      rn   rv   rt   r   )invalid_componentmessagezDDTSTART and DTEND must be of the same type, either date or datetime.z<Only one of DTEND and DURATION may be in a VEVENT, not both.z:When DTSTART is a date, DURATION must be of days or weeks.zBDTSTART and DUE must be of the same type, either date or datetime.z9Only one of DUE and DURATION may be in a VTODO, not both.r/   rY   c                 C  sL   t t}t| | W d   n1 sw   Y  |jjd |ks$J dS )z3Test that the end and start throuw the right error.Nr   )rP   rQ   r
   rc   valueargs)r}   r~   rd   er   r   r   test_invalid_event%  s   (r   c                  C  @   t  } tddddd| _| j| jksJ | jtddksJ dS )z
    For cases where a "VEVENT" calendar component
    specifies a "DTSTART" property with a DATE-TIME value type but no
    "DTEND" property, the event ends on the same calendar date and
    time of day specified by the "DTSTART" property.
    rz   r{      r|   r   rv   N)r   r   r/   rY   rk   r   rj   r   r   r   test_event_duration_zeroR  s   r   c                  C  F   t  } tddd| _| j| jtdd ksJ | jtddks!J dS )z
    For cases where a "VEVENT" calendar component
    specifies a "DTSTART" property with a DATE value type but no
    "DTEND" nor "DURATION" property, the event's duration is taken to
    be one day
    rz   r{   r   rL   rv   Nr   r   r/   rY   r   rk   r   r   r   r   test_event_duration_one_day_  s   r   c                  C  sN   t dddddd} tj| d}|j| ksJ |jtdksJ d|vs%J d	S )
u`  Event.new() with a naive datetime and no end/duration: implicit zero duration.

    See https://github.com/collective/icalendar/issues/1275

    RFC 5545 §3.6.1: "For cases where a VEVENT specifies a DTSTART with a
    DATE-TIME value type but no DTEND property, the event ends on the same
    calendar date and time of day specified by DTSTART."
                  r   r9   r   N)r   r   newrY   rk   r   r/   rj   r   r   r   7test_event_new_datetime_no_dtend_implicit_zero_durationl  s
   	r   c              	   C  sV   |  tddddddd}tj|d}|j|ksJ |jtdks#J d	|vs)J d
S )a7  Event.new() with a timezone-aware datetime and no end/duration: implicit zero duration.

    See https://github.com/collective/icalendar/issues/1275

    This is the exact case reported in the issue: timezone-aware DTSTART with
    neither DTEND nor DURATION should yield zero duration, not raise an error.
    r   r   r   r   r   r   zEurope/Berlinr9   r   N)localizer   r   r   rY   rk   r   )tzpr/   rj   r   r   r   ?test_event_new_datetime_tzaware_no_dtend_implicit_zero_duration|  s
   r   c                  C  sT   t ddd} tj| d}|j| tdd ksJ |jtddks"J d|vs(J dS )	u?  Event.new() with a date and no end/duration: implicit one-day duration.

    See https://github.com/collective/icalendar/issues/1275

    RFC 5545 §3.6.1: "For cases where a VEVENT specifies a DTSTART with a
    DATE value type but no DTEND nor DURATION property, the event's duration
    is taken to be one day."
    r   r   r   r9   rL   rv   r   N)r   r   r   rY   r   rk   r   r   r   r   -test_event_new_date_no_dtend_implicit_one_day  s
   	r   c                  C  r   )z3We do not know about the duration of a todo really.rz   r{   r   r|   r   rv   N)r   r   r/   rY   rk   r   )todor   r   r   test_todo_duration_zero  s   r   c                  C  r   )a  The end is at the end of the day, excluding midnight.

    RFC 5545:
    The following is an example of a "VTODO" calendar
    component that needs to be completed before May 1st, 2007.  On
    midnight May 1st, 2007 this to-do would be considered overdue.
    rz   r{   r   rL   rv   Nr   r   r   r   r   test_todo_duration_one_day  s   r   incomplete_event_end)r/   rY   rk   c                 C  s:   t t t| | W d   dS 1 sw   Y  dS )zGTest that components without required properties throw the right error.N)rP   rQ   r	   rc   )r   rd   r   r   r   test_incomplete_event  s   
"r   component_with_durationc                 C  sz   | j tddks
J tt | j}W d   n1 sw   Y  tt | j}W d   dS 1 s6w   Y  dS )zRTest that DURATION property is accessible even without DTSTART (fixes issue #867).rL   rt   N)rk   r   rP   rQ   r	   r/   rY   )r   _r   r   r   1test_duration_property_accessible_without_dtstart  s   
"r   invalid_valuer   )	Componentrd   c                 C  sb   | }t t}t|||  W d   n1 sw   Y  |jjd dt| j dks/J dS )z^Check that we get the right error.

    - other types that vDDDTypes accepts
    - object
    Nr   zUse datetime or date, not .)rP   rQ   	TypeErrorr\   r   r   r.   __name__)r   rd   r   r   r   r   r   r   test_set_invalid_start  s
   &r   r0   r+   c                 C  s   || |< d S rg   r   )r0   keyr   r   r   r   setitem   s   r   i  c                 C  s^   || d< t t}| j W d   n1 sw   Y  |jjd dt|j dks-J dS )rO   rn   Nr   z"DURATION must be a timedelta, not r   )rP   rQ   r
   rn   r   r   r.   r   )r    r   r   r   r   r   test_check_invalid_duration  s   
r   c              	   C  s   t | d}tddddd| _tdd| _t| |tddddd d	| vs&J | jd
u s-J t| |}|tdddddks>J d
S )z+Setting the end should not break the event.r   rz   r{   r   r|   rL   rv   r   rn   N)r   r   r5   r   rn   r\   rc   )r    r   rY   r   r   r   )test_setting_the_end_deletes_the_duration  s   

r   c              	   C  sv   t | d}tddddd| _t| |tddddd tdd| _|| vs&J t| |d	u s/J tdd| jks9J d	S )
z0Setting the duration should not break the event.r   rz   r{   r   r|   r   rL   rv   N)r   r   r5   r\   r   rn   rc   )r    r   r   r   r   %test_setting_duration_deletes_the_end%  s   
r   )rd   r   c                 C  sP   t | |}t| || || v sJ t| ||ksJ t| |d || vs&J dS )z(Setting attributes to None deletes them.N)r   r\   rc   r    rd   r   r   r   r   "test_setting_to_none_deletes_value:  s   
r   c                 C  sB   t | |}t| ||tdd  t| || t| ||ksJ dS )z'Setting attributes twice replaces them.rL   rv   N)r   r\   r   rc   r   r   r   r   test_setting_a_value_twiceE  s   
r   )r5   r   rn   c                 C  sL   t | |}d| |< tt t| | W d   dS 1 sw   Y  dS )zSpecial case for None.N)r   rP   rQ   r
   rc   )r    rd   r   r   r   test_invalid_noneN  s
   
"r   c                 C  s"   t dd| _| `| jdu sJ dS )zTest the del command.rL   rv   N)r   rn   rS   r   r   r   test_delete_durationW  s   r   )r5   rY   r/   c                 C  sR   t  }t|||  | |jksJ |j| ksJ |j| ksJ |jtdks'J dS )z,Test that we can set the start of a journal.r   N)r   r\   r5   r/   rY   rk   r   )r/   rd   jr   r   r   test_journal_start^  s   r   c                 C  sr   t  }tddddd|_d|_|jdu sJ d|vsJ tt t||  W d   dS 1 s2w   Y  dS )z Delete the start of the journal.i  r   r#   r$   rV   Nr5   )r   r   r/   r5   rP   rQ   r	   rc   )rd   r   r   r   r   test_delete_journal_startq  s   "r   c                  C  sh   t  } tddd| _tddd| _tddd| jksJ | jtdddks'J | jtdddks2J d S )Nrz   rL   r   )r   r   r5   r/   rY   )r   r   r   r   *setting_twice_does_not_duplicate_the_entry}  s   r   )filetriggerrelatedrfc_5545_absolute_alarm_example19970317T133000ZSTARTrfc_5545_endEND
start_datec                 C  s(   | | }||j ksJ ||jksJ dS Get the trigger property.N)TRIGGERTRIGGER_RELATED)alarmsr   r   r   alarmr   r   r   test_get_alarm_trigger_property  s   r   c                  C  s8   t  } tdd| _tdd| jksJ | jdksJ dS )Set the alarm trigger.rL   rt   r   Nr   r   r   r   ar   r   r   test_set_alarm_trigger  s   r   c                  C  s>   t  } tdd| _d| _tdd| jksJ | jdksJ dS )r   rL   rt   r   Nr   r   r   r   r   test_set_alarm_trigger_related  s
   r   c                   C     t  jdksJ dS )zThe default is startr   N)r   r   r   r   r   r    test_get_related_without_trigger     r   c                  C  sN   t t} t }d|_W d   n1 sw   Y  | jjd dks%J dS )z)TRIGGER must be set to set the parameter.r   Nr   z<You must set a TRIGGER before setting the RELATED parameter.)rP   rQ   
ValueErrorr   r   r   r   )r   r   r   r   r   'test_cannot_set_related_without_trigger  s   
r   )r   triggersr   19970317T134500Z19970317T140000Z19970317T141500Z19970317T143000Zc                 C  s0   | | }t t|j t | |j|ksJ dS r   )r>   tupler   )r   r   r   r   r   r   r   test_get_alarm_triggers  s   r   c                   C  r   )z)An alarm with no trigger has no triggers.)r   r   r   N)r   r   r   r   r   r   test_triggers_emtpy_alarm  r   r   c                  C  s,   t  } t| _t| _| jtfddfksJ dS )Check incomplete values.r   N)r   h1r   rn   r   r   r   r   r   "test_triggers_emtpy_with_no_repeat     r   c                  C  s,   t  } t| _d| _| jtfddfksJ dS )r   r{   r   N)r   r   r   REPEATr   r   r   r   r   $test_triggers_emtpy_with_no_duration  r   r   repeatr   c           	      C  s   | |   }||_||_t||jddD ]3\}}|s!|dks J qt|d| ks+J |d |d ks5J t|D ]\}}|| |ksFJ q:qdS )r   F)strictr   rL   r   N)copyr   rn   zipr   len	itertoolspairwise)	r   r   r   rk   r   r   expectedxyr   r   r    test_get_alarm_triggers_repeated  s   r   zinvalid string{   r   c                 C  s\   |  }t t}||_W d   n1 sw   Y  |jjd dt|j dks,J dS )zTest that setting duration with a non-timedelta raises TypeError.

    This ensures that we get the expected error message:
    'Use timedelta, not {type}.'
    Nr   zUse timedelta, not r   )rP   rQ   r   rk   r   r   r.   r   )r   r   r   r   r   r   r   test_set_duration_invalid_type  s
   &r   )r   r   r   r   r   r   )rj   r   rk   r   )r0   r+   )j__doc__
__future__r   r   r   r   r   zoneinfor   rP   	icalendarr   r   r	   r
   r   r   r   r   r   r   fixturer    r(   r1   r7   r:   rA   r'   rG   rJ   invalid_start_event_1r;   r?   r<   invalid_start_event_2invalid_start_event_3invalid_start_todo_1invalid_start_todo_2invalid_start_todo_3markparametrizerR   rT   rX   rZ   r^   r`   ra   rW   re   rf   ri   rp   rr   rs   rk   ry   invalid_event_end_1invalid_event_end_2invalid_event_end_3invalid_event_end_4invalid_todo_end_1invalid_todo_end_2invalid_todo_end_3invalid_todo_end_4r   r   r   r   r   r   r   r   incomplete_event_1incomplete_event_2incomplete_todo_1incomplete_todo_2r   r   objectr   r   r   r   r   valid_valuesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s@   ,




	
 


	





%













	
	


	