
    Pik                     z   d Z ddl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 ej                            d          Z ej        ddg          d	             Zej        d
             Zej                            dg d          d             Zej                            dddg          d             Zd Zd Zej                            dddg          d             Zej                            dg d          d             Zd Zej                            dg d          d             Zd Zd Zd ZdS ) zZ
Tests compressed data parsing functionality for all
of the parsers defined in parsers.py
    N)Path)	DataFramez=ignore:Passing a BlockManager to DataFrame:DeprecationWarningTF)paramsc                     | j         S )N)param)requests    {/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/tests/io/parser/test_compression.pybufferr
      s
    =    c                     | }t          |d          5 }|                                }d d d            n# 1 swxY w Y   |                    |          }|||fS )Nrb)openreadread_csv)all_parserscsv1parserfdataexpecteds         r	   parser_and_datar      s    F	dD		 Qvvxx              t$$H4!!s   488compression)zipinferzip2c                    |\  }}}| dz  }t          j        |d          5 }|                    d|           d d d            n# 1 swxY w Y   |dk    r@t          |d          5 }|                    |d          }	d d d            n# 1 swxY w Y   n|                    ||          }	t          j        |	|           d S )	Ntest_file.zipwmode	test_filer   r   r   r   )zipfileZipFilewritestrr   r   tmassert_frame_equal)
tmp_pathr   r   r   r   r   pathtmpr   results
             r	   test_zipr,   %   sH   ,FD(o%D	C	(	(	( (C[$'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( f$ 	;__QE_::F	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; ;??&(+++++s#   AA	A	&B

BBr   r   c                 N   |\  }}}| dz  }ddg}t          j        |d          5 }|D ]}	|                    |	|           	 d d d            n# 1 swxY w Y   t          j        t
          d          5  |                    ||           d d d            d S # 1 swxY w Y   d S )	Nzcombined_zip.zipr!   second_filer   r   zMultiple filesmatchr"   )r#   r$   r%   pytestraises
ValueErrorr   )
r(   r   r   r   r   r   r)   inner_file_namesr*   	file_names
             r	   test_zip_error_multiple_filesr6   6   sH   ,FD(((D#]3	C	(	(	( *C) 	* 	*ILLD))))	** * * * * * * * * * * * * * * 
z)9	:	:	: 7 7+6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s#   AAA5BB!Bc                    |\  }}}| dz  }t          j        |d          5  	 d d d            n# 1 swxY w Y   t          j        t          d          5  |                    |d           d d d            d S # 1 swxY w Y   d S )Nr   r   r   z
Zero filesr/   r   r"   )r#   r$   r1   r2   r3   r   )r(   r   r   _r)   s        r	   test_zip_error_no_filesr9   E   s   "LFAqo%D	C	(	(	(                 
z	6	6	6 1 1%0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   044A;;A?A?c                 4   |\  }}}| dz  }|                                  t          |d          5 }t          j        t          j        d          5  |                    |d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nzinvalid_file.zipr   zFile is not a zip filer/   r   r"   )touchr   r1   r2   r#   
BadZipFiler   )r(   r   r   r8   r)   r   s         r	   test_zip_error_invalid_zipr=   P   s   "LFAq((DJJLLL	dD		 2Q]7-5MNNN 	2 	2OOA5O111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s5   !BA5)B5A9	9B<A9	=BBBfilenamez
test.{ext}c                    |\  }}}	|}
||
         }||n|                     |          }|r5|r3|                    t          j                            d                     |r| |z  n| dz  }t          j        |
