U
    f/e;                     @  sH  d dl mZ d dlmZmZ d dlZd dlZd dlZd dl	m
Z
 d dlm  mZ d dlmZ d dlmZ d dlmZ d dlmZ edd	d
gdddgdejdgdZeddddddddgddddddddgddddddddgdddd d!d"d#d$gd%Zd&Zd'd( Zejd)d*gd+d,d- Zejejd.e d.d/d0gd+d1d2 Z!d3d4 Z"d5d6 Z#d7d8 Z$d9d: Z%d;d< Z&d=d> Z'd?Z(d@dA Z)dBdC Z*dDdE Z+ej,j-e
 dFdGdHdI Z.ej,j-e
 dJdGdKdL Z/dMdN Z0dOdP Z1dQdR Z2dSdT Z3dUdV Z4dWdX Z5dYdZ Z6ej,j-e
 dJdGd[d\ Z7d]d^ Z8ej,j-e
 dJdGd_d` Z9dadb Z:dcdd Z;dedf Z<dgdh Z=diZ>djdk Z?e d.dldm Z@e d.ej,Adndodpdqgdrds ZBdtdu ZCe d.dvdw ZDdxdy ZEdzd{ ZFeGd.d|d} ZHd~d ZIdZJe d.dd ZKe d.dd ZLe d.dd ZMe d.dd ZNe d.ej,Adddgdd ZOe d.dd ZPe d.dd ZQe d.dd ZRdd ZSe d.dd ZTe d.dd ZUe d.dd ZVd?ZWej,Adddddgdd ZXej,Adddddgej,Adddddgdd ZYdd ZZej[e de d.dd Z\dS )    )annotations)BytesIOStringION)PY38)	DataFrame)
get_handle)read_xmlZsquareZcircleZtriangleih           )shapedegreessidesZMercuryZVenusZEarthZMarsZJupiterZSaturnZUranusZNeptuneZterrestrialz	gas giantz	ice giantinnerouterg`|x ?gcAJx@g2r@gl?gh|@g	@gd]FU@g	hY@)Zplanettypelocationmassac  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <category>cooking</category>
    <title>Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.0</price>
  </row>
  <row>
    <index>1</index>
    <category>children</category>
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </row>
  <row>
    <index>2</index>
    <category>web</category>
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </row>
</data>c                 C  s   | d k	r|  dd} | S )Nz%<?xml version="1.0" encoding="utf-8"?z%<?xml version='1.0' encoding='utf-8'?)replace)doc r   C/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/io/xml/test_to_xml.pyequalize_decl   s    r   rbr)paramsc                 C  s   | j S Nparamrequestr   r   r   mode   s    r!   lxml)Zmarksetreec                 C  s   | j S r   r   r   r   r   r   parser   s    r$   c              
   C  s~   | dddd}t ||d}tdP}|j||d t|d}| d }W 5 Q R X t|}|t	kspt
W 5 Q R X d S 	Niodataxml	books.xmlr$   test.xmlr   utf-8r   tmensure_cleanto_xmlopenreaddecodestripr   from_file_expectedAssertionErrordatapathr$   filenamedf_filepathfoutputr   r   r   test_file_output_str_read   s    r>   c              
   C  s~   | dddd}t ||d}tdP}|j||d t|d}| d }W 5 Q R X t|}|t	kspt
W 5 Q R X d S r%   r-   r7   r   r   r   test_file_output_bytes_read   s    r?   c                 C  s>   | dddd}t ||d}|j|d}t|}|tks:td S )Nr&   r'   r(   r)   r*   )r   r0   r   r5   r6   r8   r$   r9   r:   r=   r   r   r   test_str_output   s
    rA   c              	   C  s,   t jtdd tjd| d W 5 Q R X d S )Nu5   No such file or directory|没有那个文件或目录matchz/my/fake/path/output.xmlr*   )pytestraisesFileNotFoundErrorgeom_dfr0   r*   r   r   r   test_wrong_file_path   s
     rH   c              
   C  s   d}| dddd}t ||d}tdR}|j|d|d	 t|d
}| d }W 5 Q R X t|}||ksvt	W 5 Q R X d S )Na$  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <category>cooking</category>
    <title>Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.0</price>
  </row>
  <row>
    <category>children</category>
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </row>
  <row>
    <category>web</category>
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </row>
</data>r&   r'   r(   r)   r*   r+   F)indexr$   r   r,   
r   r.   r/   r0   r1   r2   r3   r4   r   r6   r8   r$   expectedr9   r:   r;   r<   r=   r   r   r   test_index_false   s    rM   c              
   C  s   d}| dddd}t ||d}tdV}|j|dd	d
