a ze@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddlZGdddejZGdd d ejZGd d d ejZGd d d ejZGdddejZGdddejZGdddejZGdddejZedkredS)zPyUnit testing against strptimeN)support)skip_if_buggy_ucrt_strfptime)datec@seZdZdZddZdS) getlang_Testsz Test _getlangcCs|tttjdSN) assertEqual _strptime_getlanglocale getlocaleLC_TIMEselfrF/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_strptime.py test_basicszgetlang_Tests.test_basicN)__name__ __module__ __qualname____doc__rrrrrrsrc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)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. cCst|_t|_dS)z(Create time tuple based on current time.N)time localtime time_tupler LocaleTimeLT_insr rrrsetUps zLocaleTime_Tests.setUpcCsNt||j}||j|}|||d||||d|||fdS)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-%s: position within tuple incorrect; %s != %sN)rstrftimerlowerassertInr)rZtesting directiveZtuple_positionZ error_msgstrftime_outputZ comparisonrrrcompare_against_time!sz%LocaleTime_Tests.compare_against_timecCs,||jjddd||jjddddS)N%Az#Testing of full weekday name failed%az*Testing of abbreviated weekday name failed)r"r f_weekday a_weekdayr rrr test_weekday/s zLocaleTime_Tests.test_weekdaycCs,||jjddd||jjddddS)N%Bz&Testing against full month name failedz%bz-Testing against abbreviated month name failed)r"rZf_montha_monthr rrr test_month7s zLocaleTime_Tests.test_monthcCsVtd|j}|||jjd|jddkr8d}nd}||jj||ddS)Nz%pz!AM/PM representation not in tuple rr*z;AM/PM representation in the wrong position within the tuple)rrrrrram_pmr)rr!positionrrr test_am_pm?s zLocaleTime_Tests.test_am_pmcCsNtd|j}|rJ|||jjdvp8||jjdvd||jjfdS)N%Zrr*ztimezone %s not found in %s)rrrr assertTruertimezone)rr4rrr test_timezoneIs zLocaleTime_Tests.test_timezonecCsd}td|}|t|jj||dtd|}|t|jj||dtd|}|t|jj||dt}d|_ | |jd dS) N) ir-,7Lrz%czLC_date_time incorrectz%xzLC_date incorrectz%XzLC_time incorrect)r<z6LocaleTime's LC directives cannot handle empty strings) rrrrZ LC_date_timeZLC_dateZLC_timerrr/r3)rZ magic_dater!ZLTrrrtest_date_timeRs    zLocaleTime_Tests.test_date_timecCs||jjtdSr)rrlangrr r rrr test_langhszLocaleTime_Tests.test_langN) rrrrrr"r(r,r1r5r=r?rrrrrs  rc@sTeZdZdZddZddZddZedd Zd d Z d d Z ddZ ddZ dS) TimeRETestszTests for TimeRE.cCst|_t|_dS)z Construct generic TimeRE object.N)rTimeREtime_rer locale_timer rrrrqs zTimeRETests.setUpcCst|jd}|||jjddkd||||jjddkd||||jddkd|dS) Nz%a %A %dr: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')rBpatternr3findrCr'r&rZpattern_stringrrr test_patternvs  zTimeRETests.test_patterncCs"|jd}|d|d|dS)Nz\d+z\\d\+z/%s does not have re characters escaped properly)rBrGrrIrrrtest_pattern_escapings  z!TimeRETests.test_pattern_escapingc Cs<|jd|jjd}||o6|d|jjdkd|jd}|d|jjd|jjdf}||d|j d|jjd|jjdff||d |jjdko|d |jjdkd |j |j j |d |d fd D]H}|jd |}|t d |}||dt d ||j fqdS)Nr#r$Azre object for '%A' failedz%a %bz%s %srEz,Match failed with '%s' regex and '%s' stringabzkre object couldn't find the abbreviated weekday month in '%s' using '%s'; group 'a' = '%s', group 'b' = %s')rMrLrNBcrFGHIjmMpSuUVwWxXyYZ%rcz(Matching failed on '%s' using '%s' regex)rBcompilematchrCr&r3groupr'r+rGstringrerr)rfoundZcompiledr rrr test_compiles>    zTimeRETests.test_compilecCs4t}ttf|_|t|ddddS)Nr2r<z6with timezone == ('',''), TimeRE().pattern('%Z') != '')rr frozensetr4rrArG)rZ test_localerrrtest_blankpatterns zTimeRETests.test_blankpatterncCs&|jd}|d}||ddS)Nz\w+ %mz\w+ 10z"Escaping failed of format '\w+ 10')rBrdrer3)rZ compiled_rerirrrtest_matching_with_escapess  z&TimeRETests.test_matching_with_escapescCs@t}tdtdf|_t|}||ddddS)N)ZutcZgmtTokyo (standard time)zTokyo (daylight time)r2rnzFlocale data that contains regex metacharacters is not properly escaped)rrrkr4rAr3rdre)rrCrBrrr'test_locale_data_w_regex_metacharacterss z3TimeRETests.test_locale_data_w_regex_metacharacterscCs4|jd}|t|d|t|ddS)Nz%j %HZ180z18 0)rBrGZ assertFalserhrer3)rrGrrrtest_whitespace_substitutions z(TimeRETests.test_whitespace_substitutionN) rrrrrrJrKrrjrlrmrorprrrrr@ns   r@c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zed"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8S)9 StrptimeTestszTests for _strptime.strptime.cCst|_dS)zCreate testing time tuple.Nrgmtimerr rrrrszStrptimeTests.setUpc Cs|jttjddddD]r}ztd|WnNtyBYqYqtyz}z"|d||jjfWYd}~qd}~00|d|q|ttdd Wdn1s0Y|ttd d Wdn1s0Yd D]B}|t"td d |Wdq1s40Yq|ttddWdn1sn0Y|ttddWdn1s0YdS)N%dr#)Z data_stringformat)rcz% z%e2005z'%s' raised %s, not ValueErrorz'%s' did not raise ValueErrorz1999 50z%Y %Vz1999 51%G %VrLrMr\rYz%G %{}Z2015z%Gz1999 256z%G %j) assertRaises ValueErrorr_strptime_time ExceptionZfail __class__rru)rZ bad_formaterrr\rrrtest_ValueErrors0    * * 4 , zStrptimeTests.test_ValueErrorcCs|t}tddWdn1s,0Y||jjd|t}tddWdn1sr0Y||jjddS)Nr<z%DTZ19z%Y %)ryrzrr{ZassertIs exception__suppress_context__)rerrrtest_strptime_exception_contexts  * *z-StrptimeTests.test_strptime_exception_contextcCs|ttjdddS)Nz10 12%m)ryrzrr{r rrrtest_unconverteddatasz"StrptimeTests.test_unconverteddatac CsVtd||j}t|d|}||||j|kd|||||j|fdS)zHelper fxn in testing.rcz2testing of '%s' directive failed; '%s' -> %s != %sNrrrrr{r3)rr r0 strf_output strp_outputrrrhelpers zStrptimeTests.helperc CsjdD]}||dqdD]J\}}|D]<}t|d}|t|}||d|kd||dfq&qdS)N)r`rar))l)Z69Z99)i)Z00Z68z%yz1'y' test failed; passed in '%s' and returned '%s')rrr{intr3)rr ZcenturyZboundsboundrZexpected_resultrrr test_year s    zStrptimeTests.test_yearcCsdD]}||dqdS)N)rOrNrUr*rrr rrrr,szStrptimeTests.test_monthcCs|dddS)NrFr:rr rrrtest_dayszStrptimeTests.test_daycCsX|ddtd|j}t|d}||d|jdkd||d|jdfdS)NrRr-%I %pz7testing of '%%I %%p' directive failed; '%s' -> %s != %s)rrrrrr{r3rrrrrr test_hour!s  zStrptimeTests.test_hourcCs|dddS)NrVrErr rrr test_minute*szStrptimeTests.test_minutecCs|dddS)NrXrr rrr test_second.szStrptimeTests.test_secondc CsHddl}|ddddddd}tjt|dd \}}}|||jdS) Nrir."8i4z%Y-%m-%d %H:%M:%S.%f)ru)datetimerstrrZ microsecond)rrrFtupZfrac_rrr test_fraction2szStrptimeTests.test_fractioncCsdD]}||dqdS)Nrxr$rrrrrr(9szStrptimeTests.test_weekdaycCs|dddS)NrTrr rrr test_julian>szStrptimeTests.test_juliancCs,d}d}d}tdd\^}}}}||||||dtdd\^}}}}||| ||dtdd\^}}}}||||| ||dtd d\^}}}}||||| ||d td d\^}}}}|||||dtd d\^}}}}|||| ||dtd d\^}}}}||||| ||dtdd\^}}}}||||| ||d tdd\^}}}}|||||||dtdd\^}}}}||d||ddS)Niiz+0130%zrz-0100z-013030z-013030.000001rDz+01:00z-01:30z -01:30:30z-01:30:30.000001z +01:30:30.001irb)rr)rZone_hourZ half_hourZ half_minuteroffsetZoffset_fractionrrr test_offsetBsB           zStrptimeTests.test_offsetcCs&|ttddWdn1s,0Y|ttddWdn1sb0Y|ttddWdn1s0Y|ttddWdn1s0Y|t}tddWdn1s0Y|dt|jdS)Nz -01:30:30.rz-0130:30z-01:30:30.1234567z-01:30:30:123456z-01:3030z!Inconsistent use of : in -01:3030)ryrzrrrr)rr~rrrtest_bad_offsetes * * * * ,zStrptimeTests.test_bad_offsetcCstdd}||jdtdd}||jdt}td}t|d}t}tjdtjdksttj s| |d|dkd||d|dfn| |ddkd dS) NUTCr2rGMTr*z'timezone check failed; '%s' -> %s != %srDz]LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1) rr{rtm_isdstrrrrtznamedaylightr3)rrrrrCrrrr5rs"    zStrptimeTests.test_timezonec Cstjd}|dvr |dttd||fttddttddd N||ft_dt_t|d d }| |d d tj|tj|fWdn1s0YWdn1s0YWdn1s0YdS)Nr)rrzneed non-UTC/GMT timezonerrr*tzsetcSsdSrrrrrrz1StrptimeTests.test_bad_timezone..r2rrDz^%s lead to a timezone value of %s instead of -1 when time.daylight set to %s and passing in %s) rrupperskipTestrZ swap_attrrrr{r)rZtz_nameZtz_valuerrrtest_bad_timezones      zStrptimeTests.test_bad_timezonecCstdD]}|d|qdS)Nr$rPrangerrr0rrrr=s zStrptimeTests.test_date_timecCs tddD]}|d|q dS)Nrr-r^rrrrr test_dateszStrptimeTests.test_datecCs tddD]}|d|q dS)Nr-r$r_rrrrr test_timeszStrptimeTests.test_timecCsJtd|j}t|d}||d|jdko@|d|jdkddS)Nz%m %% %Yrr*zhandling of percent sign failedrrrrr test_percents  zStrptimeTests.test_percentcCsZtd|j}|t|dd|t|dd|t|dddS)Nr)z0strptime does not handle ALL-CAPS names properlyz1strptime does not handle lowercase names properlyz/strptime does not handle capword names properly) rrrr3rr{rr capitalize)rrrrrtest_caseinsensitivesz"StrptimeTests.test_caseinsensitivecCs,d}tdd}|||kd||fdS)N) rr*r*rrrrr*rD1rz5Default values for strptime() are incorrect; %s != %s)rr{r3)rdefaultsrrrr test_defaultss  zStrptimeTests.test_defaultscCsd}|t||dS)Nz.^$*+?{}\[]|)()r3rr{)rZ need_escapingrrr test_escapingszStrptimeTests.test_escapingcCstdddS)NFeb 29%b %d)rstrptimer rrr$test_feb29_on_leap_year_without_yearsz2StrptimeTests.test_feb29_on_leap_year_without_yearcCs |tddtdddS)NrrzMar 1)Z assertLessrrr rrr7test_mar1_comes_after_feb29_even_when_omitting_the_years  zEStrptimeTests.test_mar1_comes_after_feb29_even_when_omitting_the_yearN) rrrrrrrrrrr,rrrrrr(rrrrr5rr=rrrrrrrrrrrrrqs:#    #    rqc@seZdZdZddZdS)Strptime12AMPMTestsz9Test a _strptime regression in '%I %p' at 12 noon (12 PM)cCsb|j}|tdddd|tdddd|tdddd|tdddddS)Nz12 PMrr-r.z12 AMr)rrrrr{)reqrrrtest_twelve_noon_midnights z-Strptime12AMPMTests.test_twelve_noon_midnightN)rrrrrrrrrrsrc@seZdZdZddZdS) JulianTestsz@Test a _strptime regression that all julian (1-366) are acceptedcCs4|j}tddD]}|td|dd|qdS)Nr*ioz%d 2004z%j %Yr)rrrr{)rrirrrtest_all_julian_dayssz JulianTests.test_all_julian_daysN)rrrrrrrrrrsrc@sxeZdZdZddZeddZeddZedd Ze j rHd Z d Z nd Z d Z e ejd dddZddZdS)CalculationTestsz4Test that strptime() fills in missing info correctlycCst|_dSrrrr rrrrszCalculationTests.setUpcCsBd}tt||j|}||j|jjkd|j|jjfdS)Nz%Y %m %d %H %M %S %w %Zz'Calculation of tm_yday failed; %s != %s)rr{rrrr3tm_ydayr format_stringresultrrrtest_julian_calculations z(CalculationTests.test_julian_calculationc Csrd}tt||j|}||j|jjkoF|j|jjkoF|j|jjkd|j|j|j|jj|jj|jjfdS)Nz%Y %H %M %S %w %j %Zz:Calculation of Gregorian date failed; %s-%s-%s != %s-%s-%s) rr{rrrr3tm_yeartm_montm_mdayrrrrtest_gregorian_calculations    z+CalculationTests.test_gregorian_calculationcCsBd}tt||j|}||j|jjkd|j|jjfdS)Nz%Y %m %d %H %S %j %Zz/Calculation of day of the week failed; %s != %s)rr{rrrr3tm_wdayrrrrtest_day_of_week_calculations z-CalculationTests.test_day_of_week_calculation)qr*r*rr.r.}r.r)rwrZaixzbpo-29972: broken test on AIXcsfdd}|dd|dd|dd|d d |d d |d d|dd|dd|dd|dd|dd|dd|dd|dd|dd|dd |d!d"|d#d$|d%d&|d'd(dS))Nc sdD]}|jvr"|jvr"dSdD]}|d|}j|||d^t|}||}t||}d||d|df}|dd||Wdq&1s0Yq&qdS)N)z%Y %Wz%Y %Urw)z%wz%ur%r# )rruz %r: %s != %srr-) _formats_excluded _ymd_excludedZsubTest datetime_daterrr{Z timetupler) Z ymd_tupleZ test_reasonZyear_week_formatZweekday_formatrZdt_dateZ strp_inputrmsgr rr test_helper!s*    zSCalculationTests.test_week_of_year_and_day_of_week_calculation..test_helper)mr*r-zweek 0)rr*rz common case)rr* z day on Sunday)rr*z day on MondayrzJan 1 on Sunday)rr*r*zJan 1 on Monday)rr*rz)first Sunday in a year starting on Monday)rr.rzDec 31 on SundayrzDec 31 on Mondayrz#Monday in the last week of the year)rr.r7z-Monday in the second-to-last week of the year)i zrandomly chosen date)ir.zEyear starting and ending on Monday while date not on Sunday or Monday)rr.r6zXyear starting and ending on Monday with a Monday not at the beginning or end of the yearrz8Dec 31 on Monday with year starting and ending on Monday)r*rzFirst Sunday of 2007)rr*rzSecond Sunday of 2007)r.rzLast Sunday of 2006)rr.zSecond to last Sunday of 2006r)rrrr r-test_week_of_year_and_day_of_week_calculations*                    z>CalculationTests.test_week_of_year_and_day_of_week_calculationc sTfdd}|ddddddddd d |dd d d ddddd d |dddddddddd |dddddddddd |dd dddddddd |ddddddddd d |ddddddddd d |dd ddddddd d |dddddddddd |dddddddddd |dd dddddddd |ddd d d ddddd |ddd d d ddddd |dd d d d ddddd |d dd d dddddd |d!dd d dddddd |d!d d d dddddd |d"dd d ddddd#d |d$dd d ddddd#d |d$d d d ddddd#d |d%dd d ddddd d |d&dd'dddddd d |d&d d(d ddddd d |d)dd'ddddddd |d*dd'ddddddd |d*d d'ddddddd |d+dd'dddddd d |d,dd'dddddd d |d,d d'dddddd d |d-dd'ddddddd. |d/dd'ddddddd. |d/d d'ddddddd. |d0dd(d d ddddd |d1dd(d d ddddd |d1d d(d d ddddd |d2dd(d dddddd |d3dd(d dddddd |d3d d(d dddddd |d4dd(d ddddd#d |d5dd(d ddddd#d |d5d d(d ddddd#d |d6dd(d ddddd d dS)7Ncs t||dd|dS)NrD)rrr{)valueruZexpectedr rrcheckNsz+CalculationTests.test_week_0..checkz2015 0 0z%Y %U %wir.rr$ijz%Y %W %wir*rEz2015 1 1z%G %V %urikz2015 0 1z2015 1 2rilz2015 0 2z2015 1 3rr:imz2015 0 3z2015 1 4r-z2015 0 4z2015 1 5z2015 0 5z2015 1 6rz2015 0 6z2015 1 7z2009 0 0riz2009 1 1z2009 0 1z2009 1 2z2009 0 2z2009 1 3inz2009 0 3z2009 1 4z2009 0 4z2009 1 5z2009 0 5z2009 1 6z2009 0 6z2009 1 7r)rrrr r test_week_0MsV zCalculationTests.test_week_0N)rrrrrrrrrrZ is_androidrrunittestZskipIfsysplatform startswithrrrrrrrs$    /rc@sBeZdZdZddZddZddZdd Ze d d d Z d S) CacheTestsz!Test that caching works properly.cCsXtddtdddtjj_tj}tdd||tj|ttjddS)N10rtrvz%YNir*) rr{ _TimeRE_cacherCr> assertIsNotrlen _regex_cache)rZoriginal_time_rerrrtest_time_re_recreations    z"CacheTests.test_time_re_recreationcCsjz tjd=WntyYn0d}ttjtjkrHdtj|<|d7}q$tdd|ttjddS)Nrtrr*r)rrKeyErrorrZ_CACHE_MAX_SIZEr{r)rZ bogus_keyrrrtest_regex_cleanups     zCacheTests.test_regex_cleanupcCs2tjj}dtjj_tdd||tjjdS)Nrrrt)rrrCr>r{r)rZlocale_time_idrrrtest_new_localetimes  zCacheTests.test_new_localetimec Csttj}zttjdWntjy<|dYn0zttddtj}z0ttjdtddtj}| ||Wntjy|dYn0Wttj|nttj|0dS)N)en_USUTF8ztest needs en_US.UTF8 localerrt)de_DErztest needs de_DE.UTF8 locale) r r r setlocaleErrorrrr{rr)rZ locale_info first_time_resecond_time_rerrrtest_TimeRE_recreation_locales    z(CacheTests.test_TimeRE_recreation_localezSTD-1DST,M4.1.0,M10.1.0cCs*tj}ttjdd}||jdttjdd}||jdtj}dtjd<t ttjdd}||jdttjdd}||jdtj}| ||| t  t|ddWdn1s0Y| t  t|ddWdn1s0YdS)Nrr2r*zEST+05EDT,M3.2.0,M11.1.0ZTZ) rrrr{rrrosenvironrrryrz)rZ oldtznameZtmrrrrrtest_TimeRE_recreation_timezones$   . z*CacheTests.test_TimeRE_recreation_timezoneN) rrrrrrrr rZ run_with_tzr rrrrr}s  r__main__)rrrr rhr rtestrZ test.supportrrrrrZTestCaserrr@rqrrrrrmainrrrrs.   Z\   \