o
    .j                     @   s  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 d dlmZ d dl	m
Z
 d dlmZmZ d Zded	efd
dZedZedZedZedZde de de de dd dd dd dd dd dddZG dd dejZedkre  dS dS )    N)datetime)Path)mock)ZoneInfo)Calendarclia  
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Test Summary
ORGANIZER:organizer@test.test
ATTENDEE:attendee1@example.com
ATTENDEE:attendee2@test.test
COMMENT:Comment
DTSTART;TZID=Europe/Warsaw:20220820T103400
DTEND;TZID=Europe/Warsaw:20220820T113400
LOCATION:New Amsterdam, 1000 Sunrise Test Street
DESCRIPTION: Test Description
END:VEVENT
BEGIN:VEVENT
ORGANIZER:organizer@test.test
ATTENDEE:attendee1@example.com
SUMMARY:Test summary
DTSTART;TZID=Europe/Warsaw:20220820T200000
DTEND;TZID=Europe/Warsaw:20220820T203000
LOCATION:New Amsterdam, 1010 Test Street
DESCRIPTION:Test Description\nThis one is multiline
END:VEVENT
BEGIN:VEVENT
UID:1
SUMMARY:TEST
DTSTART:20220511
DURATION:P5D
END:VEVENT
END:VCALENDAR
dtreturnc                 C   s"   t | djtdd dS )z
    Match the CLI's behavior: display datetimes in the *local* timezone.
    The source times are Europe/Warsaw; convert to local tz for comparison.
    z%Y%m%dT%H%M%SzEurope/Warsaw)tzinfoz%c)r   strptimereplacer   
astimezonestrftime)r    r   _/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_issue_821_stdin_parse.py_local_datetime0   s   
r   20220820T10340020220820T11340020220820T20000020220820T203000z    Organizer: organizer <organizer@test.test>
    Attendees:
     attendee1 <attendee1@example.com>
     attendee2 <attendee2@test.test>
    Summary    : Test Summary
    Starts     : z
    End        : a)  
    Duration   : 1:00:00
    Location   : New Amsterdam, 1000 Sunrise Test Street
    Comment    : Comment
    Description:
      Test Description

    Organizer: organizer <organizer@test.test>
    Attendees:
     attendee1 <attendee1@example.com>
    Summary    : Test summary
    Starts     : z[
    Duration   : 0:30:00
    Location   : New Amsterdam, 1010 Test Street
    Comment    : zR
    Description:
     Test Description
     This one is multiline

    Organizer:z
    Attendees:

    Summary    : TEST
    Starts     : Wed May 11 00:00:00 2022
    End        : Mon May 16 00:00:00 2022
    Duration   : 5 days, 0:00:00
    Location   :z
    Comment    :z
    Description:
    z

z

c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestIcalendarCLIArgparseStdinc              
   C   s   t t}t  }tjtd|; tjtdddg! t| t	
  W d   n1 s1w   Y  W d   n1 s@w   Y  W d   n1 sOw   Y  | tks\J dS )z
        Validate that `type=argparse.FileType("r", ...)` maps '-' to sys.stdin
        and the CLI prints the expected, fully formatted output.
        stdinargv	icalendar-N)ioStringIOINPUTr   patchobjectsys
contextlibredirect_stdoutr   maingetvaluePROPER_OUTPUT)self
fake_stdincapturedr   r   r   test_cli_with_stdin_dashm   s   

  z6TestIcalendarCLIArgparseStdin.test_cli_with_stdin_dashc              	   C   s   t jdddd}|t |j}W d   n1 sw   Y  zHt }tj	t
dd|g! t| t  W d   n1 sDw   Y  W d   n1 sSw   Y  | tks`J W t|  dS t|  w )zU
        Validate that passing a real file path also yields the same output.
        wFzutf-8)deleteencodingNr   r   )tempfileNamedTemporaryFilewriter   namer   r   r   r    r!   r"   r#   r$   r   r%   r&   r'   r   unlink)r(   tftmpnamer*   r   r   r   test_cli_with_file_path   s    

 z5TestIcalendarCLIArgparseStdin.test_cli_with_file_pathc                 C   sV   t t}g }|dD ]}|t| |d qd|d }|tks)J dS )z
        Optional: sanity check that the lower-level view(event) path
        still matches what the CLI emits, to guard against formatting drift.
        vevent r   N)	r   	from_icalr   walkappendr   viewjoinr'   )r(   calmanualevtmanual_outputr   r   r   test_view_direct_matches_cli   s   
z:TestIcalendarCLIArgparseStdin.test_view_direct_matches_cliN)__name__
__module____qualname__r+   r6   rB   r   r   r   r   r   l   s    r   __main__)r#   r   r"   r/   unittestr   pathlibr   r   zoneinfor   r   r   r   lstripr   strr   _firststart	_firstend_secondstart
_secondendr   r'   TestCaser   rC   r%   r   r   r   r   <module>   sV   "!"$&)5