B
    u9a=¼  ã               @   sØ  d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ G dd	„ d	ejƒZG d
d„ dejƒZG dd„ dejƒZG dd„ deƒZG dd„ dejƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZG dd„ deƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG d d!„ d!ejƒZ G d"d#„ d#ƒZ!e "e#ed$ƒd%¡G d&d'„ d'ejƒƒZ$G d(d)„ d)ejƒZ%G d*d+„ d+ejƒZ&G d,d-„ d-ejƒZ'e(d.krÔe )¡  dS )/é    N)ÚStringIO)ÚTemporaryFile)Úsupport)Úpermutations)Údedent)ÚOrderedDictc               @   s  e 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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ejd+d,„ ƒZd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Z d9d:„ Z!d;d<„ Z"d=d>„ Z#d?d@„ Z$dAS )BÚTest_Csvc             C   sþ   |   t|¡ |   t|d ¡ | j t||dd | j t||dd | j t||dd |   tj||d¡ | j t||d d | j t||dd | j t||dd | j t||d d | j t||dd | j t||d d	 | j t||tjd
d | j t||tjd d d S )Nr   )Úbad_attr)Ú	delimiterZXXZfooé   )Ú	quotechar)Úlineterminator)ÚquotingÚ )r   r   )ÚassertRaisesÚ	TypeErrorÚcsvÚErrorÚ	QUOTE_ALL)ÚselfÚctorÚarg© r   ú/usr/lib/python3.7/test_csv.pyÚ_test_arg_valid   s     

zTest_Csv._test_arg_validc             C   s   |   tjg ¡ d S )N)r   r   Úreader)r   r   r   r   Útest_reader_arg_valid)   s    zTest_Csv.test_reader_arg_validc             C   s   |   tjtƒ ¡ d S )N)r   r   Úwriterr   )r   r   r   r   Útest_writer_arg_valid,   s    zTest_Csv.test_writer_arg_validc             G   sÚ   ||Ž }|   |jjd¡ |   |jjd¡ |   |jjd ¡ |   |jjd¡ |   |jjd¡ |   |jjtj	¡ |   |jj
d¡ |   |jjd¡ |  tt|jd¡ |  tt|jdd¡ |  tt|jd¡ |  tt|jdd ¡ d S )	Nú,Tz
ú"Fr
   ú:r   )ÚassertEqualÚdialectr
   ÚdoublequoteÚ
escapecharr   r   r   r   ÚQUOTE_MINIMALÚskipinitialspaceÚstrictr   ÚAttributeErrorÚdelattrÚsetattr)r   r   ÚargsÚobjr   r   r   Ú_test_default_attrs/   s    zTest_Csv._test_default_attrsc             C   s   |   tjg ¡ d S )N)r.   r   r   )r   r   r   r   Útest_reader_attrsA   s    zTest_Csv.test_reader_attrsc             C   s   |   tjtƒ ¡ d S )N)r.   r   r   r   )r   r   r   r   Útest_writer_attrsD   s    zTest_Csv.test_writer_attrsc          
   G   sª   t dddddtjddd}|||Ž}|  |jjd¡ |  |jjd¡ |  |jjd¡ |  |jjd¡ |  |jj	d¡ |  |jj
tj¡ |  |jjd¡ |  |jjd¡ d S )Nr!   Fú\úÚ*T)r
   r$   r%   r   r   r   r'   r(   )Údictr   Ú
QUOTE_NONEr"   r#   r
   r$   r%   r   r   r   r'   r(   )r   r   r,   Úkwargsr-   r   r   r   Ú_test_kw_attrsG   s    
zTest_Csv._test_kw_attrsc             C   s   |   tjg ¡ d S )N)r7   r   r   )r   r   r   r   Útest_reader_kw_attrsW   s    zTest_Csv.test_reader_kw_attrsc             C   s   |   tjtƒ ¡ d S )N)r7   r   r   r   )r   r   r   r   Útest_writer_kw_attrsZ   s    zTest_Csv.test_writer_kw_attrsc             G   s¦   G dd„ dƒ}||f }||Ž }|   |jjd¡ |   |jjd¡ |   |jjd¡ |   |jjd¡ |   |jjd¡ |   |jjtj	¡ |   |jj
d¡ |   |jjd¡ d S )	Nc               @   s.   e Zd ZdZdZdZdZdZej	Z
dZdZdS )z-Test_Csv._test_dialect_attrs.<locals>.dialectú-Fú^ú$ú#TN)Ú__name__Ú
__module__Ú__qualname__r
   r$   r%   r   r   r   r   r   r'   r(   r   r   r   r   r#   _   s   r#   r:   Fr;   r<   r=   T)r"   r#   r
   r$   r%   r   r   r   r   r   r'   r(   )r   r   r,   r#   r-   r   r   r   Ú_test_dialect_attrs]   s    	
zTest_Csv._test_dialect_attrsc             C   s   |   tjg ¡ d S )N)rA   r   r   )r   r   r   r   Útest_reader_dialect_attrss   s    z"Test_Csv.test_reader_dialect_attrsc             C   s   |   tjtƒ ¡ d S )N)rA   r   r   r   )r   r   r   r   Útest_writer_dialect_attrsv   s    z"Test_Csv.test_writer_dialect_attrsc          	   K   sV   t ddd@}tj|f|Ž}| |¡ | d¡ |  | ¡ ||jj ¡ W d Q R X d S )Nzw+r   )Únewliner   )	r   r   r   ÚwriterowÚseekr"   Úreadr#   r   )r   ÚfieldsÚexpectr6   Úfileobjr   r   r   r   Ú_write_testz   s    


zTest_Csv._write_testc          
   K   sd   t dddN}tj|f|Ž}|  |¡ | |¡ W d Q R X | d¡ |  | ¡ d¡ W d Q R X d S )Nzw+r   )rD   r   )r   r   r   r   rE   rF   r"   rG   )r   ÚexcrH   r6   rJ   r   r   r   r   Ú_write_error_test‚   s    
zTest_Csv._write_error_testc             C   s|   |   tjd ¡ |  dd¡ |  d gd¡ | j tjd gtjd G dd„ dƒ}|   t|ƒ ¡ G dd„ dƒ}|   t|ƒ g¡ d S )	Nr   r   z"")r   c               @   s   e Zd Zdd„ Zdd„ ZdS )z.Test_Csv.test_write_arg_valid.<locals>.BadListc             S   s   dS )Né
   r   )r   r   r   r   Ú__len__‘   s    z6Test_Csv.test_write_arg_valid.<locals>.BadList.__len__c             S   s   |dkrt ‚d S )Né   )ÚOSError)r   Úir   r   r   Ú__getitem__“   s    z:Test_Csv.test_write_arg_valid.<locals>.BadList.__getitem__N)r>   r?   r@   rO   rS   r   r   r   r   ÚBadList   s   rT   c               @   s   e Zd Zdd„ ZdS )z.Test_Csv.test_write_arg_valid.<locals>.BadItemc             S   s   t ‚d S )N)rQ   )r   r   r   r   Ú__str__˜   s    z6Test_Csv.test_write_arg_valid.<locals>.BadItem.__str__N)r>   r?   r@   rU   r   r   r   r   ÚBadItem—   s   rV   )rM   r   r   rK   r5   rQ   )r   rT   rV   r   r   r   Útest_write_arg_validŠ   s    zTest_Csv.test_write_arg_validc             C   s$   dd }|   ||gd||f ¡ d S )NÚXiPÃ  z%s,%s)rK   )r   Ú	bigstringr   r   r   Útest_write_bigfieldœ   s    zTest_Csv.test_write_bigfieldc             C   sŽ   |   dddgd¡ | jtjdddgtjd | j dddgdtjd | j dddgdtjd | j dddgdtjd | j ddgd	tjd d S )