|d t|d}| d }W 5 Q R X t|}||kszt	W 5 Q R X d S )Na,  <?xml version='1.0' encoding='utf-8'?>
<books>
  <book>
    <category>cooking</category>
    <title>Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.0</price>
  </book>
  <book>
    <category>children</category>
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book>
    <category>web</category>
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</books>r&   r'   r(   r)   r*   r+   FZbooksZbook)rI   	root_nameZrow_namer$   r   r,   rJ   rK   r   r   r    test_index_false_rename_row_root   s        rO   a  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>c                 C  s$   t j|d}t|}|tks td S )Nr*   rG   r0   r   na_expectedr6   r8   r$   r=   r   r   r   test_na_elem_output@  s    rS   c                 C  s&   t jd|d}t|}|tks"td S )N na_repr$   rP   rR   r   r   r   test_na_empty_str_elem_optionG  s    rW   c                 C  s*   d}t jd|d}t|}||ks&td S )Na  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides>0.0</sides>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>z0.0rU   rG   r0   r   r6   r8   r$   rL   r=   r   r   r   test_na_empty_elem_optionN  s    rZ   z'etree alpha ordered attributes < py 3.8)reasonc                 C  s0   d}t jdddg|d}t|}||ks,td S )Nz<?xml version='1.0' encoding='utf-8'?>
<data>
  <row index="0" shape="square" degrees="360" sides="4.0"/>
  <row index="1" shape="circle" degrees="360"/>
  <row index="2" shape="triangle" degrees="180" sides="3.0"/>
</data>r   r   r   	attr_colsr$   rX   rY   r   r   r   test_attrs_cols_nan_outputo  s    r^   z&etree alpha ordered attributes < py3.8c                 C  s:   d}t jddddgddid|d}t|}||ks6td S )	Na>  <?xml version='1.0' encoding='utf-8'?>
<doc:data xmlns:doc="http://example.xom">
  <doc:row doc:index="0" doc:shape="square" doc:degrees="360" doc:sides="4.0"/>
  <doc:row doc:index="1" doc:shape="circle" doc:degrees="360"/>
  <doc:row doc:index="2" doc:shape="triangle" doc:degrees="180" doc:sides="3.0"/>
</doc:data>rI   r   r   r   r   zhttp://example.xom)r]   
namespacesprefixr$   rX   rY   r   r   r   test_attrs_cols_prefix  s    
ra   c              	   C  s2   t jtdd tjdddg| d W 5 Q R X d S )Nno valid columnrB   r   degreer   r\   rD   rE   KeyErrorrG   r0   r*   r   r   r   test_attrs_unknown_column  s    rf   c              	   C  s,   t jtdd tjd| d W 5 Q R X d S )Nz!is not a valid type for attr_colsrB   "shape", "degree", "sides"r\   rD   rE   	TypeErrorrG   r0   r*   r   r   r   test_attrs_wrong_type  s    rj   c                 C  s2   d}t jddddg|d}t|}||ks.td S )NaD  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <degrees>360</degrees>
    <sides>4.0</sides>
    <shape>square</shape>
  </row>
  <row>
    <degrees>360</degrees>
    <sides/>
    <shape>circle</shape>
  </row>
  <row>
    <degrees>180</degrees>
    <sides>3.0</sides>
    <shape>triangle</shape>
  </row>
