
    <e                        d Z ddlZ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Z G d dej                  Z G d d	ej                  Z G d
 dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Zedk    r ej                     dS dS )zPyUnit testing against strptime    N)support)skip_if_buggy_ucrt_strfptime)datec                       e Zd ZdZd ZdS )getlang_TestszTest _getlangc                     |                      t          j                    t          j        t          j                             d S N)assertEqual	_strptime_getlanglocale	getlocaleLC_TIMEselfs    )/usr/lib/python3.11/test/test_strptime.py
test_basiczgetlang_Tests.test_basic   s4    +--v/?/O/OPPPPP    N)__name__
__module____qualname____doc__r    r   r   r   r      s.        Q Q Q Q Qr   r   c                   z    e Zd ZdZd Zd Zd Zd Zd Z e	j
        ej        d          d             Zd	 Zd
 ZdS )LocaleTime_TestszTests for _strptime.LocaleTime.

    All values are lower-cased when stored in LocaleTime, so make sure to
    compare values after running ``lower`` on them.

    c                 f    t          j                    | _        t          j                    | _        dS )z(Create time tuple based on current time.N)time	localtime
time_tupler   
LocaleTimeLT_insr   s    r   setUpzLocaleTime_Tests.setUp   s%    .***,,r   c           	          t          j        || j                                                  }|| j        |                  }|                     ||d|z             |                     |||d|d|           dS )zHelper method that tests testing against directive based on the
        tuple_position of time_tuple.  Uses error_msg as error message.

        z%s: not found in tuplez#: position within tuple incorrect;  != N)r   strftimer   lowerassertInr
   )r   testing	directivetuple_position	error_msgstrftime_output
comparisons          r   compare_against_timez%LocaleTime_Tests.compare_against_time!   s     -	4?CCIIKKT_^<=
ow.:	< 	< 	<_#))ZZZB	C 	C 	C 	C 	Cr   c                     |                      | j        j        ddd           |                      | j        j        ddd           d S )N%A   z#Testing of full weekday name failed%az*Testing of abbreviated weekday name failed)r.   r!   	f_weekday	a_weekdayr   s    r   test_weekdayzLocaleTime_Tests.test_weekday/   sb     	!!$+"7q"G	I 	I 	I!!$+"7q"N	P 	P 	P 	P 	Pr   c                     |                      | j        j        ddd           |                      | j        j        ddd           d S )N%B   z&Testing against full month name failedz%bz-Testing against abbreviated month name failed)r.   r!   f_montha_monthr   s    r   
test_monthzLocaleTime_Tests.test_month7   sb     	!!$+"5tQ"J	L 	L 	L!!$+"5tQ"Q	S 	S 	S 	S 	Sr   c                    t          j        d| j                                                  }|                     || j        j        d           | j        d         dk     rd}nd}|                     | j        j        |         |d           d S )Nz%pz!AM/PM representation not in tuple      r   r8   z;AM/PM representation in the wrong position within the tuple)r   r%   r   r&   r'   r!   am_pmr
   )r   r,   positions      r   
test_am_pmzLocaleTime_Tests.test_am_pm?   s    -do>>DDFFot{'89	; 	; 	;?1""qHHh*84oV	X 	X 	X 	X 	Xr   (musl libc issue on Emscripten, bpo-46390c                     t          j        d| j                                                  }|rN|                     || j        j        d         v p|| j        j        d         v d|d| j        j                   d S d S )N%Zr   r8   z	timezone z not found in )r   r%   r   r&   
assertTruer!   timezone)r   rF   s     r   test_timezonezLocaleTime_Tests.test_timezoneI   s    
 =t77==?? 	>OOH(<Q(?? @$(<Q(??%XXt{';';=> > > > >	> 	>r   c                 *   d}t          j        d|          }|                     t          j        | j        j        |          |d           t          j        d|          }|                     t          j        | j        j        |          |d           t          j        d|          }|                     t          j        | j        j        |          |d           t          j                    }d|_	        | 
                    |j        d	           d S )
N)	i  r=         ,   7      L   r   z%czLC_date_time incorrectz%xzLC_date incorrectz%XzLC_time incorrect) rO   z6LocaleTime's LC directives cannot handle empty strings)r   r%   r
   r!   LC_date_timeLC_dateLC_timer   r    r?   rE   )r   
