o
    .j                     @   s   d Z ddlmZ ddlZddlmZmZ dd Zdd Zej	d	d
dgdd Z
dd Zdd Zdd Zej	dg ddd Zdd Zdd Zdd ZdS )zBehavioral tests for :class:`~icalendar.cal.lazy.LazyCalendar`.

Tests here cover serialization round-trips, property accessors, timezone
handling, and ``with_uid()`` edge cases not covered by
:mod:`test_issue_1050_lazy_parsing`.

See :issue:`1050`.
    )datetimeN)CalendarEventc                 C   s(   | j }t|jdksJ | rJ dS )z<An empty calendar has no subcomponents after accessing them.r   N)issue_1050_empty_calendarlensubcomponentsis_lazy)lazy_calendarscal r   b/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_issue_1050_lazy_calendar.py(test_empty_calendar_has_no_subcomponents   s   r   c                 C   s<   | j }| s	J |d}t|dksJ | sJ dS )zHA calendar with only ``VTIMEZONE`` stays lazy after accessing timezones.	VTIMEZONE   N)!issue_1050_timezone_only_calendarr   walkr   )r	   r
   	timezonesr   r   r   &test_timezone_only_calendar_stays_lazy   s
   
r   )propsummary)todoszTest Todo 1)journalszTest Journal 1c                 C   s<   | j }t||}t|dksJ t|d d |ksJ dS )zFAccessing ``.todos`` and ``.journals`` returns the correct components.r   r   SUMMARYN))issue_1050_calendar_with_events_and_todosgetattrr   str)	calendarsr   r   r
   
componentsr   r   r   test_component_property#   s   	
r   c                 C   s(   | j }|jd d jddksJ dS )z4Events carry their ``TZID`` parameter after parsing.r   DTSTARTTZIDzAmerica/New_YorkN)r   eventsparamsgetr   r
   r   r   r   test_tzid_accessible_on_events3   s   "r%   c                 C   sh   | j }t|jdksJ t|jdksJ t|ddks J t|jdks)J t|jdks2J dS )zJMixing property access and ``walk()`` in any order returns correct counts.r      VTODON)r   r   r   r!   r   r   r$   r   r   r   test_property_and_walk_access:   s   r(   c                 C   sL   | j }t|jdksJ |jd d j}|jdusJ t|jdks$J dS )zD``VTIMEZONE`` defined after its referencing event is still resolved.r   r   r   NzEurope/Berlin)%issue_1050_forward_timezone_referencer   r!   dttzinfor   )r   r
   dtstartr   r   r   test_forward_timezone_referenceE   s
   r-   access)nonepartialfullc                 C   s   | j }|dkr|j}n|dkr| }| }t|}t|ddks'J t|ddks2J t|ddks=J t|ddksHJ d	S )
z>Serializing at any parse state preserves all component counts.r0   r1   VEVENTr&   r'   r   VJOURNALr   N)r   r!   r   to_icalr   	from_icalr   )r   r.   r
   _outputcal2r   r   r   test_to_ical_roundtripO   s   
r9   c              
   C   sp   | j }t }|dd |dd |dtdddd	d
d
 || tdd |jD }|ddgks6J dS )z5``add_component()`` appends to the parsed event list.UIDznew-event@example.comr   z	New Eventr   i  r&   r   
   r   c                 s   s    | ]	}t |d  V  qdS )r:   N)r   ).0er   r   r   	<genexpr>k   s    z7test_add_component_appears_in_events.<locals>.<genexpr>zsimple-event@example.comN)issue_1050_simple_calendarr   addr   add_componentsortedr!   )r   r
   	new_eventuidsr   r   r   $test_add_component_appears_in_eventsa   s   
rE   c                 C   sH   | j j}t|dksJ t|d jdksJ t|d jdks"J dS )z8``from_ical(..., multiple=True)`` returns all calendars.r&   r   r   N)multipleissue_1050_multiple_calendarsr   r!   )r   calsr   r   r   test_multiple_calendarso   s   rI   c                 C   s8   | j }|d}t|dksJ |d d dksJ dS )u  ``with_uid()`` returns only the component whose ``UID`` matches exactly.

    :class:`~icalendar.parser.ical.lazy.LazySubcomponent` scans raw lines to
    decide whether to parse a component for ``with_uid()``. A ``DESCRIPTION``
    that contains the target UID string causes that component to be parsed as a
    false positive — this is intentional (parse more, never miss) — but the
    returned list must contain only the exact match.
    abcr   r   r   targetN)issue_1050_uid_in_descriptionwith_uidr   )r   r
   resultr   r   r   !test_uid_substring_in_descriptionx   s   	
rO   )__doc__r   pytest	icalendarr   r   r   r   markparametrizer   r%   r(   r-   r9   rE   rI   rO   r   r   r   r   <module>   s*    	

	

	