o
    .jz-                     @   s   d Z ddlmZmZmZ ddlZddlmZmZ ddlm	Z	m
Z
mZmZmZmZmZ ddlmZmZ G dd dZG d	d
 d
ZdS )zDTests for consolidated attribute functions in icalendar.attr module.    )datedatetime	timedeltaN)EventTodo)get_duration_propertyget_end_property&get_start_end_duration_with_validationget_start_propertyset_duration_with_lockingset_end_with_lockingset_start_with_locking)IncompleteComponentInvalidCalendarc                   @   j   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dddZ
dddZdddZdS )TestConsolidatedSettersz7Test consolidated setter functions from icalendar.attr.returnNc              	   C      t  }|dd |dtddddd |dtdddd	d t|tdddd
ddd |jtdddd
dks;J |jtdddd	dksHJ |jtddksRJ dS )z1Test set_start_with_locking for Event components.UID
test-eventDTSTART        r   DTEND   
   end   hoursN)r   addr   r   startr   durationr   selfevent r'   f/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_consolidation_attr_functions.py!test_set_start_with_locking_event      z9TestConsolidatedSetters.test_set_start_with_locking_eventc              	   C   r   )z0Test set_start_with_locking for Todo components.r   	test-todor   r   r   r   r   DUEr   r   r   r   r   N)r   r!   r   r   r"   r   r#   r   r%   todor'   r'   r(    test_set_start_with_locking_todo%   r*   z8TestConsolidatedSetters.test_set_start_with_locking_todoc              	   C      t  }|dd |dtddddd |dtdddd	d t|tdddd
ddd |jtdddddks;J |jtdddd
dksHJ |jtddksRJ dS )z/Test set_end_with_locking for Event components.r   r   r   r   r   r   r   r   r      r"   r   r   N)r   r!   r   r   r"   r   r#   r   r$   r'   r'   r(   test_set_end_with_locking_event3   r*   z7TestConsolidatedSetters.test_set_end_with_locking_eventc              	   C   r0   )z.Test set_end_with_locking for Todo components.r   r+   r   r   r   r   r   r,   r   r1   r"   r   r   N)r   r!   r   r   r"   r   r#   r   r-   r'   r'   r(   test_set_end_with_locking_todoA   r*   z6TestConsolidatedSetters.test_set_end_with_locking_todoc              	   C      t  }|dd |dtddddd |dtdddd	d t|td
ddd |jtdddddks8J |jtdddddksEJ |jtd
dksOJ dS )z4Test set_duration_with_locking for Event components.r   r   r   r   r   r   r   r   r      r   r"      N)r   r!   r   r   r   r"   r   r#   r$   r'   r'   r(   $test_set_duration_with_locking_eventO      z<TestConsolidatedSetters.test_set_duration_with_locking_eventc              	   C   r4   )z3Test set_duration_with_locking for Todo components.r   r+   r   r   r   r   r   r,   r   r5   r   r"   r6   N)r   r!   r   r   r   r"   r   r#   r-   r'   r'   r(   #test_set_duration_with_locking_todo]   r8   z;TestConsolidatedSetters.test_set_duration_with_locking_todoc              	   C   s   t  }|dd |dtddddd |dtd	d
 t|tddddddd |jtdddddks8J |jtd	d
ksBJ |jtdddddksOJ dS )z(Test auto-detection of property locking.r   r   r   r   r   r   r   DURATION   r   r   Nr   )r   r!   r   r   r   r"   r#   r   r$   r'   r'   r(   !test_auto_detect_property_lockingk   s   z9TestConsolidatedSetters.test_auto_detect_property_lockingc              	   C   s   t  }|dd tjtdd t|tdddddd	d
 W d   n1 s(w   Y  tjtdd t|tdddddd	d
 W d   n1 sLw   Y  tjtdd t|t	ddd	d
 W d   dS 1 snw   Y  dS )z.Test error handling in consolidated functions.r   r   zlocked must bematchr   r   r   r   invalidr   Nr   )
r   r!   pytestraises
ValueErrorr   r   r   r   r   r$   r'   r'   r(   *test_error_handling_consolidated_functions~   s4   "zBTestConsolidatedSetters.test_error_handling_consolidated_functionsc              	   C   s   t  }|dd |dtddddd |dtdddd	d t  }|dd
 |dtddddd |dtdddd	d t|tddddddd |jtddddddd |j|jksdJ |j|jkslJ |j|jkstJ dS )z=Test that consolidated functions maintain identical behavior.r   ztest-event-1r   r   r   r   r   r   r   ztest-event-2r   r   )lockedN)r   r!   r   r   	set_startr"   r   r#   )r%   event1event2r'   r'   r(   7test_consolidated_functions_maintain_identical_behavior   s$   zOTestConsolidatedSetters.test_consolidated_functions_maintain_identical_behaviorr   N)__name__