magic_dater,   LTs       r   test_date_timezLocaleTime_Tests.test_date_timeU   s    9
-j99t{'?LL(*B	D 	D 	D-j99t{':JGG(*=	? 	? 	?-j99t{':JGG(*=	? 	? 	?!##
 %4 	5 	5 	5 	5 	5r   c                 h    |                      | j        j        t          j                               d S r	   )r
   r!   langr   r   r   s    r   	test_langzLocaleTime_Tests.test_langk   s.     	)9+=+?+?@@@@@r   N)r   r   r   r   r"   r.   r5   r;   rA   unittestskipIfr   is_emscriptenrG   rU   rX   r   r   r   r   r      s         - - -
C C CP P PS S SX X X X_I > > >5 5 5,A A A A Ar   r   c                   R    e Zd ZdZd Zd Zd Zed             Zd Z	d Z
d Zd	 Zd
S )TimeRETestszTests for TimeRE.c                 f    t          j                    | _        t          j                    | _        dS )z Construct generic TimeRE object.N)r   TimeREtime_rer    locale_timer   s    r   r"   zTimeRETests.setUpt   s)     '))$/11r   c                    | j                             d          }|                     |                    | j        j        d                   dk    d|z             |                     |                    | j        j        d                   dk    d|z             |                     |                    | j         d                   dk    d|z             d S )	Nz%a %A %drM   z7did not find abbreviated weekday in pattern string '%s'   z0did not find full weekday in pattern string '%s'dz.did not find 'd' directive pattern string '%s')r`   patternrE   findra   r4   r3   r   pattern_strings     r   test_patternzTimeRETests.test_patterny   s    --k::++D,<,Fq,IJJbPQ'(	) 	) 	) 	++D,<,Fq,IJJbPJ'(	) 	) 	) 	++DL,=>>"DH'(	) 	) 	) 	) 	)r   c                 n    | j                             d          }|                     d|d|z             d S )Nz\d+z\\d\+z/%s does not have re characters escaped properly)r`   rf   r'   rh   s     r   test_pattern_escapingz!TimeRETests.test_pattern_escaping   sH     --f55hG$%	& 	& 	& 	& 	&r   c                    | j                             d                              | j        j        d                   }|                     |o(|                    d          | j        j        d         k    d           | j                             d          }|                    | j        j        d         d| j        j        d                   }|                     |d|j	        d	| j        j        d         d| j        j        d         d
           |                     |                    d          | j        j        d         k    o(|                    d          | j        j        d         k    d|j
        d|j        j	        d|                    d          d|                    d          d	           dD ]}| j                             d|z             }|                    t          j        d|z                       }|                     |dt          j        d|z             d|j	        d           d S )Nr0   r1   Azre object for '%A' failedz%a %brd    zMatch failed with 'z' regex and 'z' stringabz:re object couldn't find the abbreviated weekday month in 'z	' using 'z'; group 'a' = 'z', group 'b' = ')rp   rn   rq   Bcre   GHIjmMpSuUVwWxXyYZ%r   zMatching failed on 'z' regex)r`   compilematchra   r3   rE   groupr4   r:   rf   stringrer   r%   )r   foundcompiledr)   s       r   test_compilezTimeRETests.test_compile   sb    $$U++11$2B2LQ2OPPS%++c"2"2d6F6PQR6S"S3	5 	5 	5<''11$*:*DQ*G*G*G#/7:: < = =4+;+Ea+H+H+H+/+;+CA+F+F!H !H !HI	J 	J 	J 	C((D,<,Fq,II IS))T-=-Ea-HH  ,,,(8(8(8%++c:J:J:J:J++c****,	- 	- 	-K 	8 	8I|++C)O<<HNN4=y#A#ABBEOOEE%)]3?%C%C%C%C%-%5%5%5$7 8 8 8 8		8 	8r   c                     t          j                    }t                      t                      f|_        |                     t          j        |                              d          dd           d S )NrD   rO   z6with timezone == ('',''), TimeRE().pattern('%Z') != '')r   r    	frozensetrF   r
   r_   rf   )r   test_locales     r   test_blankpatternzTimeRETests.test_blankpattern   sn      *,, )Y[[9)+66>>tDDbQ	S 	S 	S 	S 	Sr   c                     | j                             d          }|                    d          }|                     |d           d S )Nz\w+ %mz\w+ 10z"Escaping failed of format '\w+ 10')r`   r   r   rE   )r   compiled_rer   s      r   test_matching_with_escapesz&TimeRETests.test_matching_with_escapes   sE    l**955!!),,DEEEEEr   c                    t          j                    }t          d          t          d          f|_        t          j        |          }|                     |                    d                              d          d           d S )N)utcgmtTokyo (standard time)zTokyo (daylight time)rD   r   zFlocale data that contains regex metacharacters is not properly escaped)r   r    r   rF   r_   rE   r   r   )r   ra   r`   s      r   'test_locale_data_w_regex_metacharactersz3TimeRETests.test_locale_data_w_regex_metacharacters   s      *,, ) +E !F !F )*A B B D ";//--334KLL,	- 	- 	- 	- 	-r   c                     | j                             d          }|                     t          j        |d                     |                     t          j        |d                     d S )Nz%j %H180z18 0)r`   rf   assertFalser   r   rE   )r   rf   s     r   test_whitespace_substitutionz(TimeRETests.test_whitespace_substitution   s]     ,&&w//'511222&1122222r   N)r   r   r   r   r"   rj   rl   r   r   r   r   r   r   r   r   r   r]   r]   q   s        2 2 2
) ) )& & & "8 8 "!84S S SF F F- - -3 3 3 3 3r   r]   c                   >   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Ze ej        ej        d          d                         Z ej         eed          d          d             Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d S )!StrptimeTestszTests for _strptime.strptime.c                 6    t          j                    | _        dS )zCreate testing time tuple.Nr   gmtimer   r   s    r   r"   zStrptimeTests.setUp   s    +--r   c           	      D   |                      t          t          j        dd           dD ]x}	 t          j        d|           |                     d|z             1# t          $ r Y =t
          $ r0}|                     d|d|j        j        d	           Y d }~qd }~ww xY w|                      t                    5  t          j        d