NÚar   zp,qz	a,1,"p,q")r   z"a",1,"p,q"z"a","1","p,q"za
bz	"a
b","1")rK   rM   r   r   r5   r&   ÚQUOTE_NONNUMERICr   )r   r   r   r   Útest_write_quoting¢   s    



zTest_Csv.test_write_quotingc             C   sª   | j dddgddd | jtjdddgd dd	 | j dddgd
ddd	 | j dgddtjd | j dgddtjdd | j dgddtjd | j dddgddtjd d S )Nr[   r   zp,qz	a,1,"p,q"r1   )r%   zp,"q"F)r%   r$   za,1,"p,\"q\""r    z"""")r%   r   z\")r%   r   r$   za,1,p\,q)rK   rM   r   r   r&   r5   )r   r   r   r   Útest_write_escape¯   s    




zTest_Csv.test_write_escapec             C   s€   |   tdddgƒd¡ |   tddd gƒd¡ |   tg ƒd¡ |   td gƒd¡ | jtjtd gƒtjd |   td d gƒd	¡ d S )
Nr[   r   zp,qz	a,1,"p,q"za,1,r   z"")r   r   )rK   ÚiterrM   r   r   r5   )r   r   r   r   Útest_write_iterableÀ   s    zTest_Csv.test_write_iterablec          	   C   s”   G dd„ dƒ}t  |ƒ ¡}|  t|jdgg¡ tdddP}t  |¡}|  t|jd ¡ | ddgdd	gg¡ | d
¡ |  | 	¡ d¡ W d Q R X d S )Nc               @   s   e Zd Zdd„ ZdS )z+Test_Csv.test_writerows.<locals>.BrokenFilec             S   s   t ‚d S )N)rQ   )r   Úbufr   r   r   ÚwriteÊ   s    z1Test_Csv.test_writerows.<locals>.BrokenFile.writeN)r>   r?   r@   rb   r   r   r   r   Ú
BrokenFileÉ   s   rc   r[   zw+r   )rD   ÚbÚcÚdr   z
a,b
c,d
)
r   r   r   rQ   Ú	writerowsr   r   rF   r"   rG   )r   rc   r   rJ   r   r   r   Útest_writerowsÈ   s    

zTest_Csv.test_writerowsc          	   C   sò   t ddd@}t |¡}| dd gd dgg¡ | d¡ |  | ¡ d¡ W d Q R X t ddd<}t |¡}| d gdgg¡ | d¡ |  | ¡ d¡ W d Q R X t ddd<}t |¡}| dgd gg¡ | d¡ |  | ¡ d	¡ W d Q R X d S )
Nzw+r   )rD   r[   rf   r   za,
,d
z""
a
za
""
)r   r   r   rg   rF   r"   rG   )r   rJ   r   r   r   r   Útest_writerows_with_noneÖ   s    





z!Test_Csv.test_writerows_with_nonec          	   C   s`   dd l }| d¡}tddd8}t |¡}| |gg¡ | d¡ |  | ¡ d¡ W d Q R X d S )Nr   r[   zw+r   )rD   za
)	Ú	_testcapiZunicode_legacy_stringr   r   r   rg   rF   r"   rG   )r   rj   re   rJ   r   r   r   r   Útest_writerows_legacy_stringsé   s    


z&Test_Csv.test_writerows_legacy_stringsc             K   s&   t j|f|Ž}t|ƒ}|  ||¡ d S )N)r   r   Úlistr"   )r   ÚinputrI   r6   r   Úresultr   r   r   Ú
_read_testô   s    zTest_Csv._read_testc             C   s€   |   g g ¡ |   dgg g¡ | jtj| j dgd dd | jtj| j dgd dd | j dgdggdd |  tj| j d	gd ¡ d S )
Nr   z"ab"cr   )r(   zab cÚabcr   )r$   s   ab c)ro   r   r   r   )r   r   r   r   Útest_read_oddinputsù   s    zTest_Csv.test_read_oddinputsc             C   s–   |   dgddgg¡ |   dgddgg¡ |   dgddgg¡ |   dgddgg¡ |  tj| j dgg ¡ |  tj| j dgg ¡ |  tj| j d	gg ¡ d S )
Nza,br[   rd   za,b
za,b
za,bza,bc,dza,b
c,dza,b
c,d)ro   r   r   r   )r   r   r   r   Útest_read_eol  s    zTest_Csv.test_read_eolc             C   s   |   dgddgg¡ |   dgdgg¡ | j dgdggdd | jtj| j dgg dd	 | jtj| j dgg dd	 | jtj| j dgg ddd
 d S )Nza,"r[   r   z"ar;   Ú
)r%   T)r(   )r%   r(   )ro   r   r   r   )r   r   r   r   Útest_read_eof  s    zTest_Csv.test_read_eofc             C   s–   | j dgdddggdd | j dgddggdd | j d	gddggdd | j d
gddggdd | j dgddggdd | j dgddggdd d S )Nza,\b,cr[   rd   re   r1   )r%   za,b\,czb,cza,"b\,c"za,"b,\c"z	a,"b,c\""zb,c"za,"b,c"\zb,c\)ro   )r   r   r   r   Útest_read_escape  s    zTest_Csv.test_read_escapec             C   s¬   |   dgdddgg¡ | j dgdddddggd dd | j dgdddddggtjdd	 | j d
gdddddggtjd |   dgddgg¡ | jt| j dgg gtjd d S )Nz	1,",3,",5Ú1z,3,Ú5r    Ú3r1   )r   r%   )r   r%   z,3,"5",7.3, 9r   é   g333333@é	   )r   z"a
b", 7za
bz 7zabc,3)ro   r   r5   r\   r   Ú
ValueError)r   r   r   r   Útest_read_quoting!  s    


zTest_Csv.test_read_quotingc          	   C   s¾   t  ¡ }z¤d}d| }d||f }|  |g||gg¡ t  |¡ |  |g||gg¡ |  t  ¡ |¡ t  |d ¡ |  t j| j|gg ¡ |  tt jd ¡ |  tt jdd ¡ W d t  |¡ X d S )NiPÃ  rX   z%s,%sr   )r   Zfield_size_limitro   r"   r   r   r   )r   ÚlimitÚsizerY   Zbigliner   r   r   Útest_read_bigfield/  s    
zTest_Csv.test_read_bigfieldc             C   s€   t  dddg¡}|  |jd¡ t|ƒ |  |jd¡ t|ƒ |  |jd¡ t|ƒ |  |jd¡ |  tt|¡ |  |jd¡ d S )Nzline,1zline,2zline,3r   r   rP   ry   )r   r   r"   Zline_numÚnextr   ÚStopIteration)r   Úrr   r   r   Útest_read_linenumB  s    zTest_Csv.test_read_linenumc          	   C   s†   t dddp}t |¡}|  t|jd ¡ ddgddgg}| |¡ | d¡ x*tt |¡ƒD ]\}}|  	||| ¡ q\W W d Q R X d S )	Nzw+r   )rD   za
brd   re   zx
dr   )
r   r   r   r   r   rg   rF   Ú	enumerater   r"   )r   rJ   r   ÚrowsrR   Úrowr   r   r   Útest_roundtrip_quoteed_newlinesN  s    


z(Test_Csv.test_roundtrip_quoteed_newlinesc          	   C   s†   t dddp}tj|tjdd}ddgdd	gg}| |¡ | d
¡ x2ttj|tjddƒD ]\}}|  ||| ¡ q\W W d Q R X d S )Nzw+r   )rD   r1   )r   r%   za
brd   re   zx
dr   )	r   r   r   r5   rg   rF   r„   r   r"   )r   rJ   r   r…   rR   r†   r   r   r   Ú(test_roundtrip_escaped_unquoted_newlinesX  s    

 z1Test_Csv.test_roundtrip_escaped_unquoted_newlinesN)%r>   r?   r@   r   r   r   r.   r/   r0   r7   r8   r9   rA   rB   rC   rK   rM   rW   rZ   r]   r^   r`   rh   ri   r   Zcpython_onlyrk   ro   rq   rr   rt   ru   r|   r   rƒ   r‡   rˆ   r   r   r   r   r      s@   		
r   c               @   s\   e 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 )ÚTestDialectRegistryc             C   sæ   |   ttjd ¡ |   ttj¡ |   tjtjd ¡ |   tjtjd¡ |   ttj¡ |   tjtjd ¡ |   tjtjd¡ |   ttjd ¡ |   ttjd d ¡ |   ttjddd¡ | j ttjdd d | j ttjdd d |   ttjg ¡ d S )NZnonesuchr   )Zbadargument)r   )r   r   r   Úlist_dialectsÚget_dialectr   Úunregister_dialectÚregister_dialect)r   r   r   r   Útest_registry_badargsb  s    z)TestDialectRegistry.test_registry_badargsc             C   sv   G dd„ dt jƒ}d}t  ¡ |g }| ¡  t  ||¡ |  t j|¡ |  t  |¡j	d¡ t
t  ¡ ƒ}|  ||¡ d S )Nc               @   s   e Zd ZdZdS )z5TestDialectRegistry.test_registry.<locals>.myexceltsvú	N)r>   r?   r@   r
   r   r   r   r   Ú
myexceltsvt  s   r   r   )r   ÚexcelrŠ   Úsortr   Ú
addCleanuprŒ   r"   r‹   r
   Úsorted)r   r   ÚnameZexpected_dialectsZgot_dialectsr   r   r   Útest_registrys  s    z!TestDialectRegistry.test_registryc             C   sZ   d}t j|dd |  t j|¡ |  t  |¡jd¡ |  dddggtt  dg|¡ƒ¡ d S )NZfedcbaú;)r
   rX   ÚYÚZzX;Y;Z)	r   r   r“   rŒ   r"   r‹   r
   rl   r   )r   r•   r   r   r   Útest_register_kwargs  s
    z(TestDialectRegistry.test_register_kwargsc             C   s$   G dd„ dt jƒ}|  t j|¡ d S )Nc               @   s   e Zd ZdZdS )z?TestDialectRegistry.test_incomplete_dialect.<locals>.myexceltsvr   N)r>   r?   r@   r
   r   r   r   r   r   ‡  s   r   )r   ÚDialectr   r   )r   r   r   r   r   Útest_incomplete_dialect†  s    z+TestDialectRegistry.test_incomplete_dialectc          	   C   sv   G dd„ dt jƒ}tdƒR}| d¡ | d¡ t j||ƒ d}|  t|ƒddg¡ |  t|ƒd	d
g¡ W d Q R X d S )Nc               @   s   e Zd ZdZejZdZdS )z5TestDialectRegistry.test_space_dialect.<locals>.spaceú r1   N)r>   r?   r@   r
   r   r5   r   r%   r   r   r   r   ÚspaceŒ  s   rž   zw+zabc def
c1ccccc1 benzene
r   )r#   rp   ÚdefZc1ccccc1Zbenzene)r   r‘   r   rb   rF   r   r"   r€   )r   rž   rJ   r   r   r   r   Útest_space_dialect‹  s    


z&TestDialectRegistry.test_space_dialectc          	   O   sZ   t ddddB}tj|f|ž|Ž}| dddg¡ | d¡ |  | ¡ |¡ W d Q R X d S )	Nzw+r   zutf-8)rD   Úencodingr   rP   ry   r   )r   r   r   rE   rF   r"   rG   )r   ÚexpectedZ	writeargsZkwwriteargsrJ   r   r   r   r   Úcompare_dialect_123˜  s
    
z'TestDialectRegistry.compare_dialect_123c          	   C   s¼   G dd„ dt jƒ}G dd„ dt jƒ}G dd„ dt jƒ}G dd„ dt jƒ}t  d|¡ zV|  d	¡ |  d
|¡ | jd|ƒ d | jddd | jd|dd | jd|d W d t  d¡ X d S )Nc               @   s   e Zd ZdZdS )z5TestDialectRegistry.test_dialect_apply.<locals>.testAr   N)r>   r?   r@   r
   r   r   r   r   ÚtestA¢  s   r¤   c               @   s   e Zd ZdZdS )z5TestDialectRegistry.test_dialect_apply.<locals>.testBr!   N)r>   r?   r@   r
   r   r   r   r   ÚtestB¤  s   r¥   c               @   s   e Zd ZdZdS )z5TestDialectRegistry.test_dialect_apply.<locals>.testCú|N)r>   r?   r@   r
   r   r   r   r   ÚtestC¦  s   r§   c               @   s   e Zd ZdZdS )z7TestDialectRegistry.test_dialect_apply.<locals>.testUniu   Î›N)r>   r?   r@   r
   r   r   r   r   ÚtestUni¨  s   r¨   z1,2,3
z1	2	3
z1:2:3
)r#   z1|2|3
z1;2;3
r—   )r#   r
   u	   1Î›2Î›3
)r   r‘   r   r£   rŒ   )r   r¤   r¥   r§   r¨   r   r   r   Útest_dialect_apply¡  s    
z&TestDialectRegistry.test_dialect_applyc             C   sT   | j ttjg dd | j ttjg d d | j ttjg dd | j ttjg dd d S )Nr   )r	   )r
   éÿÿÿÿ)r   éd   )r   r   r   r   )r   r   r   r   Útest_bad_dialect¹  s    z$TestDialectRegistry.test_bad_dialectc             C   s0   x*t  ¡ D ]}t  |¡}|  ttj|¡ q
W d S )N)r   rŠ   r‹   r   r   Úcopy)r   r•   r#   r   r   r   Ú	test_copyÁ  s    
zTestDialectRegistry.test_copyc             C   sJ   xDt  ¡ D ]8}t  |¡}x(ttjd ƒD ]}|  ttj||¡ q(W q
W d S )Nr   )	r   rŠ   r‹   ÚrangeÚpickleZHIGHEST_PROTOCOLr   r   Údumps)r   r•   r#   Úprotor   r   r   Útest_pickleÆ  s    
zTestDialectRegistry.test_pickleN)r>   r?   r@   rŽ   r–   rš   rœ   r    r£   r©   r¬   r®   r³   r   r   r   r   r‰   a  s   	r‰   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestCsvBasec          	   C   sT   t ddd>}| |¡ | d¡ tj|| jd}t|ƒ}|  ||¡ W d Q R X d S )Nzw+r   )rD   r   )r#   )r   rb   rF   r   r   r#   rl   r"   )r   rm   Úexpected_resultrJ   r   rH   r   r   r   ÚreaderAssertEqualÍ  s    

zTestCsvBase.readerAssertEqualc          	   C   sP   t ddd:}tj|| jd}| |¡ | d¡ |  | ¡ |¡ W d Q R X d S )Nzw+r   )rD   )r#   r   )r   r   r   r#   rg   rF   r"   rG   )r   rm   rµ   rJ   r   r   r   r   ÚwriterAssertEqualÕ  s
    

zTestCsvBase.writerAssertEqualN)r>   r?   r@   r¶   r·   r   r   r   r   r´   Ì  s   r´   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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,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4S )5ÚTestDialectExcelr‘   c             C   s   |   ddgg¡ d S )Nrp   )r¶   )r   r   r   r   Útest_singleß  s    zTestDialectExcel.test_singlec             C   s   |   ddddddgg¡ d S )Nz	1,2,3,4,5rv   Ú2rx   Ú4rw   )r¶   )r   r   r   r   Útest_simpleâ  s    zTestDialectExcel.test_simplec             C   s   |   dg ¡ d S )Nr   )r¶   )r   r   r   r   Útest_blanklineå  s    zTestDialectExcel.test_blanklinec             C   s   |   dddgg¡ d S )Nr   r   )r¶   )r   r   r   r   Útest_empty_fieldsè  s    z"TestDialectExcel.test_empty_fieldsc             C   s   |   ddgg¡ d S )Nz""r   )r¶   )r   r   r   r   Útest_singlequotedë  s    z"TestDialectExcel.test_singlequotedc             C   s   |   dddgg¡ d S )Nz"",r   )r¶   )r   r   r   r   Útest_singlequoted_left_emptyî  s    z-TestDialectExcel.test_singlequoted_left_emptyc             C   s   |   dddgg¡ d S )Nz,""r   )r¶   )r   r   r   r   Útest_singlequoted_right_emptyñ  s    z.TestDialectExcel.test_singlequoted_right_emptyc             C   s   |   ddgg¡ d S )Nz""""r    )r¶   )r   r   r   r   Útest_single_quoted_quoteô  s    z)TestDialectExcel.test_single_quoted_quotec             C   s   |   ddgg¡ d S )Nz""""""z"")r¶   )r   r   r   r   Útest_quoted_quotes÷  s    z#TestDialectExcel.test_quoted_quotesc             C   s   |   ddgg¡ d S )Nza""b)r¶   )r   r   r   r   Útest_inline_quoteú  s    z"TestDialectExcel.test_inline_quotec             C   s   |   ddgg¡ d S )Nza"b"c)r¶   )r   r   r   r   Útest_inline_quotesý  s    z#TestDialectExcel.test_inline_quotesc             C   s   |   ddgg¡ d S )Nz"a"bZab)r¶   )r   r   r   r   Útest_quotes_and_more   s    z%TestDialectExcel.test_quotes_and_morec             C   s   |   ddgg¡ d S )Nza"b)r¶   )r   r   r   r   Útest_lone_quote  s    z TestDialectExcel.test_lone_quotec             C   s   |   ddgg¡ d S )Nz"a" "b"za "b")r¶   )r   r   r   r   Útest_quote_and_quote  s    z%TestDialectExcel.test_quote_and_quotec             C   s   |   ddgg¡ d S )Nz "a")r¶   )r   r   r   r   Útest_space_and_quote  s    z%TestDialectExcel.test_space_and_quotec          	   C   s   |   dddddddgg¡ d S )Nz#1,2,3,"I think, therefore I am",5,6rv   rº   rx   zI think, therefore I amrw   Ú6)r¶   )r   r   r   r   Útest_quoted  s    zTestDialectExcel.test_quotedc             C   s   |   ddddddgg¡ d S )NzJ1,2,3,"""I see,"" said the blind man","as he picked up his hammer and saw"rv   rº   rx   z"I see," said the blind manz"as he picked up his hammer and saw)r¶   )r   r   r   r   Útest_quoted_quote  s    z"TestDialectExcel.test_quoted_quotec             C   s*   d}|   |dddddgddd	d
gg¡ d S )NzR1,2,3,"""I see,""
said the blind man","as he picked up his
hammer and saw"
9,8,7,6rv   rº   rx   z"I see,"
said the blind manz"as he picked up his
hammer and sawÚ9Ú8Ú7rÊ   )r¶   )r   rm   r   r   r   Útest_quoted_nl  s    zTestDialectExcel.test_quoted_nlc             C   s   |   dddddgg¡ d S )Nz	12,12,1",Z12z1"r   )r¶   )r   r   r   r   Útest_dubious_quote(  s    z#TestDialectExcel.test_dubious_quotec             C   s   |   g d¡ d S )Nr   )r·   )r   r   r   r   Ú	test_null+  s    zTestDialectExcel.test_nullc             C   s   |   dggd¡ d S )Nrp   zabc
)r·   )r   r   r   r   Útest_single_writer.  s    z#TestDialectExcel.test_single_writerc             C   s   |   dddddggd¡ d S )Nr   rP   rp   ry   é   z1,2,abc,3,4
)r·   )r   r   r   r   Útest_simple_writer1  s    z#TestDialectExcel.test_simple_writerc             C   s   |   dddddggd¡ d S )Nr   rP   za"bc"ry   rÔ   z1,2,"a""bc""",3,4
)r·   )r   r   r   r   Útest_quotes4  s    zTestDialectExcel.test_quotesc             C   s   |   dggd¡ d S )Nzabc,defz"abc,def"
)r·   )r   r   r   r   Útest_quote_fieldsep7  s    z$TestDialectExcel.test_quote_fieldsepc             C   s   |   dddddggd¡ d S )Nr   rP   za
bcry   rÔ   z1,2,"a
bc",3,4
)r·   )r   r   r   r   Útest_newlines:  s    zTestDialectExcel.test_newlinesN)r>   r?   r@   r#   r¹   r¼   r½   r¾   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   rÇ   rÈ   rÉ   rË   rÌ   rÐ   rÑ   rÒ   rÓ   rÕ   rÖ   r×   rØ   r   r   r   r   r¸   Ü  s4   r¸   c               @   s   e Zd ZejZdZdS )ÚEscapedExcelr1   N)r>   r?   r@   r   r5   r   r%   r   r   r   r   rÙ   =  s   rÙ   c               @   s"   e Zd Zeƒ Zdd„ Zdd„ ZdS )ÚTestEscapedExcelc             C   s   |   dggd¡ d S )Nzabc,defz
abc\,def
)r·   )r   r   r   r   Útest_escape_fieldsepD  s    z%TestEscapedExcel.test_escape_fieldsepc             C   s   |   ddgg¡ d S )Nz
abc\,def
zabc,def)r¶   )r   r   r   r   Útest_read_escape_fieldsepG  s    z*TestEscapedExcel.test_read_escape_fieldsepN)r>   r?   r@   rÙ   r#   rÛ   rÜ   r   r   r   r   rÚ   A  s   rÚ   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestDialectUnixZunixc             C   s   |   dddggd¡ d S )Nr   zabc defrp   z"1","abc def","abc"
)r·   )r   r   r   r   rÕ   M  s    z"TestDialectUnix.test_simple_writerc             C   s   |   ddddgg¡ d S )Nz"1","abc def","abc"
rv   zabc defrp   )r¶   )r   r   r   r   Útest_simple_readerP  s    z"TestDialectUnix.test_simple_readerN)r>   r?   r@   r#   rÕ   rÞ   r   r   r   r   rÝ   J  s   rÝ   c               @   s   e Zd ZejZdZdS )ÚQuotedEscapedExcelr1   N)r>   r?   r@   r   r\   r   r%   r   r   r   r   rß   S  s   rß   c               @   s"   e Zd Zeƒ Zdd„ Zdd„ ZdS )ÚTestQuotedEscapedExcelc             C   s   |   dggd¡ d S )Nzabc,defz"abc,def"
)r·   )r   r   r   r   Útest_write_escape_fieldsepZ  s    z1TestQuotedEscapedExcel.test_write_escape_fieldsepc             C   s   |   ddgg¡ d S )Nz"abc\,def"
zabc,def)r¶   )r   r   r   r   rÜ   ]  s    z0TestQuotedEscapedExcel.test_read_escape_fieldsepN)r>   r?   r@   rß   r#   rá   rÜ   r   r   r   r   rà   W  s   rà   c               @   sœ   e 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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 )&ÚTestDictFieldsc          	   C   s„   t dddn}tj|dddgd}| ¡  | d¡ |  | ¡ d	¡ | d
ddœ¡ | d¡ | ¡  |  | ¡ d¡ W d Q R X d S )Nzw+r   )rD   Úf1Úf2Úf3)Ú
fieldnamesr   z
f1,f2,f3
rN   rp   )rã   rå   z	10,,abc
)	r   r   Ú
DictWriterÚwriteheaderrF   r"   ÚreadlinerE   rG   )r   rJ   r   r   r   r   Útest_write_simple_dictc  s    