||           |rdn|
}|r@t          |d          5 }|                    ||          }d d d            n# 1 swxY w Y   n|                    ||          }t          j	        ||	           d S )N)extz9Cannot deduce compression from buffer of compressed data.)reasonr!   r   r   r"   )
formatapplymarkerr1   markxfailr&   write_to_compressedr   r   r'   )r(   r   r   compression_onlyr
   r>   compression_to_extensionr   r   r   compress_typer@   r)   r   r   r+   s                   r	   test_compressionrJ   Z   s~    -FD($M
"=
1C#+xxS1I1IH 
F 
KR   	
 	
 	
 #+F8h;0FD=$555%8''=K @$ 	A__QK_@@F	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A ;??&(+++++s   C  CCr@   )Ngzbz2c                    | }ddd} |j         |fi |}d|d<   |r8t          |d          5 } |j         |fi |}d d d            n# 1 swxY w Y   n|rd|z   nd	} |j         ||z   fi |}t          j        ||           d S )
Nr   T)	index_colparse_datesr   r   utf-8encoding. )r   r   r&   r'   )	r   r   r
   r@   r   kwargsr   r   r+   s	            r	   test_infer_compressionrV   ~   s
    FT22Fvt..v..H#F= 7$))) 	2Q$V_Q11&11F	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 &cCiiB 66v66&(+++++s   A		AAc                    | }|                     |          }t          j                            |d| d          }|                    ||dd          }t          ddgddgd	          }t          j        ||           d S )
Nutfz_ex_small.zipr   	)rR   r   sep	Venezuela   Hugo Chávez FríasHenrique Capriles R.CountryTwitter)rB   osr)   joinr   r   r&   r'   )	r   csv_dir_path	utf_valueencoding_fmtr   rR   r)   r+   r   s	            r	   test_compression_utf_encodingrf      s    F""9--H7<<&DI&D&D&DEED__TH%T_RRF#[1-/EF	
 	
 H &(+++++r   invalid_compression)sfarkbz3zipperc                     | }d|i}d| }t          j        t          |          5   |j        di | d d d            d S # 1 swxY w Y   d S )Nr   zUnrecognized compression type: r/   r   )r   )r1   r2   r3   r   )r   rg   r   compress_kwargsmsgs        r	   test_invalid_compressionrn      s    F$&9:O
A,?
A
AC	z	-	-	- < <;;?;;;< < < < < < < < < < < < < < < < < <s   AA	Ac                     | }t           j                            |d          }|                    |          }t	          |j                  dgk    sJ d S )Nztar_csv.tar.gza)ra   r)   rb   r   listcolumns)r   rc   r   r)   dfs        r	   test_compression_tar_archivert      sQ    F7<<&677D			B
u$$$$$$r   c                 P   |}t          dddgi          }| dz  }| dz  }|                    |d           t          |                              t          |                              d	          d	           t          j        |                    |d 
          |           d S )Nrp   r      ztest.csvztest.csv.zipFindexrP   rQ   r"   )r   to_csvr   
write_text	read_textr&   r'   r   )r(   r   r   rs   path_csvpath_zips         r	   !test_ignore_compression_extensionr~      s    F	C!Q=	!	!B*$H.(HIIheI$$$NNX  ' 22W     &//(/EErJJJJJr   c                    |}t          ddgddgd          }| dz  }|                    |d           t          j        |                    |          |           t          j        |d          5 }|                    |                    |                                d	                   d
          }t          j        ||           d d d            d S # 1 swxY w Y   d S )Nr[   r\   r]   r^   ztest.tar.gzFrw   zr:gzr   r   r"   )	r   ry   r&   r'   r   tarfiler   extractfilegetnames)r(   r   r   r   tar_pathtarr+   s          r	   test_writes_tar_gzr      s4   F#[1-/EF	
 	
 D -'HKKK&&& &//(33T::: 
h	'	' ,3OOCLLNN1-..G ! 
 
 	fd+++	, , , , , , , , , , , , , , , , , ,s   2ACCC)__doc__ra   pathlibr   r   r#   r1   pandasr   pandas._testing_testingr&   rD   filterwarnings
pytestmarkfixturer
   r   parametrizer,   r6   r9   r=   rJ   rV   rf   rn   rt   r~   r    r   r	   <module>r      sA   
 
			                     [''C 

 e}%%%  &% " " " (@(@(@AA, , BA,  (8997 7 :971 1 12 2 2 dL%9:: ,  , ;: ,F  3 3 344, , 54,$, , ," .0J0J0JKK< < LK<% % %K K K, , , , ,r   