Your IP : 216.73.217.129


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_strptime.cpython-35.pyc



��YfPs�@s\dZddlZddlZddlZddlZddlZddlZddlmZddl	m
ZddlZGdd�dej
�ZGdd�dej
�ZGd	d
�d
ej
�ZGdd�dej
�ZGd
d�dej
�ZGdd�dej
�ZGdd�dej
�ZGdd�dej
�ZedkrXej�dS)zPyUnit testing against strptime�N)�support)�datec@s"eZdZdZdd�ZdS)�
getlang_Testsz
Test _getlangcCs&|jtj�tjtj��dS)N)�assertEqual�	_strptime�_getlang�locale�	getlocale�LC_TIME)�self�r�7/opt/alt/python35/lib64/python3.5/test/test_strptime.py�
test_basicszgetlang_Tests.test_basicN)�__name__�
__module__�__qualname__�__doc__rrrrr
rsrc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�LocaleTime_Testsz�Tests for _strptime.LocaleTime.

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

    cCs"tj�|_tj�|_dS)z(Create time tuple based on current time.N)�time�	localtime�
time_tupler�
LocaleTime�LT_ins)rrrr
�setUpszLocaleTime_Tests.setUpcCsgtj||j�j�}||j|}|j||d|�|j||d|||f�dS)z�Helper 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-%s: position within tuple incorrect; %s != %sN)r�strftimer�lower�assertInr)rZtesting�	directiveZtuple_positionZ	error_msg�strftime_outputZ
comparisonrrr
�compare_against_time sz%LocaleTime_Tests.compare_against_timecCs<|j|jjddd�|j|jjddd�dS)Nz%A�z#Testing of full weekday name failedz%az*Testing of abbreviated weekday name failed)rr�	f_weekday�	a_weekday)rrrr
�test_weekday.szLocaleTime_Tests.test_weekdaycCs<|j|jjddd�|j|jjddd�dS)Nz%B�z&Testing against full month name failedz%bz-Testing against abbreviated month name failed)rrZf_month�a_month)rrrr
�
test_month6szLocaleTime_Tests.test_monthcCswtjd|j�j�}|j||jjd�|jddkrPd}nd}|j|jj||d�dS)Nz%pz!AM/PM representation not in tuple��rr$z;AM/PM representation in the wrong position within the tuple)rrrrrr�am_pmr)rr�positionrrr
�
test_am_pm>s	zLocaleTime_Tests.test_am_pmcCsktjd|j�j�}|rg|j||jjdkpP||jjdkd||jjf�dS)Nz%Zrr$ztimezone %s not found in %s)rrrr�
assertTruer�timezone)rr-rrr
�
test_timezoneHszLocaleTime_Tests.test_timezonec	Cs�d}tjd
|�}|jtj|jj|�|d�tjd|�}|jtj|jj|�|d
�tjd|�}|jtj|jj|�|d�tj�}d|_	|j
|jd�dS)N��r'���,�7��Lrz%czLC_date_time incorrectz%xzLC_date incorrectz%XzLC_time incorrect�z6LocaleTime's LC directives cannot handle empty strings)	r/r'r0r1r2r3r4r5r)r6r6)rrrrZLC_date_timeZLC_dateZLC_timerrr)r,)rZ
magic_daterZLTrrr
�test_date_timeQs


	zLocaleTime_Tests.test_date_timecCs |j|jjtj��dS)N)rr�langrr)rrrr
�	test_langgszLocaleTime_Tests.test_langN)rrrrrrr#r&r+r.r7r9rrrr
rs
	rc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TimeRETestszTests for TimeRE.cCs"tj�|_tj�|_dS)z Construct generic TimeRE object.N)r�TimeRE�time_rer�locale_time)rrrr
