U
    c                     @  s  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
  mZ d dlmZmZ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)ej*+d?e,e-d@dAdBdC e-d@dAD gdDdE Z.dFZ/dGdH Z0dIdJ Z1dKdL Z2dMdN Z3dOdP Z4dQdR Z5dSdT Z6dUdV Z7dWdX Z8dYdZ Z9d[d\ Z:d]d^ Z;d_d` Z<dadb Z=dcdd Z>dedf Z?dgdh Z@didj ZAdkdl ZBdmZCdndo ZDe"d.dpdq ZEe"d.ej*+drdsdtdugdvdw ZFdxdy ZGe"d.dzd{ ZHd|d} ZId~d ZJeKd.dd ZLdd ZMdZNe"d.dd ZOe"d.dd ZPe"d.dd ZQe"d.dd ZRe"d.ej*+dddgdd ZSe"d.dd ZTe"d.dd ZUe"d.dd ZVdd ZWe"d.dd ZXe"d.dd ZYe"d.dd ZZdFZ[dd Z\dd Z]dd Z^dd Z_ej*j`e"de"d.dd ZadS )    )annotations)BytesIOStringION)NA	DataFrameIndex)_compression_to_extension)
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-g7fro6k3/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/   r9   r   r   r   test_file_output_bytes_read   s    rA   c                 C  s>   | dddd}t ||d}|j|d}t|}|tks:td S )Nr(   r)   r*   r+   r,   )r
   r2   r   r7   r8   r:   r&   r;   r<   r?   r   r   r   test_str_output   s
    rC   c              	   C  s0   d}t jtdd tj|| d W 5 Q R X d S )Nz/my/fake/path/output.xmlz6Cannot save file into a non-existent directory: .*pathmatchr,   )pytestraisesOSErrorgeom_dfr2   r&   r=   r   r   r   test_wrong_file_path   s    rK   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
   r0   r1   r2   r3   r4   r5   r6   r   r8   r:   r&   expectedr;   r<   r=   r>   r?   r   r   r   test_index_false   s    rQ   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)rM   	root_nameZrow_namer&   r   r.   rN   rO   r   r   r    test_index_false_rename_row_root  s        rS   offset_index
      c                 C  s   g | ]}t |qS r   )str).0ir   r   r   
<listcomp>.  s     rZ   c                 C  s<   d}t  }t||_|jd| d}t|}||ks8tdS )z
    Tests that the output does not contain the `<index>` field when the index of the
    input Dataframe has an offset.

    This is a regression test for issue #42458.
    aD  <?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <shape>square</shape>
    <degrees>360</degrees>
    <sides>4.0</sides>
  </row>
  <row>
    <shape>circle</shape>
    <degrees>360</degrees>
    <sides/>
  </row>
  <row>
    <shape>triangle</shape>
    <degrees>180</degrees>
    <sides>3.0</sides>
  </row>
</data>FrL   N)rI   copyr   rM   r2   r   r8   )r&   rT   rP   Zoffset_geom_dfr?   r   r   r   (test_index_false_with_offset_input_index-  s    
r\   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,   rI   r2   r   na_expectedr8   r&   r?   r   r   r   test_na_elem_outputn  s    r`   c                 C  s&   t jd| d}t|}|tks"td S )N na_repr&   r]   r_   r   r   r   test_na_empty_str_elem_optionu  s    rd   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.0rb   rI   r2   r   r8   r&   rP   r?   r   r   r   test_na_empty_elem_option|  s    rg   c                 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&   re   rf   r   r   r   test_attrs_cols_nan_output  s    rj   c                 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>rM   r   r   r   r   zhttp://example.xom)ri   
namespacesprefixr&   re   rf   r   r   r   test_attrs_cols_prefix  s    
rm   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 columnrD   r   degreer   rh   rF   rG   KeyErrorrI   r2   r,   r   r   r   test_attrs_unknown_column  s    rr   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_colsrD   "shape", "degree", "sides"rh   rF   rG   	TypeErrorrI   r2   r,   r   r   r   test_attrs_wrong_type  s    rv   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   )rM   	elem_colsr&   re   r&   Zelems_cols_expectedr?   r   r   r   test_elems_cols_nan_output  s      ry   c              	   C  s2   t jtdd tjdddg| d W 5 Q R X d S )Nrn   rD   r   ro   r   rw   r&   rp   r,   r   r   r   test_elems_unknown_column  s    r{   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_colsrD   rs   rz   rt   r,   r   r   r   test_elems_wrong_type  s    r|   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   )rM   rw   ri   r&   re   rx   r   r   r   test_elems_and_attrs_cols  s    r}   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rM   valuesZaggfuncZmargins   r,   )	planet_dfpivot_tableroundr2   r   r8   r&   rP   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   r~   r   r   Tr   r   rh   )
r   r   r   r2   listreset_indexcolumnsr   r   r8   r   r   r   r   test_hierarchical_attrs_columnsF  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   r~   r   r   r   r,   )r   groupbyaggr   r2   r   r8   r&   rP   r   r?   r   r   r   test_multi_indexd  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   r~   r   r   r   rh   )r   r   r   r   r2   r   r   r   r   r   r8   r   r   r   r   test_multi_index_attrs_cols  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>ra   http://example.com)rk   r&   re   rf   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   rk   rl   r&   re   rf   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 namespacesrD   ra   r   r   r   rp   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)ra   r   r   r   z7xmlns:doc="http://other.org" xmlns="http://example.com"z7xmlns="http://example.com" xmlns:doc="http://other.org"rI   r2   r   r   r8   rf   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
   headr2   r   encoding_expectedr8   rB   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)rM   r   r&   r
   r0   r1   r2   )r:   r;   r<   r=   r   r   r   test_correct_encoding_fileM  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   )r:   r&   r   r;   r<   r=   r   r   r   test_wrong_encoding_option_lxmlV  s    r   c              	   C  s,   t jtdd tjd| d W 5 Q R X d S )Nzunknown encodingrD   zuft-8r   )rF   rG   LookupErrorrI   r2   r,   r   r   r   test_misspelled_encoding`  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)rI   r2   r8   )rP   r?   r   r   r   !test_xml_declaration_pretty_printh  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   rf   r   r   r   test_no_pretty_print_with_decl  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   )rI   r2   r   r8   rf   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.rD   )rF   rG   ImportErrorrI   r2   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.rD   Zbs4r,   rF   rG   
