m
fIc           @   sC  d  Z  d k Z d k Z d k Z d k Z d k Z d k l Z d k l	 Z
 d k Z d e i f d     YZ d e i f d     YZ d e i f d	     YZ d
 e i f d     YZ d e i f d     YZ d e i f d     YZ d e i f d     YZ d e i f d     YZ d   Z e d j o e   n d S(   s   PyUnit testing against strptimeN(   s   test_support(   s   datet   getlang_Testsc           B   s   t  Z d  Z d   Z RS(   s   Test _getlangc         C   s&   |  i t i   t i t i   d  S(   N(   t   selft   failUnlessEqualt	   _strptimet   _getlangt   localet	   getlocalet   LC_TIME(   R   (    (    t/   /mit/python/lib/python2.4/test/test_strptime.pyt
   test_basic   s    (   t   __name__t
   __module__t   __doc__R	   (    (    (    R   R       s    t   LocaleTime_Testsc           B   sV   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s   Tests for _strptime.LocaleTime.

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

    c         C   s"   t  i   |  _ t i   |  _ d S(   s(   Create time tuple based on current time.N(   t   timet	   localtimeR   t
   time_tupleR   t
   LocaleTimet   LT_ins(   R   (    (    R   t   setUp   s     c         C   sm   t  i | |  i  i   } | |  i | } |  i
 | | j d |  |  i
 | | j d | | | f  d S(   s   Helper 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(   R   t   strftimet	   directiveR   R   t   lowert   strftime_outputt   testingt   tuple_positiont
   comparisont
   failUnlesst	   error_msg(   R   R   R   R   R   R   R   (    (    R   t   compare_against_time   s     c         C   s<   |  i |  i i d d d  |  i |  i i d d d  d  S(   Ns   %Ai   s#   Testing of full weekday name faileds   %as*   Testing of abbreviated weekday name failed(   R   R   R   t	   f_weekdayt	   a_weekday(   R   (    (    R   t   test_weekday-   s    c         C   s<   |  i |  i i d d d  |  i |  i i d d d  d  S(   Ns   %Bi   s&   Testing against full month name faileds   %bs-   Testing against abbreviated month name failed(   R   R   R   t   f_montht   a_month(   R   (    (    R   t
   test_month5   s    c         C   s   t  i d |  i  i   } |  i | |  i i j d  |  i d d j  o
 d } n d } |  i | |  i i | j d  d  S(   Ns   %ps!   AM/PM representation not in tuplei   i   i    i   s;   AM/PM representation in the wrong position within the tuple(
   R   R   R   R   R   R   R   R   t   am_pmt   position(   R   R   R%   (    (    R   t
   test_am_pm=   s     
c         C   sq   t  i d |  i  i   } | oK |  i | |  i i d j p | |  i i d j d | |  i i f  n d  S(   Ns   %Zi    i   s   timezone %s not found in %s(   R   R   R   R   R   t   timezoneR   R   (   R   R'   (    (    R   t   test_timezoneG   s    0c      	   C   s   d } t i d
 |  } |  i | t i |  i i |  j d  t i d |  } |  i | t i |  i i |  j d  t i d |  } |  i | t i |  i i	 |  j d  t
 i   } d | _ |  i | i	 d  d  S(   Ni  i   i   i   i,   i7   i   iL   i    s   %cs   LC_date_time incorrects   %xs   LC_date incorrects   %Xs   LC_time incorrectt    s6   LocaleTime's LC directives cannot handle empty strings(	   i  i   i   i   i,   i7   i   iL   i    (   R)   R)   (   t
   magic_dateR   R   R   R   R   R   t   LC_date_timet   LC_datet   LC_timeR   R   t   LTR$   (   R   R   R.   R*   (    (    R   t   test_date_timeP   s     				c         C   s    |  i |  i i t i    d  S(   N(   R   R   R   t   langR   R   (   R   (    (    R   t	   test_langi   s    (   R
   R   R   R   R   R    R#   R&   R(   R/   R1   (    (    (    R   R      s    					
			t   TimeRETestsc           B   sM   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   Tests for TimeRE.c         C   s"   t  i   |  _ t  i   |  _ d S(   s    Construct generic TimeRE object.N(   R   t   TimeRER   t   time_reR   t   locale_time(   R   (    (    R   R   r   s     c         C   s   |  i i d  } |  i | i |  i i d  d j d |  |  i | i |  i i d  d j d |  |  i | i |  i d  d j d |  d  S(	   Ns   %a %A %di   is7   did not find abbreviated weekday in pattern string '%s'i   s0   did not find full weekday in pattern string '%s't   ds.   did not find 'd' directive pattern string '%s'(	   R   R4   t   patternt   pattern_stringR   t   findR5   R   R   (   R   R8   (    (    R   t   test_patternw   s    ""c         C   s0   |  i i d  } |  i d | j d |  d  S(   Ns   \d+s   \\d\+s/   %s does not have re characters escaped properly(   R   R4   R7   R8   R   (   R   R8   (    (    R   t   test_pattern_escaping   s    c         C   s  |  i i d  i |  i i d  } |  i | o | i d  |  i i d j d  |  i i d  } | i d |  i i
 d |  i i d f  } |  i | d | i d |  i i
 d |  i i d f f  |  i | i d	  |  i i
 d j o | i d
  |  i i d j d | i | i i | i d	  | i d
  f  xj d  D]b } |  i i d |  } | i t i d |   } |  i | d t i d |  | i f  qJWd  S(!   Ns   %Ai   t   As   re object for '%A' faileds   %a %bs   %s %si   s,   Match failed with '%s' regex and '%s' stringt   at   bsk   re object couldn't find the abbreviated weekday month in '%s' using '%s'; group 'a' = '%s', group 'b' = %s't   Bt   cR6   t   Ht   It   jt   mt   Mt   pt   St   Ut   wt   Wt   xt   Xt   yt   Yt   Zt   %s(   Matching failed on '%s' using '%s' regex(   R=   R<   R>   R?   R@   R6   RA   RB   RC   RD   RE   RF   RG   RH   RI   RJ   RK   RL   RM   RN   RO   RP   (   R   R4   t   compilet   matchR5   R   t   foundR   t   groupt   compiledR   R"   R7   t   stringt   reR   R   R   (   R   RS   R   RU   (    (    R   t   test_compile   s    %)-	2B2 c         C   sM   t  i   } t   t   f | _ |  i t  i |  i d  d j d  d  S(   Ns   %ZR)   s6   with timezone == ('',''), TimeRE().pattern('%Z') != ''(	   R   R   t   test_localet	   frozensetR'   R   R   R3   R7   (   R   RY   (    (    R   t   test_blankpattern   s    !c         C   s5   |  i i d  } | i d  } |  i | d  d  S(   Ns   \w+ %ms   \w+ 10s"   Escaping failed of format '\w+ 10'(   R   R4   RQ   t   compiled_reRR   RS   R   (   R   RS   R\   (    (    R   t   test_matching_with_escapes   s    c         C   s\   t  i   } t d  t d  f | _ t  i |  } |  i | i	 d  i
 d  d  d  S(   Nt   utct   gmts   Tokyo (standard time)s   Tokyo (daylight time)s   %ZsF   locale data that contains regex metacharacters is not properly escaped(   R^   R_   s   Tokyo (standard time)(   R   R   R5   RZ   R'   R3   R4   R   R   RQ   RR   (   R   R5   R4   (    (    R   t'   test_locale_data_w_regex_metacharacters   s
    (
   R
   R   R   R   R:   R;   RX   R[   R]   R`   (    (    (    R   R2   o   s    						t   StrptimeTestsc           B   s   t  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 d   Z d   Z d   Z d   Z d   Z RS(   s   Tests for _strptime.strptime.c         C   s   t  i   |  _ d S(   s   Create testing time tuple.N(   R   t   gmtimeR   R   (   R   (    (    R   R      s     c         C   s#   |  i t t i d d d d d  S(   Nt   data_strings   %dt   formats   %A(   R   t   assertRaisest
   ValueErrorR   t   strptime(   R   (    (    R   t   test_TypeError   s    c         C   s   |  i t t i d d  d  S(   Ns   10 12s   %m(   R   Re   Rf   R   Rg   (   R   (    (    R   t   test_unconverteddata   s    c         C   so   t  i d | |  i  } t i | d |  } |  i	 | | |  i | j d | | | | |  i | f  d S(   s   Helper fxn in testing.RP   s2   testing of '%s' directive failed; '%s' -> %s != %sN(   R   R   R   R   R   t   strf_outputR   Rg   t   strp_outputR   R%   (   R   R   R%   Rj   Rk   (    (    R   t   helper   s
     c         C   s   x d D] } |  i | d  q Wx d d f d d f f D]g \ } } xX | D]P } t i | d
  } | t	 |  } |  i | d | j d | | d f  qM Wq: Wd  S(   NRM   RN   i    il  t   69t   99i  t   00t   68s   %ys1   'y' test failed; passed in '%s' and returned '%s'(   RM   RN   (   Rm   Rn   (   Ro   Rp   (   R   R   Rl   t   centuryt   boundst   boundR   Rg   Rk   t   intt   expected_resultR   (   R   R   Rq   Rs   Rk   Rr   Ru   (    (    R   t	   test_year   s       c         C   s%   x d D] } |  i | d  q Wd  S(   NR?   R>   RD   i   (   R?   R>   RD   (   R   R   Rl   (   R   R   (    (    R   R#      s     c         C   s   |  i d d  d  S(   NR6   i   (   R   Rl   (   R   (    (    R   t   test_day   s    c         C   st   |  i d d  t i d |  i  } t i | d  } |  i	 | d |  i d j d | | d |  i d f  d  S(   NRA   i   s   %I %ps7   testing of '%%I %%p' directive failed; '%s' -> %s != %s(
   R   Rl   R   R   R   Rj   R   Rg   Rk   R   (   R   Rj   Rk   (    (    R   t	   test_hour   s
    c         C   s   |  i d d  d  S(   NRE   i   (   R   Rl   (   R   (    (    R   t   test_minute   s    c         C   s   |  i d d  d  S(   NRG   i   (   R   Rl   (   R   (    (    R   t   test_second   s    c         C   s%   x d D] } |  i | d  q Wd  S(   NR<   R=   RI   i   (   R<   R=   RI   (   R   R   Rl   (   R   R   (    (    R   R      s     c         C   s   |  i d d  d  S(   NRC   i   (   R   Rl   (   R   (    (    R   t   test_julian  s    c         C   s  t  i d d  } |  i | i d  t  i d d  } |  i | i d  t i d j o d  Sn t i	   } t i d  } t  i | d  } t  i   } t i d t i d j p t i o7 |  i | d | d j d | | d | d f  n |  i | d d	 j d
  d  S(   Nt   UTCs   %Zi    t   GMTt   maci   i   s'   timezone check failed; '%s' -> %s != %sis]   LocaleTime().timezone has duplicate values and time.daylight but timezone value not set to -1(   R   Rg   Rk   R   R   t   tm_isdstt   syst   platformR   R   R   R   Rj   R   R5   t   tznamet   daylightR   (   R   Rj   R   Rk   R5   (    (    R   R(   
  s    & c         C   s   t  i d j o d  Sn t i d } | i   d
 j o d  Sn zm t i } t i } | | f t _ d t _ t	 i
 | d  d } |  i | d d	 t i | t i | f  Wd  | t _ | t _ Xd  S(   NR~   i    R|   R}   i   s   %Zi   is^   %s lead to a timezone value of %s instead of -1 when time.daylight set to %s and passing in %s(   s   UTCs   GMT(   R   R   R   R   t   tz_namet   uppert   original_tznameR   t   original_daylightR   Rg   t   tz_valueR   R   (   R   R   R   R   R   (    (    R   t   test_bad_timezone#  s     			! 	c         C   s+   x$ t  d  D] } |  i d |  q Wd  S(   Ni   R@   (   t   rangeR%   R   Rl   (   R   R%   (    (    R   R/   9  s     c         C   s.   x' t  d d  D] } |  i d |  q Wd  S(   Ni    i   RK   (   R   R%   R   Rl   (   R   R%   (    (    R   t	   test_date>  s     c         C   s.   x' t  d d  D] } |  i d |  q Wd  S(   Ni   i   RL   (   R   R%   R   Rl   (   R   R%   (    (    R   t	   test_timeC  s     c         C   sd   t  i d |  i  } t i | d  } |  i | d |  i d j o | d |  i d j d  d  S(   Ns   %m %% %Yi    i   s   handling of percent sign failed(	   R   R   R   R   Rj   R   Rg   Rk   R   (   R   Rj   Rk   (    (    R   t   test_percentH  s    2c         C   s   t  i d |  i  } |  i t i | i   d  d  |  i t i | i	   d  d  |  i t i | i
   d  d  d  S(   Ns   %Bs0   strptime does not handle ALL-CAPS names properlys1   strptime does not handle lowercase names properlys/   strptime does not handle capword names properly(   R   R   R   R   Rj   R   R   Rg   R   R   t
   capitalize(   R   Rj   (    (    R   t   test_caseinsensitiveP  s    c      	   C   s<   d } t i d d  } |  i | | j d | | f  d  S(	   Nil  i   i    it   1s   %ms5   Default values for strptime() are incorrect; %s != %s(	   il  i   i   i    i    i    i    i   i(   t   defaultsR   Rg   Rk   R   R   (   R   Rk   R   (    (    R   t   test_defaultsZ  s    c         C   s#   d } |  i t i | |   d  S(   Ns   .^$*+?{}\[]|)((   t   need_escapingR   R   R   Rg   (   R   R   (    (    R   t   test_escapingb  s    (   R
   R   R   R   Rh   Ri   Rl   Rv   R#   Rw   Rx   Ry   Rz   R    R{   R(   R   R/   R   R   R   R   R   R   (    (    (    R   Ra      s,    																					
	t   Strptime12AMPMTestsc           B   s   t  Z d  Z d   Z RS(   s9   Test a _strptime regression in '%I %p' at 12 noon (12 PM)c         C   s   |  i } | t i d d  d d  | t i d d  d d  | t i d d  d d  | t i d d  d d  d  S(   Ns   12 PMs   %I %pi   i   s   12 AMi    (   R   t   assertEqualt   eqR   Rg   R   (   R   R   (    (    R   t   test_twelve_noon_midnightn  s
    	(   R
   R   R   R   (    (    (    R   R   k  s    t   JulianTestsc           B   s   t  Z d  Z d   Z RS(   s@   Test a _strptime regression that all julian (1-366) are acceptedc         C   sH   |  i } x8 t d d  D]' } | t i d | d  d |  q Wd  S(   Ni   io  s   %d 2004s   %j %Yi   (   R   R   R   R   t   iR   Rg   (   R   R   R   (    (    R   t   test_all_julian_daysy  s    	 (   R
   R   R   R   (    (    (    R   R   v  s    t   CalculationTestsc           B   s;   t  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s4   Test that strptime() fills in missing info correctlyc         C   s   t  i   |  _ d  S(   N(   R   Rb   R   R   (   R   (    (    R   R     s    c         C   s]   d } t i t i | |  i  |  } |  i | i	 |  i i	 j d | i	 |  i i	 f  d  S(   Ns   %Y %m %d %H %M %S %w %Zs'   Calculation of tm_yday failed; %s != %s(
   t   format_stringR   Rg   R   R   R   R   t   resultR   t   tm_yday(   R   R   R   (    (    R   t   test_julian_calculation  s
    	c      	   C   s   d } t i t i | |  i  |  } |  i | i	 |  i i	 j o) | i
 |  i i
 j o | i |  i i j d | i	 | i
 | i |  i i	 |  i i
 |  i i f  d  S(   Ns   %Y %H %M %S %w %j %Zs9   Calculation of Gregorian date failed;%s-%s-%s != %s-%s-%s(   R   R   Rg   R   R   R   R   R   R   t   tm_yeart   tm_mont   tm_mday(   R   R   R   (    (    R   t   test_gregorian_calculation  s
    	Dc         C   s]   d } t i t i | |  i  |  } |  i | i	 |  i i	 j d | i	 |  i i	 f  d  S(   Ns   %Y %m %d %H %S %j %Zs.   Calculation of day of the week failed;%s != %s(
   R   R   Rg   R   R   R   R   R   R   t   tm_wday(   R   R   R   (    (    R   t   test_day_of_week_calculation  s
    	c            s     d   } | d& d  | d' d  | d( d	  | d) d  | d* d  | d+ d  | d, d  | d- d  | d. d  | d/ d  | d0 d  | d1 d  | d2 d  | d3 d!  | d4 d$  | d5 d%  d  S(6   Nc            s   x d D] } d | } t |    } | i |  } t i | |  }   i | d  |  j d | | | | d  |  | d | i   d f  q Wd  S(   NRJ   RH   s   %%Y %%%s %%wi   s/   %s(%s) test failed w/ '%s': %s != %s (%s != %s)i   (   RJ   RH   (   R   R   t   datetime_datet	   ymd_tuplet   dt_dateR   t
   strp_inputR   Rg   Rk   R   R   t   test_reasont	   timetuple(   R   R   R   R   Rk   R   R   (   R   (    R   t   test_helper  s     
im  i   i   s   week 0i   s   common casei   s   day on Sundayi   s   day on Mondayiq  s   Jan 1 on Sundayir  s   Jan 1 on Mondayi   s)   first Sunday in a year starting on Mondayi   i   s   Dec 31 on Sundays   Dec 31 on Mondayi  i   s#   Monday in the last week of the yeari   s-   Monday in the second-to-last week of the yeari  i
   i   s   randomly chosen datei  i   sE   year starting and ending on Monday while date not on Sunday or Mondayi}  i   sX   year starting and ending on Monday with a Monday not at the beginning or end of the years8   Dec 31 on Monday with year starting and ending on Monday(   im  i   i   (   im  i   i   (   im  i   i   (   im  i   i   (   iq  i   i   (   ir  i   i   (   ir  i   i   (   iq  i   i   (   ir  i   i   (   i  i   i   (   i  i   i   (   i  i
   i   (   i  i   i   (   i  i
   i   (   i}  i   i   (   i}  i   i   (   R   (   R   R   (    (   R   R   t-   test_week_of_year_and_day_of_week_calculation  s"    (   R
   R   R   R   R   R   R   R   (    (    (    R   R     s    						t
   CacheTestsc           B   s)   t  Z d  Z d   Z d   Z d   Z RS(   s!   Test that caching works properly.c         C   s   t  i d d  t  i d d  d t  i i _ t t  i  } t  i d d  |  i | t t  i   |  i	 t
 t  i  d  d  S(   Nt   10s   %dt   2005s   %Yt   Nii   (   R   Rg   t   _TimeRE_cacheR5   R0   t   idt   original_time_reR   t   failIfEqualR   t   lent   _regex_cache(   R   R   (    (    R   t   test_time_re_recreation  s    c         C   s   y t  i d =Wn t j
 o n Xd } x5 t t  i  t  i j o d  t  i | <| d 7} q- Wt  i d d  |  i	 t t  i  d  d  S(   Ns   %di    i   R   (
   R   R   t   KeyErrort	   bogus_keyR   t   _CACHE_MAX_SIZEt   NoneRg   R   R   (   R   R   (    (    R   t   test_regex_cleanup  s     c         C   sQ   t  t i i  } d t i i _ t i d d  |  i | t  t i i   d  S(   NR   R   s   %d(	   R   R   R   R5   t   locale_time_idR0   Rg   R   R   (   R   R   (    (    R   t   test_new_localetime  s
    	(   R
   R   R   R   R   R   (    (    (    R   R     s    		c        	   C   s&   t  i t t t t t t t t	  d  S(   N(
   t   test_supportt   run_unittestR    R   R2   Ra   R   R   R   R   (    (    (    R   t	   test_main  s    	t   __main__(   R   t   unittestR   R   RW   R   t   testR   t   datetimet   dateR   R   t   TestCaseR    R   R2   Ra   R   R   R   R   R   R
   (   R   R2   R   R   Ra   R   R   R   R   R   R   RW   R   R    R   R   R   (    (    R   t   ?   s&   						]R	K%	