d           d d d            n# 1 swxY w Y   |                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   dD ]\}|                      t                    5  t          j        dd                    |                     d d d            n# 1 swxY w Y   ]|                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t          j        dd           d d d            d S # 1 swxY w Y   d S )N%dr0   )data_stringformat)r   z% z%e2005z'%s' did not raise ValueErrorrr   z	' raised z, not ValueErrorz1999 50z%Y %Vz1999 51%G %Vrn   rp   r   r}   z%G %{}2015z%Gz1999 256z%G %j)	assertRaises
ValueErrorr   _strptime_timefail	Exception	__class__r   r   )r   
bad_formaterrr   s       r   test_ValueErrorzStrptimeTests.test_ValueError   s   *i&>D!% 	 	' 	' 	'+ 		H 		HJH(<<< 		9JFGGGG     B B B			'ZZ)?)?)?A B B B B B B B BB z** 	4 	4	7333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 z** 	4 	4	7333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 & 	B 	BA"":.. B B#Ihooa.@.@AAAB B B B B B B B B B B B B B B z** 	. 	.---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. z** 	5 	5
G444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5sw   A
B!(	B!1&BB!>C  C$'C$D''D+.D+)FF		F		+GGG2HHHc                    |                      t                    5 }t          j        dd           d d d            n# 1 swxY w Y   |                     |j        j        d           |                      t                    5 }t          j        dd           d d d            n# 1 swxY w Y   |                     |j        j        d           d S )NrO   z%DT19z%Y %)r   r   r   r   assertIs	exception__suppress_context__)r   es     r   test_strptime_exception_contextz-StrptimeTests.test_strptime_exception_context   s,   z** 	/a$R...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ak6===z** 	3a$T6222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3ak6=====s!   =AAB$$B(+B(c                 T    |                      t          t          j        dd           d S )Nz10 12%m)r   r   r   r   r   s    r   test_unconverteddataz"StrptimeTests.test_unconverteddata  s%    *i&>NNNNNr   c                     t          j        d|z   | j                  }t          j        |d|z             }|                     ||         | j        |         k    d|d|d||         d| j        |                    dS )zHelper fxn in testing.r   ztesting of 'z' directive failed; '' -> r$   Nr   r%   r   r   r   rE   )r   r)   r@   strf_outputstrp_outputs        r   helperzStrptimeTests.helper  s    mC)OT_EE.{C)OLLH-1JJJ#))[[[+h2G2G2G/(335	6 	6 	6 	6 	6r   c           
          dD ]}|                      |d           dD ]^\  }}|D ]V}t          j        |d          }|t          |          z   }|                     |d         |k    d|d|d         d           W_d S )N)r   r   r   ))l  )6999)i  )0068z%yz'y' test failed; passed in 'z' and returned 'rr   )r   r   r   intrE   )r   r)   centuryboundsboundr   expected_results          r   	test_yearzStrptimeTests.test_year  s    # 	& 	&IKK	1%%%%K 	O 	OOGV O O'6udCC")CJJ"6A/ A A7<uuk!nnn!NO O O OO	O 	Or   c                 <    dD ]}|                      |d           d S )N)rs   rq   ry   r8   r   r   r)   s     r   r;   zStrptimeTests.test_month  s2    ( 	& 	&IKK	1%%%%	& 	&r   c                 2    |                      dd           d S )Nre   rM   r   r   s    r   test_dayzStrptimeTests.test_day       Cr   c           
         |                      dd           t          j        d| j                  }t	          j        |d          }|                     |d         | j        d         k    d|d|d         d| j        d                    d S )Nrv   r=   %I %pz&testing of '%I %p' directive failed; 'r   r$   )r   r   r%   r   r   r   rE   r   r   r   s      r   	test_hourzStrptimeTests.test_hour$  s    CmGT_==.{GDDA$/!*<<<%++{1~~~tq7I7IK	L 	L 	L 	L 	Lr   c                 2    |                      dd           d S )Nrz   rd   r   r   s    r   test_minutezStrptimeTests.test_minute-  r   r   c                 2    |                      dd           d S )Nr|      r   r   s    r   test_secondzStrptimeTests.test_second1  r   r   c           	          dd l }|                     ddddddd          }t          j        t          |          d	          \  }}}|                     ||j                   d S )