rpszTimeRETests.setUpcCs�|jjd�}|j|j|jjd�d	kd|�|j|j|jjd�d
kd|�|j|j|jd�dkd|�dS)Nz%a %A %dr4r$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@r@)r<�patternr,�findr=r"r!)r�pattern_stringrrr
�test_patternus""zTimeRETests.test_patterncCs-|jjd�}|jd|d|�dS)Nz\d+z\\d\+z/%s does not have re characters escaped properly)r<rAr)rrCrrr
�test_pattern_escaping�sz!TimeRETests.test_pattern_escapingcCs�|jjd�j|jjd�}|j|oM|jd�|jjdkd�|jjd�}|jd|jjd|jjdf�}|j|d|j	d|jjd|jjdff�|j|jd	�|jjdko|jd
�|jjdkd|j
|jj	|jd	�|jd
�f�xjd D]b}|jjd|�}|jtj
d|��}|j|dtj
d|�|j	f�qHWdS)!Nz%Ar �Azre object for '%A' failedz%a %bz%s %sr>z,Match failed with '%s' regex and '%s' string�a�bzkre object couldn't find the abbreviated weekday month in '%s' using '%s'; group 'a' = '%s', group 'b' = %s'�B�cr?�H�I�j�m�M�p�S�U�w�W�x�X�y�Y�Z�%z(Matching failed on '%s' using '%s' regex)rGrFrHrIrJr?rKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZ)r<�compile�matchr=r!r,�groupr"r%rA�string�rerr)r�foundZcompiledrrrr
�test_compile�s,%(	%
zTimeRETests.test_compilecCsJtj�}t�t�f|_|jtj|�jd�dd�dS)Nz%Zr6z6with timezone == ('',''), TimeRE().pattern('%Z') != '')rr�	frozensetr-rr;rA)rZtest_localerrr
�test_blankpattern�szTimeRETests.test_blankpatterncCs5|jjd�}|jd�}|j|d�dS)Nz\w+ %mz\w+ 10z"Escaping failed of format '\w+ 10')r<r[r\r,)rZcompiled_rer`rrr
�test_matching_with_escapes�sz&TimeRETests.test_matching_with_escapescCs\tj�}td�td�f|_tj|�}|j|jd�jd�d�dS)N�utc�gmt�Tokyo (standard time)zTokyo (daylight time)z%ZzFlocale data that contains regex metacharacters is not properly escaped)rerfrg)rrrbr-r;r,r[r\)rr=r<rrr
�'test_locale_data_w_regex_metacharacters�sz3TimeRETests.test_locale_data_w_regex_metacharacterscCsH|jjd�}|jtj|d��|jtj|d��dS)Nz%j %HZ180z18 0)r<rAZassertFalser_r\r,)rrArrr
�test_whitespace_substitution�sz(TimeRETests.test_whitespace_substitutionN)rrrrrrDrErarcrdrhrirrrr
r:ms

r:c@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4S)5�
StrptimeTestszTests for _strptime.strptime.cCstj�|_dS)zCreate testing time tuple.N)r�gmtimer)rrrr
r�szStrptimeTests.setUpcCs�|jttjdddd�x�dD]�}ytjd|�WnVtk
rWw&Yq&tk
r�}z"|jd	||jjf�WYdd}~Xq&X|jd
|�q&WdS)NZdata_stringz%d�formatz%ArZ�% �%e�2005z'%s' raised %s, not ValueErrorz'%s' did not raise ValueError)rZrmrn)�assertRaises�
ValueErrorr�_strptime_time�	ExceptionZfail�	__class__r)rZ
bad_format�errrrr
�test_ValueError�s

	'zStrptimeTests.test_ValueErrorcCs�|jt��}tjdd�WdQRX|j|jjd�|jt��}tjdd�WdQRX|j|jjd�dS)Nr6z%DTZ19z%Y %)rprqrrrZassertIsZ	exception�__suppress_context__)r�errr
�test_strptime_exception_context�sz-StrptimeTests.test_strptime_exception_contextcCs|jttjdd�dS)Nz10 12z%m)rprqrrr)rrrr
�test_unconverteddata�sz"StrptimeTests.test_unconverteddatacCsotjd||j�}tj|d|�}|j|||j|kd|||||j|f�dS)zHelper fxn in testing.rZz2testing of '%s' directive failed; '%s' -> %s != %sN)rrrrrrr,)rrr*�strf_output�strp_outputrrr
�helper�s
zStrptimeTests.helpercCs�xdD]}|j|d�qWxodD]g\}}xX|D]P}tj|d
�}|t|�}|j|d|kd||df�q;Wq(WdS)NrWrXr�l�69�99���00�68z%yz1'y' test failed; passed in '%s' and returned '%s')rWrX�rr��r~r��r�r��r�r�)r�r�)r}rrr�intr,)rrZcenturyZboundsZboundr|Zexpected_resultrrr
�	test_year�s