z%TestDictFields.test_write_simple_dictc             C   sd   t ƒ }tj|dddgd}| ¡  |  | ¡ d¡ | dddd	œd
ddd	œg¡ |  | ¡ d¡ d S )Nrã   rä   rå   )ræ   z
f1,f2,f3
r   rp   Úf)rã   rä   rå   rP   é   Zxyzzf1,f2,f3
1,abc,f
2,5,xyz
)r   r   rç   rè   r"   Úgetvaluerg   )r   rJ   r   r   r   r   Útest_write_multiple_dict_rowsn  s    
z,TestDictFields.test_write_multiple_dict_rowsc             C   s   t ƒ }|  ttj|¡ d S )N)r   r   r   r   rç   )r   rJ   r   r   r   Útest_write_no_fieldsx  s    z#TestDictFields.test_write_no_fieldsc          
   C   s’   t ddd|}tj|dddgd}|  t¡}| dd	d
dœ¡ W d Q R X t|jƒ}|  d|¡ |  d|¡ |  	d|¡ |  d|¡ W d Q R X d S )Nzw+r   )rD   rã   rä   rå   )ræ   rN   Zspamrp   )Zf4rä   r   ræ   z'f4'z'f2'rv   )
r   r   rç   r   r{   rE   ÚstrÚ	exceptionÚassertInZassertNotIn)r   rJ   r   Zcxrñ   r   r   r   Ú#test_write_fields_not_in_fieldnames|  s    
z2TestDictFields.test_write_fields_not_in_fieldnamesc             C   s$   t ƒ }| jttj|ddgdd d S )Nrã   rä   Zraised)Úextrasaction)r   r   r{   r   rç   )r   rJ   r   r   r   Ú&test_typo_in_extrasaction_raises_errorˆ  s    z5TestDictFields.test_typo_in_extrasaction_raises_errorc             C   s@   t ƒ }tj|ddgdd}ddddd	œ}|  ttjj||¡ d S )
Nrã   rä   Úraise)rô   r   r   rP   ry   )Úf0rã   rä   rå   )r   r   rç   r   r{   rE   )r   rJ   r   Údictrowr   r   r   Ú)test_write_field_not_in_field_names_raise  s    z8TestDictFields.test_write_field_not_in_field_names_raisec             C   sJ   t ƒ }tj|ddgdd}ddddd	œ}tj ||¡ |  | ¡ d
¡ d S )Nrã   rä   Úignore)rô   r   r   rP   ry   )r÷   rã   rä   rå   z1,2
)r   r   rç   rE   r"   rí   )r   rJ   r   rø   r   r   r   Ú*test_write_field_not_in_field_names_ignore“  s
    z9TestDictFields.test_write_field_not_in_field_names_ignorec          	   C   sX   t dƒF}| d¡ | d¡ tj|dddgd}|  t|ƒdd	d