Nr   i  r>      "   8   i4 z%Y-%m-%d %H:%M:%S.%f)r   )datetimer   strr
   microsecond)r   r   re   tupfrac_s         r   test_fractionzStrptimeTests.test_fraction5  sj    dBBB>> *3q66:PQQQT1q}-----r   c                 <    dD ]}|                      |d           d S )Nr   r1   r   r   s     r   r5   zStrptimeTests.test_weekday<  s2    - 	% 	%IKK	!$$$$	% 	%r   c                 2    |                      dd           d S )Nrx      r   r   s    r   test_julianzStrptimeTests.test_julianA  r   r   c                    d}d}d}t          j         dd          \  ^ }}}}|                     |||z              |                     |d           t          j         dd          \  ^ }}}}|                     ||            |                     |d           t          j         dd          \  ^ }}}}|                     |||z   |z               |                     |d           t          j         d	d          \  ^ }}}}|                     |||z   |z               |                     |d
           t          j         dd          \  ^ }}}}|                     ||           |                     |d           t          j         dd          \  ^ }}}}|                     |||z               |                     |d           t          j         dd          \  ^ }}}}|                     |||z   |z               |                     |d           t          j         dd          \  ^ }}}}|                     |||z   |z               |                     |d
           t          j         dd          \  ^ }}}}|                     |||z   |z              |                     |d           t          j         dd          \  ^ }}}}|                     |d           |                     |d           d S )Ni  i     z+0130%zr   z-0100z-013030z-013030.000001rc   z+01:00z-01:30z	-01:30:30z-01:30:30.000001z+01:30:30.001i  r   )r   r
   )r   one_hour	half_hourhalf_minuter   offsetoffset_fractions          r   test_offsetzStrptimeTests.test_offsetE  sC   	+4+>w+M+M(!VaI!5666!,,,+4+>w+M+M(!Va(+++!,,,+4+>y$+O+O(!Va8i#7+#E!FGGG!,,,+4+>?OQU+V+V(!Va8i#7+#E!FGGG"---+4+>x+N+N(!Va***!,,,+4+>x+N+N(!Va8i#7!8999!,,,+4+>{D+Q+Q(!Va8i#7+#E!FGGG!,,,+4+>?QSW+X+X(!Va8i#7+#E!FGGG"---+4+>PT+U+U(!VaI!5!CDDD$///+4+>sD+I+I(!Va###!,,,,,r   c                    |                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t          j        dd           d d d            n# 1 swxY w Y   |                      t                    5 }t          j        dd           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nz
-01:30:30.r   z-0130:30z-01:30:30.1234567z-01:30:30:123456z-01:3030z!Inconsistent use of : in -01:3030)r   r   r   r
   r   r   )r   r   s     r   test_bad_offsetzStrptimeTests.test_bad_offseth  s   z** 	4 	4d333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4z** 	2 	2
D111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2z** 	; 	; 3T:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;z** 	: 	: 2D999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:z** 	2c
D111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2<c#->P>PQQQQQsW   =AA"BBB)CCC0DDD7EE ErB   c           
         t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t	          j                    }t	          j        d          }t          j        |d          }t          j                    }t          j        d         t          j        d         k    st          j	        s=| 
                    |d         |d         k    d|d|d         d	|d                    d S | 
                    |d         d
k    d           d S )NUTCrD   r   GMTr8      ztimezone check failed; 'r   r$   rc   z]LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1)r   r   r
   tm_isdstr   r   r%   r    tznamedaylightrE   )r   r   r   r   ra   s        r   rG   zStrptimeTests.test_timezoneu  sB     .ud;;-q111.ud;;-q111^%%