zStrptimeTests.test_yearcCs%xdD]}|j|d�qWdS)NrIrHrNr$)rIrHrN)r})rrrrr
r&s
zStrptimeTests.test_monthcCs|jdd�dS)Nr?r4)r})rrrr
�test_dayszStrptimeTests.test_daycCst|jdd�tjd|j�}tj|d�}|j|d|jdkd||d|jdf�dS)NrKr'z%I %pz7testing of '%%I %%p' directive failed; '%s' -> %s != %s)r}rrrrrrr,)rr{r|rrr
�	test_hourszStrptimeTests.test_hourcCs|jdd�dS)NrOr>)r})rrrr
�test_minuteszStrptimeTests.test_minutecCs|jdd�dS)NrQ�)r})rrrr
�test_secondszStrptimeTests.test_secondcCseddl}|jddddddd�}tjt|�dd	�\}}|j||j�dS)
Nri�r(��"�8i�4rlz%Y-%m-%d %H:%M:%S.%f)�datetimer�strrZmicrosecond)rr�r?�tupZfracrrr
�
test_fractions!!zStrptimeTests.test_fractioncCs%xdD]}|j|d�qWdS)NrFrGrSr )rFrGrS)r})rrrrr
r##s
zStrptimeTests.test_weekdaycCs|jdd�dS)NrM�)r})rrrr
�test_julian(szStrptimeTests.test_juliancCs�tjdd�}|j|jd�tjdd�}|j|jd�tj�}tjd�}tj|d�}tj�}tjdtjdks�tj	r�|j
|d|dkd||d|df�n|j
|dd	kd�dS)
N�UTCz%Zr�GMTr$�z'timezone check failed; '%s' -> %s != %sz]LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1r@)rrrr�tm_isdstrrrr�tzname�daylightr,)rr|rr{r=rrr
r.,s$zStrptimeTests.test_timezonecCs�tjd}|j�dkr,|jd�tjtd||f���tjtdd��tjtdd	d
���\||ft_dt_tj|d�d}|j	|dd
tj|tj|f�WdQRXWdQRXWdQRXdS)Nrr�r�zneed non-UTC/GMT timezoner�r�r$�tzsetcSsdS)Nrrrrr
�<lambda>Ksz1StrptimeTests.test_bad_timezone.<locals>.<lambda>z%Zr�z^%s lead to a timezone value of %s instead of -1 when time.daylight set to %s and passing in %s)r�r�r@)
rr��upper�skipTestrZ	swap_attrr�rrrr)rZtz_nameZtz_valuerrr
�test_bad_timezoneBs

	zStrptimeTests.test_bad_timezonecCs+x$td�D]}|jd|�q
WdS)Nr rJ)�ranger})rr*rrr
r7TszStrptimeTests.test_date_timecCs.x'tdd�D]}|jd|�qWdS)Nrr'rU)r�r})rr*rrr
�	test_dateYszStrptimeTests.test_datecCs.x'tdd�D]}|jd|�qWdS)Nr'r rV)r�r})rr*rrr
�	test_time^szStrptimeTests.test_timecCsctjd|j�}tj|d�}|j|d|jdkoX|d|jdkd�dS)Nz%m %% %Yrr$zhandling of percent sign failed)rrrrrrr,)rr{r|rrr
�test_percentcs
zStrptimeTests.test_percentcCstjd|j�}|jtj|j�d�d�|jtj|j�d�d�|jtj|j�d�d�dS)Nz%Bz0strptime does not handle ALL-CAPS names properlyz1strptime does not handle lowercase names properlyz/strptime does not handle capword names properly)	rrrr,rrrr�r�
capitalize)rr{rrr
�test_caseinsensitiveksz"StrptimeTests.test_caseinsensitivec	Cs<d}tjdd�}|j||kd||f�dS)	N�lr$r�1z%mz5Default values for strptime() are incorrect; %s != %sr@)	r�r$r$rrrrr$r@)rrrr,)rZdefaultsr|rrr
�
test_defaultsus
zStrptimeTests.test_defaultscCs#d}|jtj||��dS)Nz.^$*+?{}\[]|)()r,rrr)rZ
need_escapingrrr
�
test_escaping}szStrptimeTests.test_escapingcCstjdd�dS)NzFeb 29z%b %d)r�strptime)rrrr
�$test_feb29_on_leap_year_without_year�sz2StrptimeTests.test_feb29_on_leap_year_without_yearcCs,|jtjdd�tjdd��dS)NzFeb 29z%b %dzMar 1)Z
assertLessrr�)rrrr
�7test_mar1_comes_after_feb29_even_when_omitting_the_year�szEStrptimeTests.test_mar1_comes_after_feb29_even_when_omitting_the_yearN)rrrrrrvryrzr}r�r&r�r�r�r�r�r#r�r.r�r7r�r�r�r�r�r�r�r�rrrr
rj�s4
	
	
	rjc@s"eZdZdZdd�ZdS)�Strptime12AMPMTestsz9Test a _strptime regression in '%I %p' at 12 noon (12 PM)cCs�|j}|tjdd�dd�|tjdd�dd�|tjdd�dd�|tjdd�dd�dS)Nz12 PMz%I %pr'r(z12 AMr)rrr�rrr)r�eqrrr