</data>Fr   r   r   )rI   	elem_colsr$   rX   r8   r$   Zelems_cols_expectedr=   r   r   r   test_elems_cols_nan_output  s      rm   c              	   C  s2   t jtdd tjdddg| d W 5 Q R X d S )Nrb   rB   r   rc   r   rk   r$   rd   r*   r   r   r   test_elems_unknown_column  s    ro   c              	   C  s,   t jtdd tjd| d W 5 Q R X d S )Nz!is not a valid type for elem_colsrB   rg   rn   rh   r*   r   r   r   test_elems_wrong_type  s    rp   c                 C  s4   d}t jdddgdg|d}t|}||ks0td S )Na#  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row shape="square">
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row shape="circle">
    <degrees>360</degrees>
    <sides/>
  </row>
  <row shape="triangle">
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>Fr   r   r   )rI   rk   r]   r$   rX   rl   r   r   r   test_elems_and_attrs_cols  s    rq   c                 C  sJ   d}t jddgddddgdd	d
}|j|d}t|}||ksFtd S )Na  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <location>inner</location>
    <type>terrestrial</type>
    <count_mass>4</count_mass>
    <sum_mass>11.81</sum_mass>
    <mean_mass>2.95</mean_mass>
  </row>
  <row>
    <location>outer</location>
    <type>gas giant</type>
    <count_mass>2</count_mass>
    <sum_mass>2466.5</sum_mass>
    <mean_mass>1233.25</mean_mass>
  </row>
  <row>
    <location>outer</location>
    <type>ice giant</type>
    <count_mass>2</count_mass>
    <sum_mass>189.23</sum_mass>
    <mean_mass>94.61</mean_mass>
  </row>
  <row>
    <location>All</location>
    <type/>
    <count_mass>8</count_mass>
    <sum_mass>2667.54</sum_mass>
    <mean_mass>333.44</mean_mass>
  </row>
</data>r   r   r   countsummeanTrI   valuesZaggfuncZmargins   r*   )	planet_dfpivot_tableroundr0   r   r6   r8   r$   rL   Zpvtr=   r   r   r   test_hierarchical_columns  s    !r|   c                 C  sX   d}t jddgddddgdd	d
}|jt| jj|d}t|}||ksTt	d S )Na  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row location="inner" type="terrestrial" count_mass="4" sum_mass="11.81" mean_mass="2.95"/>
  <row location="outer" type="gas giant" count_mass="2" sum_mass="2466.5" mean_mass="1233.25"/>
  <row location="outer" type="ice giant" count_mass="2" sum_mass="189.23" mean_mass="94.61"/>
  <row location="All" type="" count_mass="8" sum_mass="2667.54" mean_mass="333.44"/>
</data>r   r   r   rr   rs   rt   Tru   rw   r\   )
rx   ry   rz   r0   listreset_indexcolumnsrv   r   r6   r{   r   r   r   test_hierarchical_attrs_columns   s    r   c                 C  sL   d}t ddgd dddgd}|j|d	}t|}||ksHtd S )
Na  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <location>inner</location>
    <type>terrestrial</type>
    <count>4</count>
    <sum>11.81</sum>
    <mean>2.95</mean>
  </row>
  <row>
    <location>outer</location>
    <type>gas giant</type>
    <count>2</count>
    <sum>2466.5</sum>
    <mean>1233.25</mean>
  </row>
  <row>
    <location>outer</location>
    <type>ice giant</type>
    <count>2</count>
    <sum>189.23</sum>
    <mean>94.61</mean>
  </row>
</data>r   r   r   rr   rs   rt   rw   r*   )rx   groupbyaggrz   r0   r   r6   r8   r$   rL   r   r=   r   r   r   test_multi_indexB  s    r   c                 C  sZ   d}t ddgd dddgd}|jt| jj|d	}t	|}||ksVt
d S )
Na$  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row location="inner" type="terrestrial" count="4" sum="11.81" mean="2.95"/>
  <row location="outer" type="gas giant" count="2" sum="2466.5" mean="1233.25"/>
  <row location="outer" type="ice giant" count="2" sum="189.23" mean="94.61"/>