mD)).{DAA*,,;q>T[^++4=+OOKNjm;;)kk;q>>>:a==JK K K K K OOKNb0NO O O O Or   tzsetz"time module has no attribute tzsetc                    t           j        d         }|                                dv r|                     d           t	          j        t           d||f          5  t	          j        t           dd          5  t	          j        t           dd           5  ||ft           _        dt           _        t          j        |d	          d
         }| 	                    |dt           j        d|dt           j        d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   )r   r   zneed non-UTC/GMT timezoner   r  r8   r  c                      d S r	   r   r   r   r   <lambda>z1StrptimeTests.test_bad_timezone.<locals>.<lambda>  s    d r   rD   r   rc   z lead to a timezone value of z) instead of -1 when time.daylight set to z and passing in )
r   r   upperskipTestr   	swap_attrr  r   r   r
   )r   tz_nametz_values      r   test_bad_timezonezStrptimeTests.test_bad_timezone  s-    +a.==??n,,MM5666tX/ABB 		E 		EtZ33		E 		EtWll;;		E 		E #G,DKDM />>qAHXr [[[(((DMMM77DE E E		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		Es[   D;7D#A,D D#DD#DD#D;#D'	'D;*D'	+D;;D?D?c                 V    t          d          D ]}|                     d|           d S )Nr1   rt   ranger   r   r@   s     r   rU   zStrptimeTests.test_date_time  s8    a 	' 	'HKKX&&&&	' 	'r   c                 X    t          dd          D ]}|                     d|           d S )Nr   r=   r   r  r  s     r   	test_datezStrptimeTests.test_date  :    a

 	' 	'HKKX&&&&	' 	'r   c                 X    t          dd          D ]}|                     d|           d S )Nr=   r1   r   r  r  s     r   	test_timezStrptimeTests.test_time  r  r   c                     t          j        d| j                  }t          j        |d          }|                     |d         | j        d         k    o|d         | j        d         k    d           d S )Nz%m %% %Yr   r8   zhandling of percent sign failedr   r   s      r   test_percentzStrptimeTests.test_percent  st    mJ@@.{JGGA$/!*<< >$Q4?1+==9	; 	; 	; 	; 	;r   c                    t          j        d| j                  }|                     t	          j        |                                d          d           |                     t	          j        |                                d          d           |                     t	          j        |                                d          d           d S )Nr7   z0strptime does not handle ALL-CAPS names properlyz1strptime does not handle lowercase names properlyz/strptime does not handle capword names properly)	r   r%   r   rE   r   r   r  r&   
capitalize)r   r   s     r   test_caseinsensitivez"StrptimeTests.test_caseinsensitive  s    mD$/::	01B1B1D1DdKKJ	L 	L 	L	01B1B1D1DdKKK	M 	M 	M	01G1G1I1I4PPI	K 	K 	K 	K 	Kr   c                 t    d}t          j        dd          }|                     ||k    d|d|           d S )N)	r   r8   r8   r   r   r   r   r8   rc   1r   z-Default values for strptime() are incorrect; r$   )r   r   rE   )r   defaultsr   s      r   test_defaultszStrptimeTests.test_defaults  sS    2.sD99x//'2{{HH>	? 	? 	? 	? 	?r   c                 Z    d}|                      t          j        ||                     d S )Nz.^$*+?{}\[]|)()rE   r   r   )r   need_escapings     r   test_escapingzStrptimeTests.test_escaping  s.     *	0NNOOOOOr   c                 0    t          j        dd           d S )NFeb 29%b %d)r   strptimer   s    r   $test_feb29_on_leap_year_without_yearz2StrptimeTests.test_feb29_on_leap_year_without_year  s    h(((((r   c                 ~    |                      t          j        dd          t          j        dd                     d S )Nr"  r#  zMar 1)
assertLessr   r$  r   s    r   7test_mar1_comes_after_feb29_even_when_omitting_the_yearzEStrptimeTests.test_mar1_comes_after_feb29_even_when_omitting_the_year  s@    h00gw//	1 	1 	1 	1 	1r   N)'r   r   r   r   r"   r   r   r   r   r   r;   r   r   r   r   r   r5   r   r   r   r   rY   rZ   r   r[   rG   
skipUnlesshasattrr   r  rU   r  r  r  r  r  r   r%  r(  r   r   r   r   r      s*       ''( ( ( 5  5  5F> > >O O O6 6 6O O O& & &
  L L L    . . .% % %
  !- !- !-FR R R "X_I O O  "!O, Xg D
 
E E
 
E$' ' '
' ' '
' ' '
; ; ;K K K? ? ?P P P) ) )1 1 1 1 1r   r   c                       e Zd ZdZd ZdS )Strptime12AMPMTestsz9Test a _strptime regression in '%I %p' at 12 noon (12 PM)c                 <   | j         } |t          j        dd          d         d            |t          j        dd          d         d            |t          j        dd          d         d            |t          j        dd          d         d           d S )Nz12 PMr   r=   r>   z12 AMr   )r
   r   r$  r   r   )r   eqs     r   test_twelve_noon_midnightz-Strptime12AMPMTests.test_twelve_noon_midnight  s    