dœ¡ W d Q R X d S )Nzw+z	1,2,abc
r   rã   rä   rå   )ræ   rv   rº   rp   )rã   rä   rå   )r   rb   rF   r   Ú
DictReaderr"   r€   )r   rJ   r   r   r   r   Útest_read_dict_fieldsš  s    


z$TestDictFields.test_read_dict_fieldsc          	   C   sb   t dƒP}| d¡ | d¡ t |¡}|  t|ƒddddœ¡ |  |jdd	d
g¡ W d Q R X d S )Nzw+zf1,f2,f3
1,2,abc
r   rv   rº   rp   )rã   rä   rå   rã   rä   rå   )r   rb   rF   r   rü   r"   r€   ræ   )r   rJ   r   r   r   r   Útest_read_dict_no_fieldnames¢  s    



z+TestDictFields.test_read_dict_no_fieldnamesc          	   C   sp   t dƒ^}| d¡ | d¡ tj|tt |¡ƒd}|  |jdddg¡ |  t|ƒdd	d
dœ¡ W d Q R X d S )Nzw+zf1,f2,f3
1,2,abc
r   )ræ   rã   rä   rå   rv   rº   rp   )rã   rä   rå   )	r   rb   rF   r   rü   r€   r   r"   ræ   )r   rJ   r   r   r   r   Ú#test_read_dict_fieldnames_from_file¬  s    