</data>r   r   r   rr   rs   rt   rw   r\   )rx   r   r   rz   r0   r}   r~   r   rv   r   r6   r   r   r   r   test_multi_index_attrs_colsi  s    r   c                 C  s.   d}t jddi| d}t|}||ks*td S )Na  <?xml version='1.0' encoding='utf-8'?>
<data xmlns="http://example.com">
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>rT   http://example.com)r_   r$   rX   r$   rL   r=   r   r   r   test_default_namespace  s    r   c                 C  s0   d}t jddid| d}t|}||ks,td S )Na  <?xml version='1.0' encoding='utf-8'?>
<doc:data xmlns:doc="http://example.com">
  <doc:row>
    <doc:index>0</doc:index>
    <doc:shape>square</doc:shape>
    <doc:degrees>360</doc:degrees>
    <doc:sides>4.0</doc:sides>
  </doc:row>
  <doc:row>
    <doc:index>1</doc:index>
    <doc:shape>circle</doc:shape>
    <doc:degrees>360</doc:degrees>
    <doc:sides/>
  </doc:row>
  <doc:row>
    <doc:index>2</doc:index>
    <doc:shape>triangle</doc:shape>
    <doc:degrees>180</doc:degrees>
    <doc:sides>3.0</doc:sides>
  </doc:row>