4='**1-r222
4='**1-q111
9#GW55a8"===
9#GW55a8!<<<<<r   N)r   r   r   r   r/  r   r   r   r,  r,    s)        CC= = = = =r   r,  c                       e Zd ZdZd ZdS )JulianTestsz@Test a _strptime regression that all julian (1-366) are acceptedc                     | j         }t          dd          D ]*} |t          j        d|z  d          d         |           +d S )Nr8   io  z%d 2004z%j %Yr   )r
   r  r   r   )r   r.  is      r   test_all_julian_daysz JulianTests.test_all_julian_days  sZ    q# 	G 	GABy'	Aw??BAFFFF	G 	Gr   N)r   r   r   r   r4  r   r   r   r1  r1    s.        JJG G G G Gr   r1  c                       e Zd ZdZd Zed             Zed             Zed             Ze	j
        rdZdZndZdZ ej        ej                            d	          d
          d             Zd ZdS )CalculationTestsz4Test that strptime() fills in missing info correctlyc                 6    t          j                    | _        d S r	   r   r   s    r   r"   zCalculationTests.setUp  s    +--r   c                     d}t          j        t          j        || j                  |          }|                     |j        | j        j        k    d|j        d| j        j                   d S )Nz%Y %m %d %H %M %S %w %ZzCalculation of tm_yday failed; r$   )r   r   r   r%   r   rE   tm_ydayr   format_stringresults      r   test_julian_calculationz(CalculationTests.test_julian_calculation  s}     2)$-t*W*W$13 3$/*AAA ...$/*A*AC	D 	D 	D 	D 	Dr   c                    d}t          j        t          j        || j                  |          }|                     |j        | j        j        k    o)|j        | j        j        k    o|j        | j        j        k    d|j        d|j        d|j        d| j        j        d| j        j        d| j        j                   d S )Nz%Y %H %M %S %w %j %Zz&Calculation of Gregorian date failed; -r$   )	r   r   r   r%   r   rE   tm_yeartm_montm_mdayr:  s      r   test_gregorian_calculationz+CalculationTests.test_gregorian_calculation  s     /)$-t*W*W$13 3$/*AA C$/*@@C4?+BB !...&---/1114?3I3I3I/11	3	4 	4 	4 	4 	4r   c                     d}t          j        t          j        || j                  |          }|                     |j        | j        j        k    d|j        d| j        j                   d S )Nz%Y %m %d %H %S %j %Zz'Calculation of day of the week failed; r$   )r   r   r   r%   r   rE   tm_wdayr:  s      r   test_day_of_week_calculationz-CalculationTests.test_day_of_week_calculation  s}     /)$-t*W*W$13 3$/*AAA'-~~~t7N7NP	Q 	Q 	Q 	Q 	Qr   )q  r8   r8   r  r>        r>      }  r>   rK  )r   r   aixzbpo-29972: broken test on AIXc                      fd} |dd            |dd            |dd            |dd	            |d
d            |dd            |dd            |dd            |dd            |dd            |dd            |dd            |dd            |dd            |dd            |dd            |d d!            |d"d#            |d$d%            |d&d'           d S )(Nc           	         dD ]}|	j         v r| 	j        v r d S dD ]}|dz   |z   }	                    || |          5  t          |  }|                    |          }t          j        ||          }|d|d         d|                                d         }	                    |d d         | |           d d d            n# 1 swxY w Y   d S )	N)z%Y %Wz%Y %Ur   )z%wz%ur2   r0   ro   )r   r   z: r   r$   r=   )	_formats_excluded_ymd_excludedsubTestdatetime_dater%   r   r   	timetupler
   )
	ymd_tupletest_reasonyear_week_formatweekday_formatr;  dt_date