z2TestDictFields.test_read_dict_fieldnames_from_filec          	   C   s†   dd l }tdƒl}| d¡ | d¡ t |¡}t|ƒ}x>| |g|¡D ],}|  |j	dddg¡ |  |ddd	d
œ¡ qHW W d Q R X d S )Nr   zw+zf1,f2,f3
1,2,abc
rã   rä   rå   rv   rº   rp   )rã   rä   rå   )
Ú	itertoolsr   rb   rF   r   rü   r€   Úchainr"   ræ   )r   r   rJ   r   Úfirstr†   r   r   r   Útest_read_dict_fieldnames_chainµ  s    



z.TestDictFields.test_read_dict_fieldnames_chainc          
   C   s^   t dƒL}| d¡ | d¡ tj|ddgd}|  t|ƒddd	d
ddgdœ¡ W d Q R X d S )Nzw+z1,2,abc,4,5,6
r   rã   rä   )ræ   rv   rº   rp   r»   rw   rÊ   )rã   rä   N)r   rb   rF   r   rü   r"   r€   )r   rJ   r   r   r   r   Útest_read_longÀ  s    


zTestDictFields.test_read_longc          
   C   s`   t dƒN}| d¡ | d¡ tj|ddgdd}|  t|ƒdd	d
dddgdœ¡ W d Q R X d S )Nzw+z1,2,abc,4,5,6
r   rã   rä   Ú_rest)ræ   Úrestkeyrv   rº   rp   r»   rw   rÊ   )rã   rä   r  )r   rb   rF   r   rü   r"   r€   )r   rJ   r   r   r   r   Útest_read_long_with_restÉ  s    


z'TestDictFields.test_read_long_with_restc          
   C   sl   t dƒZ}| d¡ | d¡ tj|dd}|  |jddg¡ |  t|ƒdd	d
dddgdœ¡ W d Q R X d S )Nzw+zf1,f2
1,2,abc,4,5,6
r   r  )r  rã   rä   rv   rº   rp   r»   rw   rÊ   )rã   rä   r  )r   rb   rF   r   rü   r"   ræ   r€   )r   rJ   r   r   r   r   Ú&test_read_long_with_rest_no_fieldnamesÒ  s    


z5TestDictFields.test_read_long_with_rest_no_fieldnamesc             C   s|   t dƒj}| d¡ | d¡ tj|d ¡ dd}|  t|ƒddd	d
dddœ¡ |  t|ƒddd	ddddœ¡ W d Q R X d S )Nzw+z1,2,abc,4,5,6
1,2,abc
r   z1 2 3 4 5 6ZDEFAULT)ræ   Zrestvalrv   rº   rp   r»   rw   rÊ   )rv   rº   rx   r»   rw   rÊ   )r   rb   rF   r   rü   Úsplitr"   r€   )r   rJ   r   r   r   r   Útest_read_shortÛ  s    


zTestDictFields.test_read_shortc          	   C   s<   dddg}t j|d ¡ d}|  t|ƒdddd	d
dœ¡ d S )Nz2147483648,43.0e12,17,abc,def
z147483648,43.0e2,17,abc,def
z47483648,43.0,170,abc,def
zi1 float i2 s1 s2)ræ   Z
2147483648z43.0e12Z17rp   rŸ   )Zi1ÚfloatZi2Ús1Ús2)r   rü   r	  r"   r€   )r   Zsampler   r   r   r   Útest_read_multiè  s    zTestDictFields.test_read_multic          
   C   sX   t jdddgd ¡ d}|  t|ƒddddd	d
dœ¡ |  t|ƒddddd	d
dœ¡ d S )Nz1,2,abc,4,5,6
z
z1 2 3 4 5 6)ræ   rv   rº   rp   r»   rw   rÊ   )rv   rº   rx   r»   rw   rÊ   )r   rü   r	  r"   r€   )r   r   r   r   r   Útest_read_with_blanks÷  s    z$TestDictFields.test_read_with_blanksc          
   C   s8   t jdgd ¡ dd}|  t|ƒddddd	d
dœ¡ d S )Nz1;2;abc;4;5;6
z1 2 3 4 5 6r—   )ræ   r
   rv   rº   rp   r»   rw   rÊ   )rv   rº   rx   r»   rw   rÊ   )r   rü   r	  r"   r€   )r   r   r   r   r   Útest_read_semi_sep   s
    z!TestDictFields.test_read_semi_sepN)r>   r?   r@   rê   rî   rï   ró   rõ   rù   rû   rý   rþ   rÿ   r  r  r  r  r
  r  r  r  r   r   r   r   râ   `  s$   

					râ   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestArrayWritesc          	   C   sŒ   dd l }dd„ tdƒD ƒ}|  d|¡}tdddP}tj|d	d
}| |¡ d dd„ |D ƒ¡d }| d¡ |  | 	¡ |¡ W d Q R X d S )Nr   c             S   s   g | ]}d | ‘qS )é   r   )Ú.0rR   r   r   r   ú
<listcomp>
  s    z2TestArrayWrites.test_int_write.<locals>.<listcomp>r  rR   zw+r   )rD   r‘   )r#   r   c             S   s   g | ]}t |ƒ‘qS r   )rð   )r  rR   r   r   r   r    s    z
)
Úarrayr¯   r   r   r   rE   ÚjoinrF   r"   rG   )r   r  Úcontentsr[   rJ   r   r¢   r   r   r   Útest_int_write  s    