__module____qualname____doc__r)   r/   r2   r3   r7   r9   r<   rC   rH   r'   r'   r'   r(   r      s    







r   c                   @   r   )TestConsolidatedPropertyGettersz,Test consolidated property getter functions.r   Nc              	   C   sZ   t  }|dd |dtddddd |dtdd	 t|}|tdd	ks+J d
S )z;Test get_duration_property when DURATION is explicitly set.r   ztest-durationr   r   r   r   r   r:   r   N)r   r!   r   r   r   r%   r&   r#   r'   r'   r(   ,test_get_duration_property_with_duration_set   s   zLTestConsolidatedPropertyGetters.test_get_duration_property_with_duration_setc              	   C   s`   t  }|dd |dtddddd |dtdddd	d t|}|td
dks.J dS )z:Test get_duration_property when calculated from start/end.r   ztest-calculatedr   r   r   r   r   r   r6   r5   r   N)r   r!   r   r   r   rO   r'   r'   r(   %test_get_duration_property_calculated   s   zETestConsolidatedPropertyGetters.test_get_duration_property_calculatedc              	   C   sN   t  }|dd |dtddddd t|}|tdddddks%J dS )	z%Test get_start_property success case.r   
test-startr   r   r   r   r   N)r   r!   r   r
   )r%   r&   r"   r'   r'   r(   test_get_start_property_success   s
   z?TestConsolidatedPropertyGetters.test_get_start_property_successc                 C   sN   t  }|dd tjtdd t| W d   dS 1 s w   Y  dS )z0Test get_start_property when DTSTART is missing.r   rR   zNo DTSTART givenr=   N)r   r!   r@   rA   r   r
   r$   r'   r'   r(   test_get_start_property_missing   s
   
"z?TestConsolidatedPropertyGetters.test_get_start_property_missingc              	   C   sh   t  }|dd |dtddddd |dtdddd	d t|d}|tdddd	dks2J d
S )z(Test get_end_property when DTEND is set.r   ztest-endr   r   r   r   r   r   r6   N)r   r!   r   r   r%   r&   r   r'   r'   r(    test_get_end_property_with_dtend   s   
z@TestConsolidatedPropertyGetters.test_get_end_property_with_dtendc              	   C   sb   t  }|dd |dtddddd |dtd	d
 t|d}|tdddddks/J dS )z+Test get_end_property when DURATION is set.r   ztest-duration-endr   r   r   r   r   r:   r5   r   r   r6   N)r   r!   r   r   r   rU   r'   r'   r(   #test_get_end_property_with_duration   s   
zCTestConsolidatedPropertyGetters.test_get_end_property_with_durationc              	   C   s   t  }|dd |dtddd t|d}|tdddks"J t  }|dd |dtdddd	d
 t|d}|tdddd	d
ksHJ dS )z'Test get_end_property default behavior.r   ztest-defaultr   r   r   r   r;   ztest-default-2r   r   N)r   r!   r   r   r   )r%   r&   r   rG   end2r'   r'   r(   &test_get_end_property_default_behavior   s   

zFTestConsolidatedPropertyGetters.test_get_end_property_default_behaviorc              	   C   s   t  }|dd |dtddddd |dtdddd	d t|ddd
\}}}|tdddddks7J |tdddd	dksCJ |du sIJ dS )z9Test get_start_end_duration_with_validation success case.r   ztest-validationr   r   r   r   r   r   r6   VEVENTN)r   r!   r   r	   )r%   r&   r"   r   r#   r'   r'   r(   .test_get_start_end_duration_validation_success  s   
zNTestConsolidatedPropertyGetters.test_get_start_end_duration_validation_successc              	   C   s  t  }|dd |dtddddd |dtdddd	d |d
tdd tjtdd t|ddd W d   n1 sCw   Y  t  }|dd |dtddd |d
tdd tjtdd t|ddd W d   n1 s}w   Y  t  }|dd |dtddd |dtdddd	d tjtdd t|ddd W d   dS 1 sw   Y  dS )z8Test get_start_end_duration_with_validation error cases.r   z	test-bothr   r   r   r   r   r   r6   r:   r;   r   zOnly one of DTEND and DURATIONr=   rZ   Nztest-date-durationzDURATION must be of daysztest-type-mismatchzmust be of the same type)	r   r!   r   r   r@   rA   r   r	   r   )r%   r&   rG   event3r'   r'   r(   -test_get_start_end_duration_validation_errors  sJ   		"zMTestConsolidatedPropertyGetters.test_get_start_end_duration_validation_errorsrI   )rJ   rK   rL   rM   rP   rQ   rS   rT   rV   rW   rY   r[   r]   r'   r'   r'   r(   rN      s    





	





rN   )rM   r   r   r   r@   	icalendarr   r   icalendar.attrr   r   r	   r
   r   r   r   icalendar.errorr   r   r   rN   r'   r'   r'   r(   <module>   s    $	 %