strp_inputr   msgr   s
            r   test_helperzSCalculationTests.test_week_of_year_and_day_of_week_calculation.<locals>.test_helper*  s}   $? J J $(>>>!T%777FF&> J JN$4s$:^$KMk+4-: & < < 
J 
J #0";%,%5%5m%D%D
&/&>z?L'N 'N0:

0;A070A0A0C0CA0F0FH ((RaR)SIII
J 
J 
J 
J 
J 
J 
J 
J 
J 
J 
J 
J 
J 
J 
JJ	J Js   A;CC
C
)m  r8   r=   zweek 0)ra  r8   r   zcommon case)ra  r8      zday on Sunday)ra  r8      zday on MondayrG  zJan 1 on Sunday)rJ  r8   r8   zJan 1 on Monday)rJ  r8   r   z)first Sunday in a year starting on Monday)rH  r>   rK  zDec 31 on SundayrI  zDec 31 on MondayrL  z#Monday in the last week of the year)rM  r>   rJ   z-Monday in the second-to-last week of the year)i  
      zrandomly chosen date)i  r>      zEyear starting and ending on Monday while date not on Sunday or Monday)rP  r>   rI   zXyear starting and ending on Monday with a Monday not at the beginning or end of the yearrO  z8Dec 31 on Monday with year starting and ending on Monday)  r8   r   zFirst Sunday of 2007)rg  r8   rc  zSecond Sunday of 2007)  r>   rK  zLast Sunday of 2006)rh  r>      zSecond to last Sunday of 2006r   )r   r`  s   ` r   -test_week_of_year_and_day_of_week_calculationz>CalculationTests.test_week_of_year_and_day_of_week_calculation%  s   
	J 	J 	J 	J 	J$ 	L(+++L-000M?333M?333L"3444L"3444L"MNNNN$6777N$6777N$IJJJN %+ 	, 	, 	,N$:;;;N$:;;;N %G 	H 	H 	HN %6 	7 	7 	7 	N %; 	< 	< 	<L"8999M#:;;;N$9:::N$CDDDDDr   c                      fd} |dddddddddd	
  
          |dd
dddddddd
  
          |dddddddddd
  
          |dddddddddd
  
          |dd
dddddddd
  
          |dddddddddd
  
          |dddddddddd
  
          |dd
dddddddd
  
          |dddddddddd
  
          |dddddddddd
  
          |dd
dddddddd
  
          |dddddddddd
  
          |dddddddddd
  
          |dd
dddddddd
  
          |dddddddddd
  
          |d ddddddddd
  
          |d d
dddddddd
  
          |d!dddddddd"d
  
          |d#dddddddd"d
  
          |d#d
ddddddd"d
  
          |d$ddddddddd
  
          |d%dd&ddddddd
  
          |d%d
d'ddddddd
  
          |d(dd&ddddddd
  
          |d)dd&ddddddd
  
          |d)d
d&ddddddd
  
          |d*dd&ddddddd
  
          |d+dd&ddddddd
  
          |d+d
d&ddddddd
  
          |d,dd&ddddddd-
  
          |d.dd&ddddddd-
  
          |d.d
d&ddddddd-
  
          |d/dd'ddddddd
  
          |d0dd'ddddddd
  
          |d0d
d'ddddddd
  
          |d1dd'ddddddd
  
          |d2dd'ddddddd
  
          |d2d
d'ddddddd
  
          |d3dd'dddddd"d
  
          |d4dd'dddddd"d
  
          |d4d
