3
Kd5                 @   s   d dl Z d dlmZ d dlZd dlmZmZmZm	Z	 d dl
mZmZmZmZmZmZ G dd dZG dd dZd	d
 ZG dd dZG dd dZdS )    N)date)assert_assert_equalassert_allcloseassert_raises)LineSplitterNameValidatorStringConverterhas_nested_fields
easy_dtypeflatten_dtypec               @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestLineSplitterzTests the LineSplitter class.c             C   sF   d}t  |}t|dddddg t d|}t|dddddg dS )	zTest LineSplitter w/o delimiterz 1 2 3 4  5 # test12345 N)r   r   )selfstrgtest r   Q/var/www/html/virt/lib64/python3.6/site-packages/numpy/lib/tests/test__iotools.pytest_no_delimiter   s
    
z"TestLineSplitter.test_no_delimiterc             C   sD   d}t d|}t|ddddddg t d	|}t|d
dg dS )zTest space delimiterz 1 2 3 4  5 # test r   r   r   r   r   r   z  z1 2 3 4N)r   r   )r   r   r   r   r   r   test_space_delimiter   s
    z%TestLineSplitter.test_space_delimiterc             C   sH   d}t d|}t|dddddg d}t d|}t|d	d
dg dS )zTest tab delimiterz 1	 2	 3	 4	 5  6	r   r   r   r   z5  6z 1  2	 3  4	 5  6z1  2z3  4N)r   r   )r   r   r   r   r   r   test_tab_delimiter!   s    z#TestLineSplitter.test_tab_delimiterc             C   sz   d}t d|}t|ddddddg d	}t d|}t|ddddddg d
}t ddd|}t|ddddddg dS )zTest LineSplitter on delimiterz
1,2,3,4,,5,r   r   r   r   r   r   z 1,2,3,4,,5 # tests    1,2,3,4,,5 % test   ,   %)	delimitercommentsN)r   r   )r   r   r   r   r   r   test_other_delimiter*   s    z%TestLineSplitter.test_other_delimiterc          	   C   sd   d}t d|}t|dddddddg d	}t d
|}t|dg d	}t d|}t|dg dS )z'Test LineSplitter w/ fixed-width fieldsz  1  2  3  4     5   # test   r   r   r   r   r   r   z  1     3  4  5  6# test   z1     3  4  5  6   N)r   r   )r   r   r   r   r   r   test_constant_fixed_width9   s    z*TestLineSplitter.test_constant_fixed_widthc             C   sF   d}t d|}t|ddddg d}t d|}t|dd	d
g d S )Nz  1     3  4  5  6# testr$      r   r   z4  56	   z3  4z5  6)r$   r(   r(   r$   )r(   r(   r*   )r   r   )r   r   r   r   r   r   test_variable_fixed_widthG   s    z*TestLineSplitter.test_variable_fixed_widthN)
__name__
__module____qualname____doc__r   r   r   r#   r'   r+   r   r   r   r   r      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 )TestNameValidatorc             C   s   ddddg}t  j|}t|ddddg t ddj|}t|dddd	g t d
dj|}t|dddd	g t ddj|}t|ddddg ttt dd dS )zTest case sensitivityAabcF)Zcase_sensitiveZA_1BCupperlowerZa_1ZfoobarN)r   validater   r   
ValueError)r   namesr   r   r   r   test_case_sensitivityU   s    z'TestNameValidator.test_case_sensitivityc             C   s<   ddddg}t dddgd}|j|}t|dddd	g d
S )zTest excludelistdatesdataz
Other Datamask)ZexcludelistZdates_Zdata_Z
Other_DataZmask_N)r   r9   r   )r   r;   	validatorr   r   r   r   test_excludelistd   s    
z"TestNameValidator.test_excludelistc             C   sj   d	}t  }t||dddg d
}t||dddg d}t||dddg d}t||dddg dS )zTest validate missing namesr2   r3   r4   r   f0f1f2N)r2   r3   r4   )r   r3   r4   )r2   r3   r   )r   rB   r   )r   r   )r   namelistr@   r   r   r   test_missing_namesk   s    z$TestNameValidator.test_missing_namesc             C   s>   d}t  }t||ddd t||ddddddd	d
g dS )zTest validate nb namesr2   r3   r4      )nbfields   zg%i)rH   
defaultfmtZg0Zg1N)r2   r3   r4   )r2   )r   r   )r   rE   r@   r   r   r   test_validate_nb_namesw   s
    z(TestNameValidator.test_validate_nb_namesc             C   s6   d}t  }t||dk t||dddddg dS )zTest validate no namesNr$   )rH   rB   rC   rD   )r   r   r   )r   rE   r@   r   r   r   test_validate_wo_names   s    z(TestNameValidator.test_validate_wo_namesN)r,   r-   r.   r<   rA   rF   rK   rL   r   r   r   r   r0   S   s
   r0   c             C   s   t tj| dd d  S )Nz%Y-%m-%dr$   )r   timestrptime)sr   r   r   _bytes_to_date   s    rP   c               @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )TestStringConverterzTest StringConverterc             C   s&   t td}t|jd t|jd dS )z"Test creation of a StringConverteri rG   Niayiay)r	   intr   _statusdefault)r   	converterr   r   r   test_creation   s    