zTestArrayWrites.test_int_writec          	   C   sŒ   dd l }dd„ tdƒD ƒ}|  d|¡}tdddP}tj|d	d
}| |¡ d dd„ |D ƒ¡d }| d¡ |  | 	¡ |¡ W d Q R X d S )Nr   c             S   s   g | ]}d | d ‘qS )r  gš™™™™™¹?r   )r  rR   r   r   r   r    s    z5TestArrayWrites.test_double_write.<locals>.<listcomp>r  rf   zw+r   )rD   r‘   )r#   r   c             S   s   g | ]}t |ƒ‘qS r   )rð   )r  rR   r   r   r   r    s    z
)
r  r¯   r   r   r   rE   r  rF   r"   rG   )r   r  r  r[   rJ   r   r¢   r   r   r   Útest_double_write  s    

z!TestArrayWrites.test_double_writec          	   C   sŒ   dd l }dd„ tdƒD ƒ}|  d|¡}tdddP}tj|d	d
}| |¡ d dd„ |D ƒ¡d }| d¡ |  | 	¡ |¡ W d Q R X d S )Nr   c             S   s   g | ]}d | d ‘qS )r  gš™™™™™¹?r   )r  rR   r   r   r   r  !  s    z4TestArrayWrites.test_float_write.<locals>.<listcomp>r  rë   zw+r   )rD   r‘   )r#   r   c             S   s   g | ]}t |ƒ‘qS r   )rð   )r  rR   r   r   r   r  &  s    z
)
r  r¯   r   r   r   rE   r  rF   r"   rG   )r   r  r  r[   rJ   r   r¢   r   r   r   Útest_float_write  s    

z TestArrayWrites.test_float_writec          	   C   sz   dd l }dd l}|  d|j¡}tdddF}tj|dd}| |¡ d |¡d	 }| d¡ |  	| 
¡ |¡ W d Q R X d S )
Nr   Úuzw+r   )rD   r‘   )r#   r   z
)r  ÚstringZascii_lettersr   r   r   rE   r  rF   r"   rG   )r   r  r  r[   rJ   r   r¢   r   r   r   Útest_char_write*  s    

zTestArrayWrites.test_char_writeN)r>   r?   r@   r  r  r  r  r   r   r   r   r    s   r  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestDialectValidityc          	   C   sð   G dd„ dt jƒ}|ƒ }|  |jt j¡ d |_|  t j|¡ d|_t j|_d|_	|ƒ }|  |jt j¡ |  |j	d¡ |  
|j¡ d|_	|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d|_	|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d S )	Nc               @   s&   e Zd ZdZdZdZdZdZej	Z
dS )z3TestDialectValidity.test_quoting.<locals>.mydialectr—   r1   FTz
N)r>   r?   r@   r
   r%   r$   r'   r   r   r5   r   r   r   r   r   Ú	mydialect7  s   r  Tr    z''z("quotechar" must be a 1-character stringrÔ   z#"quotechar" must be string, not int)r   r›   r"   r   r5   r   r   r$   r   r   Ú