�test_twelve_noon_midnight�s
	z-Strptime12AMPMTests.test_twelve_noon_midnightN)rrrrr�rrrr
r��sr�c@s"eZdZdZdd�ZdS)�JulianTestsz@Test a _strptime regression that all julian (1-366) are acceptedcCsH|j}x8tdd�D]'}|tjd|d�d|�qWdS)Nr$ioz%d 2004z%j %Yr�)rr�rrr)rr��irrr
�test_all_julian_days�s	z JulianTests.test_all_julian_daysN)rrrrr�rrrr
r��sr�c@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�CalculationTestsz4Test that strptime() fills in missing info correctlycCstj�|_dS)N)rrkr)rrrr
r�szCalculationTests.setUpcCs]d}tjtj||j�|�}|j|j|jjkd|j|jjf�dS)Nz%Y %m %d %H %M %S %w %Zz'Calculation of tm_yday failed; %s != %s)rrrrrrr,Ztm_yday)r�
format_string�resultrrr
�test_julian_calculation�s	z(CalculationTests.test_julian_calculationc	Cs�d}tjtj||j�|�}|j|j|jjkoi|j|jjkoi|j|jjkd|j|j|j|jj|jj|jjf�dS)Nz%Y %H %M %S %w %j %Zz9Calculation of Gregorian date failed;%s-%s-%s != %s-%s-%s)	rrrrrrr,Ztm_yearZtm_monZtm_mday)rr�r�rrr
�test_gregorian_calculation�s	z+CalculationTests.test_gregorian_calculationcCs]d}tjtj||j�|�}|j|j|jjkd|j|jjf�dS)Nz%Y %m %d %H %S %j %Zz.Calculation of day of the week failed;%s != %s)rrrrrrr,Ztm_wday)rr�r�rrr
�test_day_of_week_calculation�s	z-CalculationTests.test_day_of_week_calculationcs�fdd�}|d.d�|d/d�|d0d
�|d1d�|d2d�|d3d�|d4d�|d5d�|d6d�|d7d�|d8d�|d9d�|d:d�|d;d"�|d<d%�|d=d&�|d>d(�|d?d)�|d@d+�|dAd-�dS)BNcs�x�dD]�}d|}t|�}|j|�}tj||�}�j|dd�|kd||||dd�||d|j�df�qWdS)NrTrRz%%Y %%%s %%wr'z/%s(%s) test failed w/ '%s': %s != %s (%s != %s)r�)rTrR)�
datetime_daterrrrr,Z	timetuple)Z	ymd_tupleZtest_reasonrr�Zdt_dateZ
strp_inputr|)rrr
�test_helper�s

	zSCalculationTests.test_week_of_year_and_day_of_week_calculation.<locals>.test_helper�mr$r'zweek 0r�zcommon case�
z
day on Sunday�z
day on Monday�qzJan 1 on Sunday�rzJan 1 on Mondayr�z)first Sunday in a year starting on Mondayr(�zDec 31 on SundayzDec 31 on Monday���z#Monday in the last week of the yearr1z-Monday in the second-to-last week of the year��
�zrandomly chosen date���zEyear starting and ending on Monday while date not on Sunday or Monday�}r0zXyear starting and ending on Monday with a Monday not at the beginning or end of the yearz8Dec 31 on Monday with year starting and ending on Monday��zFirst Sunday of 2007zSecond Sunday of 2007��zLast Sunday of 2006�zSecond to last Sunday of 2006)r�r$r')r�r$r�)r�r$r�)r�r$r�)r�r$r$)r�r$r$)r�r$r�)r�r(r�)r�r(r�)r�r(r�)r�r(r1)r�r�r�)r�r(r�)r�r�r�)r�r(r0)r�r(r�)r�r$r�)r�r$r�)r�r(r�)r�r(r�r)rr�r)rr
�-test_week_of_year_and_day_of_week_calculation�s*


















