m %UIc@sCdZdkZdkZdkZdkZdkZdklZdkl Z dk Z dei fdYZ dei fdYZdei fd YZd ei fd YZd ei fd YZdei fdYZdei fdYZdei fdYZdZedjo endS(sPyUnit testing against strptimeN(s test_support(sdatet getlang_TestscBstZdZdZRS(s Test _getlangcCs&|itititidS(N(tselftfailUnlessEqualt _strptimet_getlangtlocalet getlocaletLC_TIME(R((t//data/zmath/lib/python2.4/test/test_strptime.pyt test_basics(t__name__t __module__t__doc__R (((RR s tLocaleTime_TestscBsVtZdZdZdZdZdZdZdZdZ dZ RS( sTests for _strptime.LocaleTime. All values are lower-cased when stored in LocaleTime, so make sure to compare values after running ``lower`` on them. cCs"ti|_ti|_dS(s(Create time tuple based on current time.N(ttimet localtimeRt time_tupleRt LocaleTimetLT_ins(R((RtsetUpscCsmti||ii}||i|}|i ||jd||i ||jd|||fdS(sHelper method that tests testing against directive based on the tuple_position of time_tuple. Uses error_msg as error message. s%s: not found in tuples-%s: position within tuple incorrect; %s != %sN( Rtstrftimet directiveRRtlowertstrftime_outputttestingttuple_positiont comparisont failUnlesst error_msg(RRRRRRR((Rtcompare_against_times cCs<|i|iiddd|i|iiddddS(Ns%Ais#Testing of full weekday name faileds%as*Testing of abbreviated weekday name failed(RRRt f_weekdayt a_weekday(R((Rt test_weekday-scCs<|i|iiddd|i|iiddddS(Ns%Bis&Testing against full month name faileds%bs-Testing against abbreviated month name failed(RRRtf_monthta_month(R((Rt test_month5scCstid|ii}|i||iijd|iddjo d}nd}|i||ii|jddS(Ns%ps!AM/PM representation not in tupleii iis;AM/PM representation in the wrong position within the tuple( RRRRRRRRtam_pmtposition(RRR%((Rt test_am_pm=s cCsqtid|ii}|oK|i||iidjp||iidjd||iifndS(Ns%Ziistimezone %s not found in %s(RRRRRttimezoneRR(RR'((Rt test_timezoneGs0c Csd}tid |}|i|ti|ii|jd tid |}|i|ti|ii|jd tid|}|i|ti|ii |jdt i }d|_ |i|i ddS(Niiiii,i7iiLis%csLC_date_time incorrects%xsLC_date incorrects%XsLC_time incorrectts6LocaleTime's LC directives cannot handle empty strings( iiiii,i7iiLi(R)R)(t magic_dateRRRRRRt LC_date_timetLC_datetLC_timeRRtLTR$(RRR.R*((Rttest_date_timePs      cCs |i|iitidS(N(RRRtlangRR(R((Rt test_langis( R R R RRR R#R&R(R/R1(((RR s      t TimeRETestscBsMtZdZdZdZdZdZdZdZdZ RS(sTests for TimeRE.cCs"ti|_ti|_dS(s Construct generic TimeRE object.N(RtTimeRERttime_reRt locale_time(R((RRrscCs|iid}|i|i|iiddjd||i|i|iiddjd||i|i|iddjd|dS( Ns%a %A %diis7did not find abbreviated weekday in pattern string '%s'is0did not find full weekday in pattern string '%s'tds.did not find 'd' directive pattern string '%s'( RR4tpatterntpattern_stringRtfindR5RR(RR8((Rt test_patternws" " cCs0|iid}|id|jd|dS(Ns\d+s\\d\+s/%s does not have re characters escaped properly(RR4R7R8R(RR8((Rttest_pattern_escapingscCs|iidi|iid}|i|o|id|iidjd|iid}|id|ii d|ii df}|i|d|i d|ii d|ii dff|i|id |ii djo|id |ii djd |i |ii |id |id fxjd D]b}|iid|}|itid|}|i|dtid||i fqJWdS(!Ns%AitAsre object for '%A' faileds%a %bs%s %sis,Match failed with '%s' regex and '%s' stringtatbskre object couldn't find the abbreviated weekday month in '%s' using '%s'; group 'a' = '%s', group 'b' = %s'tBtcR6tHtItjtmtMtptStUtwtWtxtXtytYtZt%s(Matching failed on '%s' using '%s' regex(R=R<R>R?R@R6RARBRCRDRERFRGRHRIRJRKRLRMRNRORP(RR4tcompiletmatchR5RtfoundRtgrouptcompiledRR"R7tstringtreRRR(RRSRRU((Rt test_compiles%)- 2B2cCsMti}ttf|_|iti|iddjddS(Ns%ZR)s6with timezone == ('',''), TimeRE().pattern('%Z') != ''( RRt test_localet frozensetR'RRR3R7(RRY((Rttest_blankpatterns !cCs5|iid}|id}|i|ddS(Ns\w+ %ms\w+ 10s"Escaping failed of format '\w+ 10'(RR4RQt compiled_reRRRSR(RRSR\((Rttest_matching_with_escapesscCs\ti}tdtdf|_ti|}|i|i di dddS(NtutctgmtsTokyo (standard time)sTokyo (daylight time)s%ZsFlocale data that contains regex metacharacters is not properly escaped(R^R_sTokyo (standard time)( RRR5RZR'R3R4RRRQRR(RR5R4((Rt'test_locale_data_w_regex_metacharacterss  ( R R R RR:R;RXR[R]R`(((RR2os      t StrptimeTestscBstZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZRS(sTests for _strptime.strptime.cCsti|_dS(sCreate testing time tuple.N(RtgmtimeRR(R((RRscCs#|ittidddddS(Nt data_strings%dtformats%A(Rt assertRaisest ValueErrorRtstrptime(R((Rttest_TypeErrorscCs|ittidddS(Ns10 12s%m(RReRfRRg(R((Rttest_unconverteddatascCsotid||i}ti|d|}|i |||i|jd|||||i|fdS(sHelper fxn in testing.RPs2testing of '%s' directive failed; '%s' -> %s != %sN( RRRRRt strf_outputRRgt strp_outputRR%(RRR%RjRk((Rthelpers cCsxd D]}|i|dqWxdd fddffD]g\}}xX|D]P}ti|d }|t |}|i |d|jd ||dfqMWq:WdS(NRMRNiilt69t99it00t68s%ys1'y' test failed; passed in '%s' and returned '%s'(RMRN(RmRn(RoRp( RRRltcenturytboundstboundRRgRktinttexpected_resultR(RRRqRsRkRrRu((Rt test_years cCs%xdD]}|i|dqWdS(NR?R>RDi(R?R>RD(RRRl(RR((RR#scCs|idddS(NR6i(RRl(R((Rttest_dayscCst|iddtid|i}ti|d}|i |d|idjd||d|idfdS(NRAis%I %ps7testing of '%%I %%p' directive failed; '%s' -> %s != %s( RRlRRRRjRRgRkR(RRjRk((Rt test_hours cCs|idddS(NREi(RRl(R((Rt test_minutescCs|idddS(NRGi(RRl(R((Rt test_secondscCs%xdD]}|i|dqWdS(NR<R=RIi(R<R=RI(RRRl(RR((RR scCs|idddS(NRCi(RRl(R((Rt test_julianscCstidd}|i|idtidd}|i|idtidjodSnti }ti d}ti|d}ti }tidtidjp ti o7|i|d|djd||d|dfn|i|dd jd dS( NtUTCs%ZitGMTtmaciis'timezone check failed; '%s' -> %s != %sis]LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1(RRgRkRRttm_isdsttsystplatformRRRRRjRR5ttznametdaylightR(RRjRRkR5((RR( s  & cCstidjodSntid}|id jodSnzmti}ti}||ft_dt_t i |dd}|i |dd ti|ti|fWd|t_|t_XdS( NR~iR|R}is%Ziis^%s lead to a timezone value of %s instead of -1 when time.daylight set to %s and passing in %s(sUTCsGMT(RRRRttz_nametuppertoriginal_tznameRtoriginal_daylightRRgttz_valueRR(RRRRR((Rttest_bad_timezone#s      ! cCs+x$tdD]}|id|q WdS(NiR@(trangeR%RRl(RR%((RR/9s cCs.x'tddD]}|id|qWdS(NiiRK(RR%RRl(RR%((Rt test_date>scCs.x'tddD]}|id|qWdS(NiiRL(RR%RRl(RR%((Rt test_timeCscCsdtid|i}ti|d}|i|d|idjo|d|idjddS(Ns%m %% %Yiishandling of percent sign failed( RRRRRjRRgRkR(RRjRk((Rt test_percentHs2cCstid|i}|iti|idd|iti|i dd|iti|i dddS(Ns%Bs0strptime does not handle ALL-CAPS names properlys1strptime does not handle lowercase names properlys/strptime does not handle capword names properly( RRRRRjRRRgRRt capitalize(RRj((Rttest_caseinsensitivePsc Cs<d}tidd}|i||jd||fdS( Niliiit1s%ms5Default values for strptime() are incorrect; %s != %s( iliiiiiiii(tdefaultsRRgRkRR(RRkR((Rt test_defaultsZscCs#d}|iti||dS(Ns.^$*+?{}\[]|)((t need_escapingRRRRg(RR((Rt test_escapingbs(R R R RRhRiRlRvR#RwRxRyRzR R{R(RR/RRRRRR(((RRas,                 tStrptime12AMPMTestscBstZdZdZRS(s9Test a _strptime regression in '%I %p' at 12 noon (12 PM)cCs|i}|tidddd|tidddd|tidddd|tidddddS(Ns12 PMs%I %pii s12 AMi(Rt assertEqualteqRRgR(RR((Rttest_twelve_noon_midnightns  (R R R R(((RRks t JulianTestscBstZdZdZRS(s@Test a _strptime regression that all julian (1-366) are acceptedcCsH|i}x8tddD]'}|tid|dd|qWdS(Niios%d 2004s%j %Yi(RRRRtiRRg(RRR((Rttest_all_julian_daysys (R R R R(((RRvs tCalculationTestscBs;tZdZdZdZdZdZdZRS(s4Test that strptime() fills in missing info correctlycCsti|_dS(N(RRbRR(R((RRscCs]d}titi||i|}|i|i |ii jd|i |ii fdS(Ns%Y %m %d %H %M %S %w %Zs'Calculation of tm_yday failed; %s != %s( t format_stringRRgRRRRtresultRttm_yday(RRR((Rttest_julian_calculations  c Csd}titi||i|}|i|i |ii jo)|i |ii jo|i |ii jd|i |i |i |ii |ii |ii fdS(Ns%Y %H %M %S %w %j %Zs9Calculation of Gregorian date failed;%s-%s-%s != %s-%s-%s( RRRgRRRRRRttm_yearttm_monttm_mday(RRR((Rttest_gregorian_calculations  DcCs]d}titi||i|}|i|i |ii jd|i |ii fdS(Ns%Y %m %d %H %S %j %Zs.Calculation of day of the week failed;%s != %s( RRRgRRRRRRttm_wday(RRR((Rttest_day_of_week_calculations  csd}|d&d|d'd|d(d |d)d |d*d |d+d|d,d|d-d|d.d|d/d|d0d|d1d|d2d|d3d!|d4d$|d5d%dS(6Nc sxdD]}d|}t|}|i|}ti||}i |d |jd||||d ||d|i dfqWdS(NRJRHs %%Y %%%s %%wis/%s(%s) test failed w/ '%s': %s != %s (%s != %s)i(RJRH(RRt datetime_datet ymd_tupletdt_dateRt strp_inputRRgRkRRt test_reasont timetuple(RRRRRkRR(R(Rt test_helpers  imiisweek 0is common casei s day on Sundayis day on MondayiqsJan 1 on SundayirsJan 1 on Mondayis)first Sunday in a year starting on Mondayi isDec 31 on SundaysDec 31 on Mondayiis#Monday in the last week of the yearis-Monday in the second-to-last week of the yearii israndomly chosen dateiisEyear starting and ending on Monday while date not on Sunday or Mondayi}isXyear starting and ending on Monday with a Monday not at the beginning or end of the years8Dec 31 on Monday with year starting and ending on Monday(imii(imii(imii (imii(iqii(irii(irii(iqi i(iri i(ii i(ii i(ii i(ii i(ii i(i}i i(i}i i(R(RR((RRt-test_week_of_year_and_day_of_week_calculations"               (R R R RRRRR(((RRs    t CacheTestscBs)tZdZdZdZdZRS(s!Test that caching works properly.cCstiddtidddtii_tti}tidd|i|tti|i t ti ddS(Nt10s%dt2005s%YtNii( RRgt _TimeRE_cacheR5R0tidtoriginal_time_reRt failIfEqualRtlent _regex_cache(RR((Rttest_time_re_recreationscCsytid=Wntj onXd}x5ttitijodti|<|d7}q-Wtidd|i ttiddS(Ns%diiR( RRtKeyErrort bogus_keyRt_CACHE_MAX_SIZEtNoneRgRR(RR((Rttest_regex_cleanups cCsQttii}dtii_tidd|i|ttiidS(NRRs%d( RRRR5tlocale_time_idR0RgRR(RR((Rttest_new_localetimes  (R R R RRR(((RRs  c Cs&titttttttt dS(N( t test_supportt run_unittestRR R2RaRRRR(((Rt test_mains t__main__(R tunittestRRRWRttestRtdatetimetdateRRtTestCaseRR R2RaRRRRRR (RR2RRRaRRR RRRRWRRRRR((Rt?s&        ]R  K%