assertTruerð   rñ   )r   r  rf   Úcmr   r   r   Útest_quoting6  s,    z TestDialectValidity.test_quotingc          	   C   s  G dd„ dt jƒ}|ƒ }|  |jd¡ d|_|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d|_|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d|_|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d	|_|  t j¡}|ƒ  W d Q R X |  t|jƒd
¡ d S )Nc               @   s&   e Zd ZdZdZdZdZdZej	Z
dS )z5TestDialectValidity.test_delimiter.<locals>.mydialectr—   r1   FTz
N)r>   r?   r@   r
   r%   r$   r'   r   r   r5   r   r   r   r   r   r  Y  s   r  r—   z:::z("delimiter" must be a 1-character stringr   ó   ,z%"delimiter" must be string, not bytesrÔ   z#"delimiter" must be string, not int)r   r›   r"   r
   r   r   rð   rñ   )r   r  rf   r!  r   r   r   Útest_delimiterX  s.    z"TestDialectValidity.test_delimiterc          	   C   sz   G dd„ dt jƒ}|ƒ }|  |jd¡ d|_|ƒ }|  |jd¡ d|_|  t j¡}|ƒ  W d Q R X |  t|jƒd¡ d S )Nc               @   s&   e Zd ZdZdZdZdZdZej	Z
dS )z:TestDialectValidity.test_lineterminator.<locals>.mydialectr—   r1   FTz
N)r>   r?   r@   r
   r%   r$   r'   r   r   r5   r   r   r   r   r   r  |  s   r  z
z:::rÔ   z!"lineterminator" must be a string)r   r›   r"   r   r   r   rð   rñ   )r   r  rf   r!  r   r   r   Útest_lineterminator{  s    z'TestDialectValidity.test_lineterminatorc          
   C   sz   dd„ }xldD ]d}| j |dN |  tj||d¡ |  tj||d¡ |  tj||d¡ |  tj||d¡ W d Q R X qW d S )	Nc             S   s(   G dd„ dt jƒ}t|| |ƒ |ƒ }d S )Nc               @   s   e Zd ZdS )zQTestDialectValidity.test_invalid_chars.<locals>.create_invalid.<locals>.mydialectN)r>   r?   r@   r   r   r   r   r  ’  s   r  )r   r›   r+   )Ú
field_nameÚvaluer  rf   r   r   r   Úcreate_invalid‘  s    z>TestDialectValidity.test_invalid_chars.<locals>.create_invalid)r
   r%   r   )r&  r   rp   ó   xrì   )ÚsubTestr   r   r   )r   r(  r&  r   r   r   Útest_invalid_chars  s    
z&TestDialectValidity.test_invalid_charsN)r>   r?   r@   r"  r$  r%  r+  r   r   r   r   r  5  s   "#r  c               @   sh   e 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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestSnifferzîHarry's, Arlington Heights, IL, 2/1/03, Kimi Hayes
Shark City, Glendale Heights, IL, 12/28/02, Prezence
Tommy's Place, Blue Island, IL, 12/28/02, Blue Sunday/White Crow
Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
a  'Harry''s':'Arlington Heights':'IL':'2/1/03':'Kimi Hayes'
'Shark City':'Glendale Heights':'IL':'12/28/02':'Prezence'
'Tommy''s Place':'Blue Island':'IL':'12/28/02':'Blue Sunday/White Crow'
'Stonecutters ''Seafood'' and Chop House':'Lemont':'IL':'12/19/02':'Week Back'
z+"venue","city","state","date","performers"
z¢05/05/03?05/05/03?05/05/03?05/05/03?05/05/03?05/05/03
05/05/03?05/05/03?05/05/03?05/05/03?05/05/03?05/05/03
05/05/03?05/05/03?05/05/03?05/05/03?05/05/03?05/05/03
zT2147483648;43.0e12;17;abc;def
147483648;43.0e2;17;abc;def
47483648;43.0;170;abc;def
zaaa	bbb
AAA	
BBB	
za|b|c
d|e|f
z'a'|'b'|'c'
'd'|e|f
z+"venue"+"city"+"state"+"date"+"performers"
zîHarry's+ Arlington Heights+ IL+ 2/1/03+ Kimi Hayes
Shark City+ Glendale Heights+ IL+ 12/28/02+ Prezence
Tommy's Place+ Blue Island+ IL+ 12/28/02+ Blue Sunday/White Crow
Stonecutters Seafood and Chop House+ Lemont+ IL+ 12/19/02+ Week Back
a  'Harry''s'+ Arlington Heights'+ 'IL'+ '2/1/03'+ 'Kimi Hayes'
'Shark City'+ Glendale Heights'+' IL'+ '12/28/02'+ 'Prezence'
'Tommy''s Place'+ Blue Island'+ 'IL'+ '12/28/02'+ 'Blue Sunday/White Crow'
'Stonecutters ''Seafood'' and Chop House'+ 'Lemont'+ 'IL'+ '12/19/02'+ 'Week Back'
c             C   s:   t  ¡ }|  | | j¡d¡ |  | | j| j ¡d¡ d S )NFT)r   ÚSnifferr"   Ú
has_headerÚsample1Úheader1)r   Úsnifferr   r   r   Útest_has_headerÑ  s    zTestSniffer.test_has_headerc             C   s:   t  ¡ }|  | | j¡d¡ |  | | j| j ¡d¡ d S )NFT)r   r-  r"   r.  Úsample8Úheader2)r   r1  r   r   r   Ú'test_has_header_regex_special_delimiter×  s    z3TestSniffer.test_has_header_regex_special_delimiterc          
   C   st   t  ¡ }xfdD ]^}|  |¡J | |d¡}|  |jd¡ |  |jd¡ |  |jd¡ |  |j	d¡ W d Q R X qW d S )N)z	;'123;4';z'123;4';z;'123;4'z'123;4'z,;r—   ú'F)
r   r-  r*  Úsniffr"   r
   r   ZassertIsr$   r'   )r   r1  Úheaderr#   r   r   r   Útest_guess_quote_and_delimiterÝ  s    
z*TestSniffer.test_guess_quote_and_delimiterc             C   sx   t  ¡ }| | j¡}|  |jd¡ |  |jd¡ |  |jd¡ | | j¡}|  |jd¡ |  |jd¡ |  |jd¡ d S )Nr   r    Tr!   r6  F)	r   r-  r7  r/  r"   r
   r   r'   Úsample2)r   r1  r#   r   r   r   Ú