z!TestStringConverter.test_creationc             C   s  t  }t|jd t|jdd t|jd ddljj}t|j|j	j
|j|jj
k }t|jdd t|jd|  t|jdd t|jd	|  t|jd
td
 t|jd|  x@dD ]8}|j|}tt|tk t|d t|jd|  qW dS )zTests the upgrade method.r   0rG   NZ17179869184l        z0.g           Z0jr$   r2      a   )r2   rY   )r	   r   rS   upgradeZnumpy.core.numericcorenumericrR   dtypeint_itemsizeint64r   complexr   typestr)r   rU   ZnxZstatus_offsetrO   resr   r   r   test_upgrade   s"     


z TestStringConverter.test_upgradec             C   sx   t d	d}|jd t|dd t|d|j t|d|j t|d|j y|d W n tk
rr   Y nX dS )
z Tests the use of missing values.missingmissed)missing_valuesrW   r   r   ZmissN)rg   rh   )r	   r[   r   rT   r:   )r   rU   r   r   r   test_missing   s    
z TestStringConverter.test_missingc             C   s   t }tjdd }zxtj|tddd t|tddd}|d}t|tddd |d}t|tddd |d}t|tddd W d|t_X dS )	zTests updatemapperNi  rG   z
2001-01-01i  z
2009-01-01i  r   )rP   r	   _mapperZupgrade_mapperr   r   )r   Z
dateparserZ_original_mapperconvertr   r   r   r   test_upgrademapper   s    z&TestStringConverter.test_upgrademapperc             C   s4   t jdd }t t}t|j| tt|d dS )zAMake sure that string-to-object functions are properly recognizedNrT   )r	   rk   rP   r   r   hasattr)r   Z
old_mapperconvr   r   r   test_string_to_object   s    z)TestStringConverter.test_string_to_objectc             C   sp   t dddd}|jd t|jd t|jtjt t dddd}|jd t|jd t|jtjt dS )	z+Make sure we don't lose an explicit defaultNr   i  )ri   rT   z
3.14159265r   ii)r	   r[   r   rT   rc   npr^   float)r   rU   r   r   r   test_keep_default   s    