</doc:data>r   r   r_   r`   r$   rX   r   r   r   r   test_namespace_prefix  s      r   c              	   C  s2   t jtdd tjddid| d W 5 Q R X d S )Nz!doc is not included in namespacesrB   rT   r   r   r   rd   r*   r   r   r   test_missing_prefix_in_nmsp  s      r   c                 C  sF   d}t jdddd| d}t|}|d k	r6|dd}||ksBtd S )	Na7  <?xml version='1.0' encoding='utf-8'?>
<doc:data xmlns="http://example.com" xmlns:doc="http://other.org">
  <doc:row>
    <doc:index>0</doc:index>
    <doc:shape>square</doc:shape>
    <doc:degrees>360</doc:degrees>
    <doc:sides>4.0</doc:sides>
  </doc:row>
  <doc:row>
    <doc:index>1</doc:index>
    <doc:shape>circle</doc:shape>
    <doc:degrees>360</doc:degrees>
    <doc:sides/>
  </doc:row>
  <doc:row>
    <doc:index>2</doc:index>
    <doc:shape>triangle</doc:shape>
    <doc:degrees>180</doc:degrees>
    <doc:sides>3.0</doc:sides>
  </doc:row>
</doc:data>r   zhttp://other.org)rT   r   r   r   z7xmlns:doc="http://other.org" xmlns="http://example.com"z7xmlns="http://example.com" xmlns:doc="http://other.org"rG   r0   r   r   r6   r   r   r   r   !test_namespace_prefix_and_default  s    r   u  <?xml version='1.0' encoding='ISO-8859-1'?>
<data>
  <row>
    <index>0</index>
    <rank>1</rank>
    <malename>José</malename>
    <femalename>Sofía</femalename>
  </row>
  <row>
    <index>1</index>
    <rank>2</rank>
    <malename>Luis</malename>
    <femalename>Valentina</femalename>
  </row>
  <row>
    <index>2</index>
    <rank>3</rank>
    <malename>Carlos</malename>
    <femalename>Isabella</femalename>
  </row>
  <row>
    <index>3</index>
    <rank>4</rank>
    <malename>Juan</malename>
    <femalename>Camila</femalename>
  </row>
  <row>
    <index>4</index>
    <rank>5</rank>
    <malename>Jorge</malename>
    <femalename>Valeria</femalename>
  </row>
</data>c                 C  sT   | dddd}t ||ddd}|jd|d}|d k	rD|d	d
}|tksPtd S )Nr&   r'   r(   baby_names.xml
ISO-8859-1)r$   encoding   r   r$   z*<?xml version="1.0" encoding="ISO-8859-1"?z*<?xml version='1.0' encoding='ISO-8859-1'?)r   headr0   r   encoding_expectedr6   r@   r   r   r   test_encoding_option_str  s    r   c              	   C  sH   | dddd}t |ddd}td}|j|d	ddd
 W 5 Q R X d S Nr&   r'   r(   r   r   r"   r   r+   F)rI   r   r$   r   r.   r/   r0   )r8   r9   r:   r;   r   r   r   test_correct_encoding_file/  s    r   r   zUTF-8zUTF-16r   c              	   C  sH   | dddd}t |ddd}td}|j|d	||d
 W 5 Q R X d S r   r   )r8   r$   r   r9   r:   r;   r   r   r   test_wrong_encoding_option_lxml8  s    r   c              	   C  s,   t jtdd tjd| d W 5 Q R X d S )Nzunknown encodingrB   zuft-8r   )rD   rE   LookupErrorrG   r0   r*   r   r   r   test_misspelled_encodingB  s    r   c                  C  s    d} t jdd}|| kstd S )Na\  <data>
  <row>
    <index>0</index>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <index>1</index>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <index>2</index>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>F)xml_declaration)rG   r0   r6   )rL   r=   r   r   r   !test_xml_declaration_pretty_printJ  s    r   c                 C  s>   d}t jd| d}t|}|d k	r.|dd}||ks:td S )Na4  <?xml version='1.0' encoding='utf-8'?>
<data><row><index>0</index><shape>square</shape><degrees>360</degrees><sides>4.0</sides></row><row><index>1</index><shape>circle</shape><degrees>360</degrees><sides/></row><row><index>2</index><shape>triangle</shape><degrees>180</degrees><sides>3.0</sides></row></data>F)pretty_printr$    />/>r   r   r   r   r   test_no_pretty_print_with_declg  s    
r   c                 C  s8   d}t jdd| d}|d k	r(|dd}||ks4td S )Na  <data><row><index>0</index><shape>square</shape><degrees>360</degrees><sides>4.0</sides></row><row><index>1</index><shape>circle</shape><degrees>360</degrees><sides/></row><row><index>2</index><shape>triangle</shape><degrees>180</degrees><sides>3.0</sides></row></data>F)r   r   r$   r   r   )rG   r0   r   r6   r   r   r   r   test_no_pretty_print_no_decl|  s    	r   c                	   C  s&   t jtdd t  W 5 Q R X d S )Nz7lxml not found, please install or use the etree parser.rB   )rD   rE   ImportErrorrG   r0   r   r   r   r   test_default_parser_no_lxml  s
     r   c                	   C  s*   t jtdd tjdd W 5 Q R X d S )Nz,Values for parser can only be lxml or etree.rB   Zbs4r*   rD   rE   
ValueErrorrG   r0   r   r   r   r   test_unknown_parser  s
     r   a%  <?xml version="1.0" encoding="utf-8"?>
<data>
  <row>
    <field field="index">0</field>
    <field field="shape">square</field>
    <field field="degrees">360</field>
    <field field="sides">4.0</field>
  </row>
  <row>
    <field field="index">1</field>
    <field field="shape">circle</field>
    <field field="degrees">360</field>
    <field field="sides"/>
  </row>
  <row>
    <field field="index">2</field>
    <field field="shape">triangle</field>
    <field field="degrees">180</field>
    <field field="sides">3.0</field>
  </row>
</data>c              	   C  s<   | dddd}t ||}tj|dtks.tW 5 Q R X d S Nr&   r'   r(   row_field_output.xsl
stylesheet)r1   rG   r0   xsl_expectedr6   )r8   r!   xslr<   r   r   r   test_stylesheet_file_like  s    r   c              	   C  sb   | dddd}t ||(}|dkr0t| }nt| }W 5 Q R X tj|d}|tks^td S )Nr&   r'   r(   r   r   r   )r1   r   r2   r   rG   r0   r   r6   )r8   r!   Zxsl_pathr<   xsl_objr=   r   r   r   test_stylesheet_io  s    r   c              	   C  sH   | dddd}t ||}| }W 5 Q R X tj|d}|tksDtd S r   )r1   r2   rG   r0   r   r6   )r8   r!   r   r<   r   r=   r   r   r   test_stylesheet_buffered_reader  s
    r   c              	   C  sF   ddl m} tjddd}tj|dd tj|d W 5 Q R X d S )	Nr   XMLSyntaxErrorr'   r(   zrow_field_output.xsltz!Start tag expected, '<' not foundrB   r   )	
lxml.etreer   osr;   joinrD   rE   rG   r0   )r8   r   r   r   r   r   test_stylesheet_wrong_path  s    r   valrT       c              	   C  s6   ddl m} tj|dd tj| d W 5 Q R X d S )Nr   r   z3Document is empty|Start tag expected, '<' not foundrB   r   r   r   rD   rE   rG   r0   )r   r   r   r   r   test_empty_string_stylesheet  s     r   c               	   C  s:   ddl m}  d}tj| dd tj|d W 5 Q R X d S )Nr   r   aR  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="utf-8" indent="yes" >
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="row/*">
        <field>
            <xsl:attribute name="field">
                <xsl:value-of select="name()"/>
            </xsl:attribute>
            <xsl:value-of select="text()"/>
        </field>
    </xsl:template>
</xsl:stylesheet>zOpening and ending tag mismatchrB   r   r   )r   r   r   r   r   test_incorrect_xsl_syntax  s    r   c               	   C  s:   ddl m}  d}tj| dd tj|d W 5 Q R X d S )Nr   )XSLTParseErroraT  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="utf-8" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node(*)">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="row/*">
        <field>
            <xsl:attribute name="field">
                <xsl:value-of select="name()"/>
            </xsl:attribute>
            <xsl:value-of select="text()"/>
        </field>
    </xsl:template>
</xsl:stylesheet>zfailed to compilerB   r   )r   r   rD   rE   rG   r0   )r   r   r   r   r   test_incorrect_xsl_eval  s    r   c              
   C  sR   ddl m} d}tj|dd* td}tj||d W 5 Q R X W 5 Q R X d S )Nr   )XSLTApplyErrorag  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="utf-8" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:copy-of select="document('non_existent.xml')/*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>zCannot resolve URIrB   r+   r   )r   r   rD   rE   r.   r/   rG   r0   )r$   r   r   r;   r   r   r   test_incorrect_xsl_apply2  s
    r   c              	   C  s0   d}t jtdd tjd|d W 5 Q R X d S )NaI  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="utf-8" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node(*)">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>z*To use stylesheet, you need lxml installedrB   r#   )r$   r   r   )r8   r   r   r   r   test_stylesheet_with_etreeG  s     r   c                  C  s<   d} t jdd}|d k	r | }t j| d}||ks8td S )NaQ  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:param name="delim">,</xsl:param>
    <xsl:template match="/data">
        <xsl:text>,shape,degrees,sides&#xa;</xsl:text>
        <xsl:apply-templates select="row"/>
    </xsl:template>

    <xsl:template match="row">
        <xsl:value-of select="concat(index, $delim, shape, $delim,
                                     degrees, $delim, sides)"/>
         <xsl:text>&#xa;</xsl:text>
    </xsl:template>
</xsl:stylesheet>
)Zline_terminatorr   )rG   Zto_csvr4   r0   r6   )r   Zout_csvout_xmlr   r   r   test_style_to_csvY  s    r   c                  C  s*   d} t  }t jd| d}||ks&td S )Na  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:param name="delim"><xsl:text>               </xsl:text></xsl:param>
    <xsl:template match="/data">
        <xsl:text>      shape  degrees  sides&#xa;</xsl:text>
        <xsl:apply-templates select="row"/>
    </xsl:template>

    <xsl:template match="row">
        <xsl:value-of select="concat(index, ' ',
                                     substring($delim, 1, string-length('triangle')
                                               - string-length(shape) + 1),
                                     shape,
                                     substring($delim, 1, string-length(name(degrees))
                                               - string-length(degrees) + 2),
                                     degrees,
                                     substring($delim, 1, string-length(name(sides))
                                               - string-length(sides) + 2),
                                     sides)"/>
         <xsl:text>&#xa;</xsl:text>
    </xsl:template>
</xsl:stylesheet>NaN)rV   r   )rG   Z	to_stringr0   r6   )r   Zout_strr   r   r   r   test_style_to_stringv  s    r   c                  C  s(   d} t  }t j| d}||ks$td S )Na]  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:param name="quot">"</xsl:param>

    <xsl:template match="/data">
        <xsl:text>{"shape":{</xsl:text>
        <xsl:apply-templates select="descendant::row/shape"/>
        <xsl:text>},"degrees":{</xsl:text>
        <xsl:apply-templates select="descendant::row/degrees"/>
        <xsl:text>},"sides":{</xsl:text>
        <xsl:apply-templates select="descendant::row/sides"/>
        <xsl:text>}}</xsl:text>
    </xsl:template>

    <xsl:template match="shape|degrees|sides">
        <xsl:variable name="val">
            <xsl:if test = ".=''">
                <xsl:value-of select="'null'"/>
            </xsl:if>
            <xsl:if test = "number(text()) = text()">
                <xsl:value-of select="text()"/>
            </xsl:if>
            <xsl:if test = "number(text()) != text()">
                <xsl:value-of select="concat($quot, text(), $quot)"/>
            </xsl:if>
        </xsl:variable>
        <xsl:value-of select="concat($quot, preceding-sibling::index,
                                     $quot,':', $val)"/>
        <xsl:if test="preceding-sibling::index != //row[last()]/index">
            <xsl:text>,</xsl:text>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>r   )rG   Zto_jsonr0   r6   )r   Zout_jsonr   r   r   r   test_style_to_json  s    %r   compbz2gzipxzzipc              
   C  sd   t  :}tj|| |d t|d|d}|j }W 5 Q R X W 5 Q R X t|}t|	 ks`t