ValueErrorrI   r2   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)r3   rI   r2   xsl_expectedr8   )r:   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   )r3   r   r4   r   rI   r2   r   r8   )r:   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   )r3   r4   rI   r2   r   r8   )r:   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.xslt!Start tag expected, '<' not foundrD   r   )	
lxml.etreer   osr=   joinrF   rG   rI   r2   r   r   r   r   r   test_stylesheet_wrong_path  s    r   valra       c              	   C  sF   ddl m} ddddg}tj||d tj| d W 5 Q R X d S )	Nr   r   |zDocument is emptyr   zNone \(line 0\)rD   r   )r   r   r   rF   rG   rI   r2   )r   r   msgr   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 mismatchrD   r   )r   r   rF   rG   rI   r2   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 compilerD   r   )r   r   rF   rG   rI   r2   )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 URIrD   r-   r   )r   r   rF   rG   r0   r1   rI   r2   )r   r   r=   r   r   r   test_incorrect_xsl_applyW  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 installedrD   r%   )r&   r   r   )r   r   r   r   test_stylesheet_with_etreel  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>
)lineterminatorr   )rI   Zto_csvr6   r2   r8   )r   Zout_csvout_xmlr   r   r   test_style_to_csv~  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)rc   r   )rI   Z	to_stringr2   r8   )r   Zout_strr   r   r   r   test_style_to_string  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   )rI   Zto_jsonr2   r8   )r   Zout_jsonr   r   r   r   test_style_to_json  s    %r   c              
   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   )r0   r1   rI   r2   r	   handler4   r   geom_xmlr6   r8   )r&   compression_onlyr=   
handle_objr?   r   r   r   test_compression_output  s    
r   c              
   C  st   dt |  }tj|d:}tj|| |d t|d|d}|j }W 5 Q R X W 5 Q R X t|}t	|
 ksptd S )Nzxml.)r;   r   r   r   )r   r0   r1   rI   r2   r	   r   r4   r   r   r6   r8   )r&   r   Zcompfiler=   r   r?   r   r   r   test_filename_and_suffix_comp  s    r   c                 C  s<   d}t dtgi| }|j|d}t| |ks8td S )Nzd<?xml version='1.0' encoding='utf-8'?>
<data>
  <row>
    <index>0</index>
    <a/>
  </row>
</data>ar,   )r   r   Zastyper2   r   r6   r8   )Zany_numeric_ea_dtyper&   rP   Zdfresultr   r   r   test_ea_dtypes&  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 typerD   Z7zr   )rF   rG   r   r0   r1   rI   r2   rJ   r   r   r   test_unsuported_compression4  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 DeniedrD   T)Zanonzpandas-testzs3://pandas-test/geom.xmlzip)r   r&   )r   rF   rG   PermissionErrorZS3FileSystemZlsrI   r2   )r&   Zs3_resourcer   fsr   r   r   test_s3_permission_output=  s
    
r   )b
__future__r   r(   r   r   r   ZnumpynprF   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   r   r   Zpandas._testingZ_testingr0   Z pandas.tests.io.test_compressionr   Zpandas.io.commonr	   Zpandas.io.xmlr
   nanrI   r   r7   r   Zfixturer#   r    Z
skip_if_nor&   r@   rA   rC   rK   rQ   rS   markZparametrizer   ranger\   r^   r`   rd   rg   rj   rm   rr   rv   ry   r{   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   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   r   Z
single_cpur   r   r   r   r   <module>   s  &
-


(*  
&! /'! +$


	








!
/	