z%TestStringConverter.test_keep_defaultc             C   s   t tddd}t|jd dS )z'Check that we don't lose a default of 0r   zN/A)rT   ri   N)r	   rR   r   rT   )r   rU   r   r   r   test_keep_default_zero   s    z*TestStringConverter.test_keep_default_zeroc             C   s"   t tddd}t|jddh dS )z*Check that we're not losing missing valuesr   zN/A)rT   ri   r   N)r	   rR   r   ri   )r   rU   r   r   r   test_keep_missing_values   s    z,TestStringConverter.test_keep_missing_valuesc             C   s:   t tjdd}d}t||dk d}t||dk dS )z/Check that int64 integer types can be specifiedr   )rT   z-9223372036854775807l    Z9223372036854775807Nl )r	   rq   ra   r   )r   rU   valr   r   r   test_int64_dtype   s
    z$TestStringConverter.test_int64_dtypec             C   s&   t tjdd}d}t||dk dS )z0Check that uint64 integer types can be specifiedr   )rT   Z9223372043271415339l   +&|    N)r	   rq   Zuint64r   )r   rU   rv   r   r   r   test_uint64_dtype  s    z%TestStringConverter.test_uint64_dtypeN)r,   r-   r.   r/   rV   rf   rj   rm   rp   rs   rt   ru   rw   rx   r   r   r   r   rQ      s   %rQ   c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestMiscFunctionsc             C   sh   t jt}tt|d t jd
dtfg}tt|d t jdtfddtfdgfg}tt|d d	S )zTest has_nested_dtypeFr1   |S3r5   ZBABB|S1TN)r1   rz   )r{   r|   )rq   r^   rr   r   r
   rR   )r   ndtyper   r   r   test_has_nested_dtype  s    
z'TestMiscFunctions.test_has_nested_dtypec             C   s2  t }tt|tjt  d}tt|tjd d!g tt|ddtjd"d#g d}tt|d
dtjd$d%g d}tt|ddtjd&d'g d}tt|ddtjd(d)g tt|dddtjd*d+g dtfdt fg}tt|tjdtfdt fg tt|ddtjdtfdt fg tt|ddtjdtfdt fg tt|ddtjdtfdt fg tt t f}tt|tjdtfdt fdt fg tt t f}tt|ddtjdtfdt fdt fg tjt }tt|ddtjdd d,D  tjt }tt|dddgddtjdd d-D  dS ).zTest ndtype on dtypeszi4, f8rB   i4rC   f8z
field_%03i)rJ   	field_000	field_001za, b)r;   r2   r3   za, b, cz, bzf%02i)r;   rJ   f00r1   r5   za,bza,b,crD   r4   c             S   s   g | ]}|t fqS r   )rr   ).0_r   r   r   
<listcomp>G  s    z5TestMiscFunctions.test_easy_dtype.<locals>.<listcomp>r   c             S   s   g | ]}|t fqS r   )rr   )r   r   r   r   r   r   L  s    f01f02N)rB   r   )rC   r   )r   r   )r   r   )r2   r   )r3   r   )r2   r   )r3   r   )rB   r   )r3   r   )r2   r   )r   r   )r2   r3   r4   )r   r   r   )rr   r   r   rq   r^   rR   )r   r}   r   r   r   test_easy_dtype  sN     



z!TestMiscFunctions.test_easy_dtypec             C   s   t jddg}t|}t|ttg t jdddgfdtfg}t|}t|t jdt jdtg t jdtdffdtd	ffg}t|}t|ttg t|d
}t|tgd tgd	   t jddg}t|}t|ttg dS )zTesting flatten_dtyper2   r   r3   aa|S1ab|S2rX   r$   Tr1   r5   N)r2   r   )r3   r   )r   r   )r   r   r2   r1   )r   r   r3   r5   )r   r   )rq   r^   r   r   rr   rR   )r   dtZdt_flatr   r   r   test_flatten_dtypeN  s    
z$TestMiscFunctions.test_flatten_dtypeN)r,   r-   r.   r~   r   r   r   r   r   r   ry   
  s   	9ry   )rM   datetimer   Znumpyrq   Znumpy.testingr   r   r   r   Znumpy.lib._iotoolsr   r   r	   r
   r   r   r   r0   rP   rQ   ry   r   r   r   r   <module>   s    E6}