z>CalculationTests.test_week_of_year_and_day_of_week_calculationcs"�fdd�}|ddddddddd	d
�
|dddd
ddddd	d�
|dddddddddd�
|dddddddddd�
|ddddddddd
d�
|ddddddddd
d�
|dddddddddd�
|dddddddddd�
|dddd
d
ddddd
�
|dddd
d
ddddd
�
|dddd
dddddd�
|dddd
dddddd�
|dddd
dddddd�
|dddd
dddddd�
|ddddddddd	d�
|ddd d
ddddd	d�
|d!ddddddddd�
|d!ddddddddd�
|d"dddddddd
d�
|d"dddddddd
d�
|d#ddddddddd$�
|d#ddddddddd$�
|d%dd d
d
ddddd
�
|d%dd d
d
ddddd
�
|d&dd d
dddddd�
|d&dd d
dddddd�
|d'dd d
dddddd�
|d'dd d
dddddd�
dS)(Ncs*�jtj||�dd�|�dS)Nr$r@)rrrr)�valuerlZexpected)rrr
�check�sz+CalculationTests.test_week_0.<locals>.checkz2015 0 0z%Y %U %wi�r(�rr ijz%Y %W %wi�r$r>z2015 0 1r�ikz2015 0 2�ilz2015 0 3r�r4imz2015 0 4r'z2015 0 5z2015 0 6r�z2009 0 0i�i�z2009 0 1z2009 0 2z2009 0 3inz2009 0 4z2009 0 5z2009 0 6r)rr�r)rr
�test_week_0�s:%%%%%%%%%%%%%%%%%%%%%%%%%%%zCalculationTests.test_week_0N)
rrrrrr�r�r�r�r�rrrr
r��s		(r�c@saeZdZdZdd�Zdd�Zdd�Zdd	�Zej	d
�dd��Z
d
S)�
CacheTestsz!Test that caching works properly.cCsxtjdd�tjdd�dtjj_tj}tjdd�|j|tj�|jttj�d�dS)N�10z%droz%Y�Nir$)	rrr�
_TimeRE_cacher=r8�assertIsNotr�len�_regex_cache)rZoriginal_time_rerrr
�test_time_re_recreations	z"CacheTests.test_time_re_recreationcCs�ytjd=Wntk
r"YnXd}x3ttj�tjkr^dtj|<|d7}q,Wtjdd�|jttj�d�dS)Nz%drr$r�)rr��KeyErrorr�Z_CACHE_MAX_SIZErrr)rZ	bogus_keyrrr
�test_regex_cleanups

zCacheTests.test_regex_cleanupcCsEtjj}dtjj_tjdd�|j|tjj�dS)Nr�r�z%d)rr�r=r8rrr�)rZlocale_time_idrrr
�test_new_localetime,szCacheTests.test_new_localetimecCs�tjtj�}ytjtjd�Wn"tjk
rM|jd�YnXz�tjdd�tj}y@tjtjd	�tjdd�tj}|j	||�Wn"tjk
r�|jd�YnXWdtjtj|�XdS)
N�en_US�UTF8ztest needs en_US.UTF8 localer�z%d�de_DEztest needs de_DE.UTF8 locale)r�r�)r�r�)
rr	r
�	setlocale�Errorr�rrrr�r�)rZlocale_info�
first_time_re�second_time_rerrr
�test_TimeRE_recreation_locale4s 		z(CacheTests.test_TimeRE_recreation_localezSTD-1DSTcCsLtj}tjtjdd�}|j|jd�tjtjdd�}|j|jd�tj}dtjd<tj	�tjtjdd�}|j|jd�tjtjdd�}|j|jd�tj}|j
||�|jt��tj|dd�WdQRX|jt��tj|dd�WdQRXdS)Nrz%Zr$zEST+05EDT,M3.2.0,M11.1.0ZTZ)
rr�rrrrr�r��os�environr�r�rprq)rZ	oldtznameZtmr�r�rrr
�test_TimeRE_recreation_timezoneQs$		

	z*CacheTests.test_TimeRE_recreation_timezoneN)rrrrr�r�r�r�rZrun_with_tzr�rrrr
r�s
r��__main__)rZunittestrrr_r��sysZtestrr�rr�rZTestCaserrr:rjr�r�r�r�r�mainrrrr
�<module>s&Z[�	o\