d'dddddd"d
  
          |d5dd'ddddddd
  
         d S )6Nc                 j                         t          j        | |          d d         |           d S )Nrc   )r
   r   r   )valuer   expectedr   s      r   checkz+CalculationTests.test_week_0.<locals>.checkW  s5    Y5eVDDSbSI8TTTTTr   z2015 0 0z%Y %U %wi  r>      r   r1   ij  z%Y %W %wi  r8   rd   z2015 1 1z%G %V %urN  ik  z2015 0 1z2015 1 2r   il  z2015 0 2z2015 1 3rK  rM   im  z2015 0 3z2015 1 4r=   z2015 0 4z2015 1 5z2015 0 5z2015 1 6r   z2015 0 6z2015 1 7z2009 0 0rM  i  z2009 1 1z2009 0 1z2009 1 2z2009 0 2z2009 1 3in  z2009 0 3z2009 1 4z2009 0 4z2009 1 5z2009 0 5z2009 1 6z2009 0 6z2009 1 7r   )r   ro  s   ` r   test_week_0zCalculationTests.test_week_0V  s   	U 	U 	U 	U 	Uj*dBAq!QDDDj*dAq!Q1a@@@j*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dBAq!QDDDj*dAq!Q1a@@@j*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dBAq!QDDDj*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@j*dAq!Q1a@@@@@r   N)r   r   r   r   r"   r   r=  rC  rF  r   
is_androidrU  rT  rY   rZ   sysplatform
startswithrj  rq  r   r   r   r6  r6    s       >>( ( ( "D D "!D "4 4 "!4 "Q Q "!Q  (&X_S\,,U3346 6-E -E6 6-E^-A -A -A -A -Ar   r6  c                   \    e Zd ZdZd Zd Zd Zd Z ej	        d          d             Z
dS )	
CacheTestsz!Test that caching works properly.c                 b   t          j        dd           t          j        dd           dt           j        j        _        t           j        }t          j        dd           |                     |t           j                   |                     t          t           j                  d           d S )N10r   r   z%YNir8   )	r   r   _TimeRE_cachera   rW   assertIsNotr
   len_regex_cache)r   original_time_res     r   test_time_re_recreationz"CacheTests.test_time_re_recreation  s     	 t,,, ...37	+0$2 t,,,)9+BCCCY344a88888r   c                    	 t           j        d= n# t          $ r Y nw xY wd}t          t           j                  t           j        k    r;d t           j        |<   |dz  }t          t           j                  t           j        k    ;t          j        dd           |                     t          t           j                  d           d S )Nr   r   r8   ry  )r   r~  KeyErrorr}  _CACHE_MAX_SIZEr   r
   )r   	bogus_keys     r   test_regex_cleanupzCacheTests.test_regex_cleanup  s    	&t,, 	 	 	D		)())Y-FFF04I"9-NI )())Y-FFF 	 t,,,Y344a88888s    
c                     t           j        j        }dt           j        j        _        t          j        dd           |                     |t           j        j                   d S )Nrz  ry  r   )r   r{  ra   rW   r   r|  )r   locale_time_ids     r   test_new_localetimezCacheTests.test_new_localetime  sR     #0<37	+0 t,,,)@)LMMMMMr   c                    t          j        t           j                  }	 t          j        t           j        d           n*# t           j        $ r |                     d           Y nw xY w	 t          j        dd           t          j        }	 t          j        t           j        d           t          j        dd           t          j        }| 	                    ||           n*# t           j        $ r |                     d           Y nw xY wt          j        t           j        |           d S # t          j        t           j        |           w xY w)N)en_USUTF8ztest needs en_US.UTF8 localery  r   )de_DEr  ztest needs de_DE.UTF8 locale)
r   r   r   	setlocaleErrorr  r   r   r{  r|  )r   locale_infofirst_time_resecond_time_res       r   test_TimeRE_recreation_localez(CacheTests.test_TimeRE_recreation_locale  sG   &v~66	:V^->????| 	: 	: 	:MM899999	:	:$T4000%3M> 1BCCC(t444!*!8  ???? < > > ><=====>
 V^[99999FV^[9999sB   A   $A'&A'+!D/ AC$ #D/ $$DD/ 
DD/ /!EzSTD-1DST,M4.1.0,M10.1.0c                    t           j        }t          j        t           j        d         d          }|                     |j        d           t          j        t           j        d         d          }|                     |j        d           t          j        }dt          j        d<   t          j	                     t          j        t           j        d         d          }|                     |j        d           t          j        t           j        d         d          }|                     |j        d           t          j        }| 
                    ||           |                     t                    5  t          j        |d         d           d d d            n# 1 swxY w Y   |                     t                    5  t          j        |d         d           d d d            d S # 1 swxY w Y   d S )Nr   rD   r8   zEST+05EDT,M3.2.0,M11.1.0TZ)r   r   r   r   r
   r   r{  osenvironr  r|  r   r   )r   	oldtznametmr  r  s        r   test_TimeRE_recreation_timezonez*CacheTests.test_TimeRE_recreation_timezone  s    K	%dk!nd;;a(((%dk!nd;;a(((!/5
4
%dk!nd;;a(((%dk!nd;;a((("0777z** 	9 	9$Yq\4888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9z** 	9 	9$Yq\4888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s$   7FF#&F#G--G14G1N)r   r   r   r   r  r  r  r  r   run_with_tzr  r   r   r   rw  rw    s        ++	9 	9 	99 9 9N N N: : :: W2339 9 439 9 9r   rw  __main__)r   rY   r   r   r   r  rs  testr   test.supportr   r   r   rW  r   TestCaser   r   r]   r   r,  r1  r6  rw  r   mainr   r   r   <module>r     s^   % %    				 				 



       5 5 5 5 5 5 * * * * * *    Q Q Q Q QH% Q Q Q
ZA ZA ZA ZA ZAx( ZA ZA ZAzY3 Y3 Y3 Y3 Y3(# Y3 Y3 Y3xO1 O1 O1 O1 O1H% O1 O1 O1b= = = = =(+ = = =G G G G G(# G G GQA QA QA QA QAx( QA QA QAhY9 Y9 Y9 Y9 Y9" Y9 Y9 Y9x zHMOOOOO r   