{G_Tc@sYdZddlZddlZddlZddlZddlZddlmZddlm Z ddl Z dej fdYZ dej fdYZd ej fd YZd ej fd YZd ej fdYZdej fdYZdej fdYZdej fdYZdZedkrUendS(sPyUnit testing against strptimeiN(t test_support(tdatet getlang_TestscBseZdZdZRS(s Test _getlangcCs&|jtjtjtjdS(N(t assertEqualt _strptimet_getlangtlocalet getlocaletLC_TIME(tself((s./usr/local/lib/python2.7/test/test_strptime.pyt test_basics(t__name__t __module__t__doc__R (((s./usr/local/lib/python2.7/test/test_strptime.pyR stLocaleTime_TestscBsVeZdZdZdZdZdZdZdZdZ 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"tj|_tj|_dS(s(Create time tuple based on current time.N(ttimet localtimet time_tupleRt LocaleTimetLT_ins(R ((s./usr/local/lib/python2.7/test/test_strptime.pytsetUpscCsgtj||jj}||j|}|j||d||j||d|||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(RtstrftimeRtlowertassertInR(R ttestingt directivettuple_positiont error_msgtstrftime_outputt comparison((s./usr/local/lib/python2.7/test/test_strptime.pytcompare_against_times   cCs<|j|jjddd|j|jjddddS(Ns%Ais#Testing of full weekday name faileds%as*Testing of abbreviated weekday name failed(RRt f_weekdayt a_weekday(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_weekday-scCs<|j|jjddd|j|jjddddS(Ns%Bis&Testing against full month name faileds%bs-Testing against abbreviated month name failed(RRtf_monthta_month(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_month5scCswtjd|jj}|j||jjd|jddkrPd}nd}|j|jj||ddS(Ns%ps!AM/PM representation not in tupleii iis;AM/PM representation in the wrong position within the tuple(RRRRRRtam_pmR(R Rtposition((s./usr/local/lib/python2.7/test/test_strptime.pyt test_am_pm=s cCsntjd|jj}|rj|j||jjdkpP||jjdkd||jjfndS(Ns%Ziistimezone %s not found in %s(RRRRt assertTrueRttimezone(R R)((s./usr/local/lib/python2.7/test/test_strptime.pyt test_timezoneGs c Csd}tjd |}|jtj|jj||d tjd |}|jtj|jj||d tjd|}|jtj|jj||dtj}d|_ |j |jddS(Niiiii,i7iiLis%csLC_date_time incorrects%xsLC_date incorrects%XsLC_time incorrectts6LocaleTime's LC directives cannot handle empty strings( iiiii,i7iiLi(R+R+( RRRRt LC_date_timetLC_datetLC_timeRRR%R((R t magic_dateRtLT((s./usr/local/lib/python2.7/test/test_strptime.pyttest_date_timePs     cCs |j|jjtjdS(N(RRtlangRR(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_langfs( R R R RRR!R$R'R*R1R3(((s./usr/local/lib/python2.7/test/test_strptime.pyRs     t TimeRETestscBsVeZdZdZdZdZdZdZdZdZ dZ RS( sTests for TimeRE.cCs"tj|_tj|_dS(s Construct generic TimeRE object.N(RtTimeREttime_reRt locale_time(R ((s./usr/local/lib/python2.7/test/test_strptime.pyRoscCs|jjd}|j|j|jjddkd||j|j|jjddkd||j|j|jddkd|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'(R6tpatternR(tfindR7R R(R tpattern_string((s./usr/local/lib/python2.7/test/test_strptime.pyt test_patternts""cCs-|jjd}|jd|d|dS(Ns\d+s\\d\+s/%s does not have re characters escaped properly(R6R9R(R R;((s./usr/local/lib/python2.7/test/test_strptime.pyttest_pattern_escapings cCs|jjdj|jjd}|j|oM|jd|jjdkd|jjd}|jd|jjd|jjdf}|j|d|j d|jjd|jjdff|j|jd |jjdko|jd |jjdkd |j |j j |jd |jd fxjd D]b}|jjd|}|jt j d|}|j|dt j d||j fqHWdS(!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'tBtcR8tHtItjtmtMtptStUtwtWtxtXtytYtZt%s(Matching failed on '%s' using '%s' regex(R?R>R@RARBR8RCRDRERFRGRHRIRJRKRLRMRNRORPRQRR(R6tcompiletmatchR7RR(tgroupR R#R9tstringtreRR(R tfoundtcompiledR((s./usr/local/lib/python2.7/test/test_strptime.pyt test_compiles,%( %  cCsJtj}ttf|_|jtj|jddddS(Ns%ZR+s6with timezone == ('',''), TimeRE().pattern('%Z') != ''(RRt frozensetR)RR5R9(R t test_locale((s./usr/local/lib/python2.7/test/test_strptime.pyttest_blankpatterns cCs5|jjd}|jd}|j|ddS(Ns\w+ %ms\w+ 10s"Escaping failed of format '\w+ 10'(R6RSRTR((R t compiled_reRX((s./usr/local/lib/python2.7/test/test_strptime.pyttest_matching_with_escapesscCs\tj}tdtdf|_tj|}|j|jdjdddS(NtutctgmtsTokyo (standard time)sTokyo (daylight time)s%ZsFlocale data that contains regex metacharacters is not properly escaped(R`RasTokyo (standard time)(RRR[R)R5R(RSRT(R R7R6((s./usr/local/lib/python2.7/test/test_strptime.pyt'test_locale_data_w_regex_metacharacterss cCsH|jjd}|jtj|d|jtj|ddS(Ns%j %Ht180s18 0(R6R9t assertFalseRWRTR((R R9((s./usr/local/lib/python2.7/test/test_strptime.pyttest_whitespace_substitutions( R R R RR<R=RZR]R_RbRe(((s./usr/local/lib/python2.7/test/test_strptime.pyR4ls      t StrptimeTestscBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZRS(sTests for _strptime.strptime.cCstj|_dS(sCreate testing time tuple.N(RtgmtimeR(R ((s./usr/local/lib/python2.7/test/test_strptime.pyRscCs|jttjddddxyd D]q}ytjd|WnCtk rVq&q&tk r}|jd ||jjfq&X|jd |q&WdS( Nt data_strings%dtformats%ARRs% s%et2005s'%s' raised %s, not ValueErrors'%s' did not raise ValueError(RRs% s%e(t assertRaisest ValueErrorRt_strptime_timet Exceptiontfailt __class__R (R t bad_formatterr((s./usr/local/lib/python2.7/test/test_strptime.pyttest_ValueErrors   cCs|jttjdddS(Ns10 12s%m(RkRlRRm(R ((s./usr/local/lib/python2.7/test/test_strptime.pyttest_unconverteddatascCsotjd||j}tj|d|}|j|||j|kd|||||j|fdS(sHelper fxn in testing.RRs2testing of '%s' directive failed; '%s' -> %s != %sN(RRRRRmR((R RR&t strf_outputt strp_output((s./usr/local/lib/python2.7/test/test_strptime.pythelpers  cCsxd D]}|j|dqWxdd fddffD]g\}}xX|D]P}tj|d }|t|}|j|d|kd ||dfqMWq:WdS(NRORPiilt69t99it00t68s%ys1'y' test failed; passed in '%s' and returned '%s'(RORP(RxRy(RzR{(RwRRmtintR((R RtcenturytboundstboundRvtexpected_result((s./usr/local/lib/python2.7/test/test_strptime.pyt test_years % cCs%xdD]}|j|dqWdS(NRAR@RFi(RAR@RF(Rw(R R((s./usr/local/lib/python2.7/test/test_strptime.pyR$s cCs|jdddS(NR8i(Rw(R ((s./usr/local/lib/python2.7/test/test_strptime.pyttest_dayscCst|jddtjd|j}tj|d}|j|d|jdkd||d|jdfdS(NRCis%I %ps7testing of '%%I %%p' directive failed; '%s' -> %s != %s(RwRRRRRmR((R RuRv((s./usr/local/lib/python2.7/test/test_strptime.pyt test_hours cCs|jdddS(NRGi(Rw(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_minute scCs|jdddS(NRIi(Rw(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_second scCseddl}|jddddddd}tjt|dd \}}|j||jdS( Niii ii"i8i4Ris%Y-%m-%d %H:%M:%S.%f(tdatetimeRtstrRt microsecond(R RR8ttuptfrac((s./usr/local/lib/python2.7/test/test_strptime.pyt test_fractions !!cCs%xdD]}|j|dqWdS(NR>R?RKi(R>R?RK(Rw(R R((s./usr/local/lib/python2.7/test/test_strptime.pyR!s cCs|jdddS(NREi(Rw(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt test_julianscCstjdd}|j|jdtjdd}|j|jdtj}tjd}tj|d}tj}tjdtjdkstj r|j |d|dkd||d|dfn|j |ddkd dS( NtUTCs%ZitGMTiis'timezone check failed; '%s' -> %s != %sis]LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1( RRmRttm_isdstRRRRttznametdaylightR((R RvRRuR7((s./usr/local/lib/python2.7/test/test_strptime.pyR*!s  $cCstjd}|jd kr/|jdnzmtj}tj}||ft_dt_tj|dd}|j|dd tj|tj|fWd|t_|t_XdS( NiRRsneed non-UTC/GMT timezoneis%Ziis^%s lead to a timezone value of %s instead of -1 when time.daylight set to %s and passing in %s(sUTCsGMT(RRtuppertskipTestRRRmR(R ttz_nametoriginal_tznametoriginal_daylightttz_value((s./usr/local/lib/python2.7/test/test_strptime.pyttest_bad_timezone7s      cCs+x$tdD]}|jd|q WdS(NiRB(trangeRw(R R&((s./usr/local/lib/python2.7/test/test_strptime.pyR1KscCs.x'tddD]}|jd|qWdS(NiiRM(RRw(R R&((s./usr/local/lib/python2.7/test/test_strptime.pyt test_datePscCs.x'tddD]}|jd|qWdS(NiiRN(RRw(R R&((s./usr/local/lib/python2.7/test/test_strptime.pyt test_timeUscCsctjd|j}tj|d}|j|d|jdkoX|d|jdkddS(Ns%m %% %Yiishandling of percent sign failed(RRRRRmR((R RuRv((s./usr/local/lib/python2.7/test/test_strptime.pyt test_percentZs cCstjd|j}|jtj|jdd|jtj|jdd|jtj|jdddS(Ns%Bs0strptime does not handle ALL-CAPS names properlys1strptime does not handle lowercase names properlys/strptime does not handle capword names properly( RRRR(RRmRRt capitalize(R Ru((s./usr/local/lib/python2.7/test/test_strptime.pyttest_caseinsensitivebsc Cs<d}tjdd}|j||kd||fdS( Niliiit1s%ms5Default values for strptime() are incorrect; %s != %s( iliiiiiiii(RRmR((R tdefaultsRv((s./usr/local/lib/python2.7/test/test_strptime.pyt test_defaultsls cCs#d}|jtj||dS(Ns.^$*+?{}\[]|)((R(RRm(R t need_escaping((s./usr/local/lib/python2.7/test/test_strptime.pyt test_escapingtscCstjdddS(NsFeb 29s%b %d(Rtstrptime(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt$test_feb29_on_leap_year_without_year}scCs,|jtjddtjdddS(NsFeb 29s%b %dsMar 1(t assertLessRR(R ((s./usr/local/lib/python2.7/test/test_strptime.pyt7test_mar1_comes_after_feb29_even_when_omitting_the_years(R R R RRsRtRwRR$RRRRRR!RR*RR1RRRRRRRR(((s./usr/local/lib/python2.7/test/test_strptime.pyRfs2                  tStrptime12AMPMTestscBseZdZdZRS(s9Test a _strptime regression in '%I %p' at 12 noon (12 PM)cCs|j}|tjdddd|tjdddd|tjdddd|tjdddddS(Ns12 PMs%I %pii s12 AMi(RRRRRm(R teq((s./usr/local/lib/python2.7/test/test_strptime.pyttest_twelve_noon_midnights  (R R R R(((s./usr/local/lib/python2.7/test/test_strptime.pyRst JulianTestscBseZdZdZRS(s@Test a _strptime regression that all julian (1-366) are acceptedcCsH|j}x8tddD]'}|tjd|dd|qWdS(Niios%d 2004s%j %Yi(RRRRm(R Rti((s./usr/local/lib/python2.7/test/test_strptime.pyttest_all_julian_dayss (R R R R(((s./usr/local/lib/python2.7/test/test_strptime.pyRstCalculationTestscBs;eZdZdZdZdZdZdZRS(s4Test that strptime() fills in missing info correctlycCstj|_dS(N(RRgR(R ((s./usr/local/lib/python2.7/test/test_strptime.pyRscCs]d}tjtj||j|}|j|j|jjkd|j|jjfdS(Ns%Y %m %d %H %M %S %w %Zs'Calculation of tm_yday failed; %s != %s(RRmRRRR(ttm_yday(R t format_stringtresult((s./usr/local/lib/python2.7/test/test_strptime.pyttest_julian_calculations  c Csd}tjtj||j|}|j|j|jjkoi|j|jjkoi|j|jjkd|j|j|j|jj|jj|jjfdS(Ns%Y %H %M %S %w %j %Zs9Calculation of Gregorian date failed;%s-%s-%s != %s-%s-%s( RRmRRRR(ttm_yearttm_monttm_mday(R RR((s./usr/local/lib/python2.7/test/test_strptime.pyttest_gregorian_calculations cCs]d}tjtj||j|}|j|j|jjkd|j|jjfdS(Ns%Y %m %d %H %S %j %Zs.Calculation of day of the week failed;%s != %s(RRmRRRR(ttm_wday(R RR((s./usr/local/lib/python2.7/test/test_strptime.pyttest_day_of_week_calculations  csfd}|d-d|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,dS(ANc sxdD]}d|}t|}|j|}tj||}j|d |kd||||d ||d|jdfqWdS(NRLRJs %%Y %%%s %%wis/%s(%s) test failed w/ '%s': %s != %s (%s != %s)i(RLRJ(t datetime_dateRRRmR(t timetuple(t ymd_tuplet test_reasonRRtdt_datet strp_inputRv(R (s./usr/local/lib/python2.7/test/test_strptime.pyt 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 MondayisFirst Sunday of 2007sSecond Sunday of 2007isLast Sunday of 2006isSecond to last Sunday of 2006(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(iii(iii(ii i(ii i((R R((R s./usr/local/lib/python2.7/test/test_strptime.pyt-test_week_of_year_and_day_of_week_calculations*                   (R R R RRRRR(((s./usr/local/lib/python2.7/test/test_strptime.pyRs    t CacheTestscBs2eZdZdZdZdZdZRS(s!Test that caching works properly.cCsxtjddtjdddtjj_tj}tjdd|j|tj|jttjddS(Nt10s%dRjs%YtNii( RRmt _TimeRE_cacheR7R2t assertIsNotRtlent _regex_cache(R toriginal_time_re((s./usr/local/lib/python2.7/test/test_strptime.pyttest_time_re_recreations cCsytjd=Wntk r!nXd}x3ttjtjkr]dtj|<|d7}q+Wtjdd|jttjddS(Ns%diiR(RRtKeyErrorRt_CACHE_MAX_SIZEtNoneRmR(R t bogus_key((s./usr/local/lib/python2.7/test/test_strptime.pyttest_regex_cleanups  cCsEtjj}dtjj_tjdd|j|tjjdS(NRRs%d(RRR7R2RmR(R tlocale_time_id((s./usr/local/lib/python2.7/test/test_strptime.pyttest_new_localetimes cCstjtj}ytjtjdWn!tjk rL|jdnXztjddtj}y@tjtjd tjddtj}|j ||Wn!tjk r|jdnXWdtjtj|XdS( Nten_UStUTF8stest needs en_US.UTF8 localeRs%dtde_DEstest needs de_DE.UTF8 locale(RR(RR( RRRt setlocaletErrorRRRmRR(R t locale_infot first_time_retsecond_time_re((s./usr/local/lib/python2.7/test/test_strptime.pyttest_TimeRE_recreation s   (R R R RRRR(((s./usr/local/lib/python2.7/test/test_strptime.pyRs  c Cs&tjtttttttt dS(N( Rt run_unittestRRR4RfRRRR(((s./usr/local/lib/python2.7/test/test_strptime.pyt test_main)st__main__(R tunittestRRRWtsysttestRRRRRtTestCaseRRR4RfRRRRRR (((s./usr/local/lib/python2.7/test/test_strptime.pyts&      Z[  OA