B
    u9a+                 @   s   d Z ddlZddlZddlZddlmZ ddlZddlZdd Zdd Z	G dd	 d	ej
ZG d
d dej
Zedkr|e  dS )z
Unittest for time.strftime
    N)supportc             C   s,   | d dkr(| d d d | dd   } | S )N    0	    )sr   r   #/usr/lib/python3.7/test_strftime.py
fixasctime   s    r
   c             C   sD   t | }|t ||}|dd}|dd}|dd}|S )z
    Escape text to deal with possible locale values that have regex
    syntax while allowing regex syntax used for comparison.
    z\%%z\::z\??)reescapereplace)textampmZnew_textr   r   r	   	escapestr   s    
r   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )StrftimeTestc             C   s   t || _t |}|d dk r*d| _nd| _t t |d ddddddddf	| _y&|d rpt jd | _nt jd | _W n t	k
r   d| _Y nX |d dkr|d d | _
n|d dkr|d | _
nd| _
|| _d S )	N      z(AM|am)z(PM|pm)r      r    )timeZgmtimeZgmtZ	localtimer   Zmktimejan1ZtznametzAttributeErrorclock12now)selfr   r   r   r	   _update_variables"   s$    
 (   zStrftimeTest._update_variablesc             C   sj   y dd l }|jj|jjj W nD tk
rd   ddlm}m} ||}||d | 	||| Y nX d S )Nr   )	setlocaleLC_TIMEC)
javautilZLocaleZ
setDefaultZUSImportErrorlocaler!   r"   Z
addCleanup)r   r$   r!   r"   Zsaved_localer   r   r	   setUp8   s    
zStrftimeTest.setUpc             C   s   t   }| | | | | | tjrHtdtjtj	
 d f  xZtddD ]L}xFtdD ]:}|||d  d d  }| | | | | | qbW qTW d S )	Nz/Strftime test, platform: %s, Python version: %sr         d      i  )r   r    	strftest1	strftest2r   verboseprintsysplatformversionsplitrange)r   r   jiargr   r   r	   test_strftimeB   s    




zStrftimeTest.test_strftimec             C   sT  t jrtdt| | j}dtj|d  dfdtj|d  dfdtj	|d  d	fd
tj
|d  dfdd|d  dfdd|d  dfdd| j dfdd|d  dfdd|d  dfdd|d  dfd| jdfd d|d!  d"fd#d|d | jd  d  d$fd%d&d|d  d  d'fd(d|d | jd d d  d  d)fd*d+|d |d |d! f d,fd-d|d. d/  d0fd1d|d.  d2fd3f}x|D ]}yt|d. |}W n: tk
r } z| d4|d. |f  W d d }~X Y nX tt|d | j|rq|r|d. d5kr(| d6|d. |d f  n"| d7|d. |d |d |f  qW d S )8Nzstrftime test forz%a   zabbreviated weekday namez%Azfull weekday namez%br   zabbreviated month namez%Bzfull month namez%dz%02d   zday of month as number (00-31)z%Hr   zhour (00-23)z%Izhour (01-12)z%jz%03d   zjulian day (001-366)z%mzmonth as number (01-12)z%M   zminute, (00-59)z%pzAM or PM as appropriatez%Sr*   zseconds of current time (00-60)z%Uz!week number of the year (Sun 1st)z%wz0?%dzweekday as a number (Sun 1st)z%Wz!week number of the year (Mon 1st)z%Xz%02d:%02d:%02dz%H:%M:%Sz%yr   r,   zyear without centuryz%Yzyear with century)z%%r   zsingle percent signz#strftime '%s' format gave error: %sr   z3strftime does not support standard '%s' format (%s)z-Conflict for %s (%s): expected %s, but got %s)r   r0   r1   r   Zctimer   calendarZday_abbrZday_name
month_abbrZ
month_namer   r   r   strftime
ValueErrorZfailr   matchr   )r   r   Zexpectationseresulterrorr   r   r	   r.   S   sH    
"
(zStrftimeTest.strftest1c             C   sP  t t|d d }| j}dtt|dfdd|d |d |d d	 f d
fdd| j dfdd|d |d |d d	 f dfdd|d  dfdtj|d  dfdd|d  dfddd| j	|d |d | j
f dfdd|d |d f d fd|d!fd"d#d$|d |d |d f d%fd&d'|d d	  d(ff}x|D ]}yt|d |}W nR tk
r } z2d)|d |d t |f }tjrt| w2W d d }~X Y nX tt|d | j
|rtjrFtd*|d |d f  nj|r|d d+krtjrFtd,|d |d f  n4tjr2td-|d |d f  td.|d |f  q2W d S )/Nz%cznear-asctime() formatz%xz%02d/%02d/%02dr   r<   r   r,   z%m/%d/%y %H:%M:%Sz%Zz%sztime zone namez%Dzmm/dd/yyz%ez%2dz,day of month as number, blank padded ( 0-31)z%hzabbreviated month namez%kr   zhour, blank padded ( 0-23))z%n
znewline characterz%rz%02d:%02d:%02d %sr>   r*   z%I:%M:%S %pz%Rz	%02d:%02dz%H:%Mzseconds since the Epoch in UCT)z%t	ztab characterz%Tz%02d:%02d:%02dz%H:%M:%Sz%3yz%03dz.year without century rendered using fieldwidthz*Error for nonstandard '%s' format (%s): %sz%Supports nonstandard '%s' format (%s)r   z+Does not appear to support '%s' format (%s)z*Conflict for nonstandard '%s' format (%s):z  Expected %s, but got %s)strintr   r
   r   Zasctimer   r?   r@   r   r   rA   rB   r   r0   r1   r   rC   r   )r   r   ZnowsecsZnonstandard_expectationsrD   rE   msgr   r   r	   r/      sN    "zStrftimeTest.strftest2N)__name__
__module____qualname__r    r(   r:   r.   r/   r   r   r   r	   r       s
   
0r   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	
Y1900TestszA limitation of the MS C runtime library is that it crashes if
    a date before 1900 is passed with a format string containing "%y"
    c          	   C   sV   d}t jdkst jdr>| t td| W d Q R X n| td|d d S )N)	ik  r   r   r   r   r   r   r   r   win32)ZaixZsunosZsolarisz%yZ99)r2   r3   
startswithZassertRaisesrB   r   rA   assertEqual)r   tr   r   r	   test_y_before_1900   s    
zY1900Tests.test_y_before_1900c             C   s   |  tddd d S )Nz%y)	il  r   r   r   r   r   r   r   r   Z00)rS   r   rA   )r   r   r   r	   test_y_1900   s    zY1900Tests.test_y_1900c             C   s   |  tddd d S )Nz%y)	i  r   r   r   r   r   r   r   r   Z13)rS   r   rA   )r   r   r   r	   test_y_after_1900   s    zY1900Tests.test_y_after_1900N)rM   rN   rO   __doc__rU   rV   rW   r   r   r   r	   rP      s   
rP   __main__)rX   r?   r2   r   Ztestr   r   Zunittestr
   r   ZTestCaser   rP   rM   mainr   r   r   r	   <module>   s    