
    <e                        	 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 )    N)support)skip_if_buggy_ucrt_strfptime)datec                       e Zd Z	 d ZdS )getlang_Testsc                     |                      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__r    r   r   r   r      s+        Q Q Q Q Qr   r   c                   x    e 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_Testsc                 h    	 t          j                    | _        t          j                    | _        d S r	   )time	localtime
time_tupler   
LocaleTimeLT_insr   s    r   setUpzLocaleTime_Tests.setUp   s(    6.***,,r   c           	          	 t          j        || j                                                  }|| j        |                  }|                     ||d|z             |                     |||d|d|           d S )Nz%s: not found in tuplez#: position within tuple incorrect;  != )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   r7   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   r7   z	timezone z not found in )r   r$   r   r%   
assertTruer    timezone)r   rE   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) rN   z6LocaleTime's LC directives cannot handle empty strings)r   r$   r
   r    LC_date_timeLC_dateLC_timer   r   r>   rD   )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-   r4   r:   r@   unittestskipIfr   is_emscriptenrF   rT   rW   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                   P    e Zd Z	 d Zd Zd Zed             Zd Zd Z	d Z
d Zd	S )
TimeRETestsc                 h    	 t          j                    | _        t          j                    | _        d S r	   )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 %drL   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_   patternrD   findr`   r3   r2   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_   re   r&   rg   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 )Nr/   r0   Azre object for '%A' failedz%a %brc    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' = ')ro   rm   rp   Bcrd   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matchr`   r2   rD   groupr3   r9   re   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 )NrC   rN   z6with timezone == ('',''), TimeRE().pattern('%Z') != '')r   r   	frozensetrE   r
   r^   re   )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   rD   )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)rC   r   zFlocale data that contains regex metacharacters is not properly escaped)r   r   r   rE   r^   rD   r   r   )r   r`   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_   re   assertFalser   r   rD   )r   re   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!   ri   rk   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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 ) StrptimeTestsc                 8    	 t          j                    | _        d S r	   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%dr/   )data_stringformat)r   z% z%e2005z'%s' did not raise ValueErrorrq   z	' raised z, not ValueErrorz1999 50z%Y %Vz1999 51%G %Vrm   ro   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 )NrN   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 )Nr   ztesting of 'z' directive failed; '' -> r#   r   r$   r   r   r   rD   )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 'rq   )r   r   r   intrD   )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)rr   rp   rx   r7   r   r   r(   s     r   r:   zStrptimeTests.test_month  s2    ( 	& 	&IKK	1%%%%	& 	&r   c                 2    |                      dd           d S )Nrd   rL   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 )Nru   r<   %I %pz&testing of '%I %p' directive failed; 'r   r#   )r   r   r$   r   r   r   rD   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 )Nry   rc   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   rd   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   r0   r   r   s     r   r4   zStrptimeTests.test_weekday<  s2    - 	% 	%IKK	!$$$$	% 	%r   c                 2    |                      dd           d S )Nrw      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.000001rb   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rA   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UTCrC   r   GMTr7      ztimezone check failed; 'r   r#   rb   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daylightrD   )r   r   r   r   r`   s        r   rF   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   r7   r  c                      d S r	   r   r   r   r   <lambda>z1StrptimeTests.test_bad_timezone.<locals>.<lambda>  s    d r   rC   r   rb   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 )Nr0   rs   ranger   r   r?   s     r   rT   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<   r0   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   r7   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 )Nr6   z0strptime does not handle ALL-CAPS names properlyz1strptime does not handle lowercase names properlyz/strptime does not handle capword names properly)	r   r$   r   rD   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   r7   r7   r   r   r   r   r7   rb   1r   z-Default values for strptime() are incorrect; r#   )r   r   rD   )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.^$*+?{}\[]|)()rD   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   r4   r   r   r   r   rX   rY   r   rZ   rF   
skipUnlesshasattrr   r
  rT   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S )Strptime12AMPMTestsc                 <   | 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+    s&        C= = = = =r   r+  c                       e Zd Z	 d ZdS )JulianTestsc                     | j         }t          dd          D ]*} |t          j        d|z  d          d         |           +d S )Nr7   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   r3  r   r   r   r0  r0    s+        JG G G G Gr   r0  c                       e 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 )CalculationTestsc                 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   rD   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   rD   tm_yeartm_montm_mdayr9  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   rD   tm_wdayr9  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  r7   r7   r  r=        r=      }  r=   rJ  )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%ur1   r/   rn   )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  r7   r<   zweek 0)r`  r7   r   zcommon case)r`  r7      zday on Sunday)r`  r7      zday on MondayrF  zJan 1 on Sunday)rI  r7   r7   zJan 1 on Monday)rI  r7   r   z)first Sunday in a year starting on Monday)rG  r=   rJ  zDec 31 on SundayrH  zDec 31 on MondayrK  z#Monday in the last week of the year)rL  r=   rI   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)rO  r=   rH   zXyear starting and ending on Monday with a Monday not at the beginning or end of the yearrN  z8Dec 31 on Monday with year starting and ending on Monday)  r7   r   zFirst Sunday of 2007)rf  r7   rb  zSecond Sunday of 2007)  r=   rJ  zLast Sunday of 2006)rg  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 )Nrb   )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   r0   ij  z%Y %W %wi  r7   rc   z2015 1 1z%G %V %urM  ik  z2015 0 1z2015 1 2r   il  z2015 0 2z2015 1 3rJ  rL   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 0rL  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   rn  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<  rB  rE  r   
is_androidrT  rS  rX   rY   sysplatform
startswithri  rp  r   r   r   r5  r5    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   r5  c                   Z    e Zd Z	 d Zd Zd Zd Z ej        d          d             Z	dS )
CacheTestsc                 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Nir7   )	r   r   _TimeRE_cacher`   rV   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   r7   rx  )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 )Nry  rx  r   )r   rz  r`   rV   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 localerx  r   )de_DEr  ztest needs de_DE.UTF8 locale)
r   r   r   	setlocaleErrorr  r   r   rz  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   rC   r7   zEST+05EDT,M3.2.0,M11.1.0TZ)r   r   r   r   r
   r   rz  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   run_with_tzr  r   r   r   rv  rv    s        +	9 	9 	99 9 9N N N: : :: W2339 9 439 9 9r   rv  __main__)rX   r   r   r   r  rr  testr   test.supportr   r   r   rV  r   TestCaser   r   r\   r   r+  r0  r5  rv  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   