d S )Nr$   compressionr   r   r.   r/   rG   r0   r   handler2   r   geom_xmlr4   r6   )r$   r   r;   
handle_objr=   r   r   r   test_compression_output  s    
r   compfilezxml.bz2zxml.gzzxml.xzzxml.zipc              
   C  sh   t j|d:}tj|| |d t|d|d}|j }W 5 Q R X W 5 Q R X t|}t|	 ksdt
d S )N)r9   r   r   r   r   )r$   r   r   r;   r   r=   r   r   r   test_filename_and_suffix_comp  s    r   c              
   C  sB   t jtdd* t }tj||dd W 5 Q R X W 5 Q R X d S )NzUnrecognized compression typerB   Z7zr   )rD   rE   r   r.   r/   rG   r0   )r8   r$   r;   r   r   r   test_unsuported_compression  s    
r   s3fsc              	   C  sL   dd l }tjtdd, |jdd}|d tjdd| d	 W 5 Q R X d S )
Nr   zAccess DeniedrB   T)Zanonzpandas-testzs3://pandas-test/geom.xmlr   )r   r$   )r   rD   rE   PermissionErrorZS3FileSystemZlsrG   r0   )r$   r   fsr   r   r   test_s3_permission_output  s
    
r   )]
__future__r   r&   r   r   r   ZnumpynprD   Zpandas.compatr   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   Zpandas._testingZ_testingr.   Zpandas.io.commonr   Zpandas.io.xmlr   nanrG   rx   r5   r   Zfixturer!   r   Z
skip_if_nor$   r>   r?   rA   rH   rM   rO   rQ   rS   rW   rZ   markZskipifr^   ra   rf   rj   rm   ro   rp   rq   r|   r   r   r   r   r   r   r   r   r   r   Zparametrizer   r   r   r   r   Zskip_if_installedr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   networkr   r   r   r   r   <module>   s4  &
-



(,!

 /
'
! +$


	



	




!
/
	