test_sniffç  s    zTestSniffer.test_sniffc             C   s  t  ¡ }| | j¡}|  |j| j¡ |j| jdd}|  |jd¡ |j| jdd}|  |jd¡ | | j¡}|  |jd¡ | | j¡}|  |jd¡ | | j	¡}|  |jd¡ | | j
¡}|  |jd¡ |  |jd	¡ | | j¡}|  |jd
¡ | | j¡}|  |jd
¡ |  |jd	¡ d S )Nz?,)Z
delimitersú?z/,ú/r—   r   r¦   r6  ú+)r   r-  r7  Úsample3rò   r
   r"   Úsample4Úsample5Úsample6Úsample7r   r3  Úsample9)r   r1  r#   r   r   r   Útest_delimitersó  s*    zTestSniffer.test_delimitersc             C   s„   t  ¡ }| | j¡}|  |j¡ | | j¡}|  |j¡ | | j¡}|  |j¡ | | j	¡}|  |j¡ | | j
¡}|  |j¡ d S )N)r   r-  r7  r0  ZassertFalser$   r4  r:  r   r3  rD  )r   r1  r#   r   r   r   Útest_doublequote  s    zTestSniffer.test_doublequoteN)r>   r?   r@   r/  r:  r0  r?  r@  rA  rB  rC  r4  r3  rD  r2  r5  r9  r;  rE  rF  r   r   r   r   r,  Ÿ  s"   
r,  c               @   s   e Zd Zdd„ ZeZdS )ÚNULc             G   s   d S )Nr   )Úsr,   r   r   r   rb     s    z	NUL.writeN)r>   r?   r@   rb   Ú
writelinesr   r   r   r   rG    s   rG  Úgettotalrefcountzrequires sys.gettotalrefcount()c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú	TestLeaksc             C   s€   d}t  ¡ }x^tdƒD ]R}t ¡  |  tjg ¡ t  ¡ }t dg¡ t dg¡ t dg¡ || }|}qW |  |dk d¡ d S )Nr   r  za,b,c
ry   T)	ÚsysrJ  r¯   ÚgcÚcollectr"   Úgarbager   r   )r   ÚdeltaÚlastrcrR   Úrcr   r   r   Útest_create_read"  s    zTestLeaks.test_create_readc             C   s€   d}t  ¡ }tƒ }xXtdƒD ]L}t ¡  |  tjg ¡ t  ¡ }t 	|¡ t 	|¡ t 	|¡ || }|}qW |  |dk d¡ d S )Nr   r  ry   T)
rL  rJ  rG  r¯   rM  rN  r"   rO  r   r   )r   rP  rQ  rH  rR   rR  r   r   r   Útest_create_write1  s    


zTestLeaks.test_create_writec             C   s~   d}dgd }t  ¡ }xRtdƒD ]F}t ¡  |  tjg ¡ t  ¡ }t |¡}x|D ]}qRW || }|}q W |  |dk d¡ d S )Nr   za,b,c
rì   r  T)	rL  rJ  r¯   rM  rN  r"   rO  r   r   )r   rP  r…   rQ  rR   rR  Zrdrr†   r   r   r   Ú	test_readA  s    


zTestLeaks.test_readc       	      C   s”   d}dddggd }t ƒ }t ¡ }x\tdƒD ]P}t ¡  |  tjg ¡ t ¡ }t 	|¡}x|D ]}| 
|¡ q^W || }|}q,W |  |dk d¡ d S )Nr   r   rP   ry   rì   r  T)rG  rL  rJ  r¯   rM  rN  r"   rO  r   r   rE   )	r   rP  r…   rH  rQ  rR   rR  r   r†   r   r   r   Ú
test_writeQ  s    

zTestLeaks.test_writeN)r>   r?   r@   rS  rT  rU  rV  r   r   r   r   rK    s   rK  c               @   s(   e Zd ZddddgZdd„ Zdd„ Zd	S )
ÚTestUnicodeu   Martin von LÃ¶wisu   Marc AndrÃ© LemburgzGuido van Rossumu   FranÃ§ois Pinardc          	   C   s\   t ddddD}| d | j¡d ¡ | d¡ t |¡}|  t|ƒ| jg¡ W d Q R X d S )Nzw+r   zutf-8)rD   r¡   r   z
r   )	r   rb   r  ÚnamesrF   r   r   r"   rl   )r   rJ   r   r   r   r   Útest_unicode_readi  s
    

zTestUnicode.test_unicode_readc          	   C   s^   t ddddF}t |¡}| | j¡ d | j¡d }| d¡ |  | ¡ |¡ W d Q R X d S )Nzw+r   zutf-8)rD   r¡   r   z
r   )	r   r   r   rE   rX  r  rF   r"   rG   )r   rJ   r   r¢   r   r   r   Útest_unicode_writeq  s    

zTestUnicode.test_unicode_writeN)r>   r?   r@   rX  rY  rZ  r   r   r   r   rW  b  s   rW  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚKeyOrderingTestc          
   C   s   t ƒ }xrtdƒD ]f}tddddN}t ||¡}| ¡  | d¡ t |¡}t|j	ƒ}|  
||¡ | |¡ W d Q R X qW |  
t|ƒdd¡ d S )	NZabcdezw+r   zutf-8)rD   r¡   r   éx   z@Key ordering: some key permutations not collected (expected 120))Úsetr   r   r   rç   rè   rF   rü   Útupleræ   r"   ÚaddÚlen)r   Z	resultsetÚkeysZ
fileobjectZdwZdrZktr   r   r   Ú,test_ordering_for_the_dict_reader_and_writer{  s    


z<KeyOrderingTest.test_ordering_for_the_dict_reader_and_writerc          
   C   sú   t dƒ ¡ }|  tt |¡ƒtddgƒtddd ddgfgƒtdd	gƒtd
dgƒg¡ |  ttj|ddƒtddgƒtdddddgfgƒtdd	gƒtd
dgƒg¡ |d= |  ttj|ddgdƒtddgƒtddd ddgfgƒtddgƒtddgƒg¡ d S )Nz            FirstName,LastName
            Eric,Idle
            Graham,Chapman,Over1,Over2

            Under1
            John,Cleese
        )Ú	FirstNameÚEric)ÚLastNameÚIdle)rc  ÚGraham)re  ÚChapmanZOver1ZOver2)rc  ÚUnder1)re  N)rc  ÚJohn)re  ÚCleeseZ	OtherInfo)r  r   ÚfnameÚlname)ræ   )rl  rd  )rm  rf  )rl  rg  )rm  rh  )rl  ri  )rm  N)rl  rj  )rm  rk  )r   Ú
splitlinesr"   rl   r   rü   r   )r   Údatar   r   r   Útest_ordered_dict_reader‰  s*    






z(KeyOrderingTest.test_ordered_dict_readerN)r>   r?   r@   rb  rp  r   r   r   r   r[  y  s   r[  c               @   s   e Zd Zdd„ ZdS )ÚMiscTestCasec             C   s   ddh}t j| td|d d S )NÚ__doc__Ú__version__)r   Z_csv)Úextra)r   Zcheck__all__r   )r   rt  r   r   r   Útest__all__®  s    zMiscTestCase.test__all__N)r>   r?   r@   ru  r   r   r   r   rq  ­  s   rq  Ú__main__)*r­   rL  ZunittestÚior   Ztempfiler   r   rM  r°   Ztestr   r   r   Útextwrapr   Úcollectionsr   ZTestCaser   r‰   r´   r¸   r‘   rÙ   rÚ   rÝ   rß   rà   râ   r  r  r,  rG  Z
skipUnlessÚhasattrrK  rW  r[  rq  r>   Úmainr   r   r   r   Ú<module>   sH     Rka			 (.j{
A4
