o
    i>                     @   s   d dl mZ d dlZeeZd dlZd dlmZm	Z	 d dl
mZ d dlmZmZmZmZmZmZ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edkrje  dS dS )    )print_functionN)etreehtml)E)ComplexModelXmlAttributeUnicodeArrayIntegerSelfReferenceXmlData)XmlCloth)FakeContext)BytesIOc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestModelClothc                 C   4   G dd dt }|jjd u sJ |jjd usJ d S )Nc                   @      e Zd ZG dd dejZdS )z1TestModelCloth.test_root_html.<locals>.SomeObjectc                   @      e Zd ZedZdS )z<TestModelCloth.test_root_html.<locals>.SomeObject.Attributesz%<html><body spyne-root></body></html>N__name__
__module____qualname__r   
fromstring
html_cloth r   r   ^/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/test/protocol/test_cloth.py
Attributes(       r   Nr   r   r   r   r   r   r   r   r   
SomeObject'       r   r   r   _html_cloth_html_root_clothselfr   r   r   r   test_root_html&      zTestModelCloth.test_root_htmlc                 C   4   G dd dt }|jjd usJ |jjd u sJ d S )Nc                   @   r   )z,TestModelCloth.test_html.<locals>.SomeObjectc                   @   r   )z7TestModelCloth.test_html.<locals>.SomeObject.Attributesz(<html><body spyne-id="za"></body></html>Nr   r   r   r   r   r   0   r   r   Nr   r   r   r   r   r   /   r    r   r!   r$   r   r   r   	test_html.   r'   zTestModelCloth.test_htmlc                 C   r   )Nc                   @   r   )z0TestModelCloth.test_root_xml.<locals>.SomeObjectc                   @   r   )z;TestModelCloth.test_root_xml.<locals>.SomeObject.Attributesz(<html><body spyne-root=""></body></html>N)r   r   r   r   r   	xml_clothr   r   r   r   r   8   r   r   Nr   r   r   r   r   r   7   r    r   r   r   
_xml_cloth_xml_root_clothr$   r   r   r   test_root_xml6   r'   zTestModelCloth.test_root_xmlc                 C   r(   )Nc                   @   r   )z+TestModelCloth.test_xml.<locals>.SomeObjectc                   @   r   )z6TestModelCloth.test_xml.<locals>.SomeObject.Attributesz#<html><body foo="za"></body></html>N)r   r   r   r   r   r*   r   r   r   r   r   @   r   r   Nr   r   r   r   r   r   ?   r    r   r+   r$   r   r   r   test_xml>   r'   zTestModelCloth.test_xmlN)r   r   r   r&   r)   r.   r/   r   r   r   r   r   %   s
    r   c                   @   s6   e Zd Zdd ZdddZdd Zdd	 Zd
d ZdS )TestXmlClothToParentc                 C   "   t  | _t | _tjtjd d S N)levelr   ctxr   streamloggingbasicConfigDEBUGr%   r   r   r   setUpH      zTestXmlClothToParent.setUpNc                 C   sz   |d u r|j }t| j}t j| j||||jd W d    n1 s%w   Y  t| j	 }t
tj|dd |S )N)nameTpretty_print)	__class__r   xmlfiler6   r   subserializer5   r   r   getvalueprinttostring)r%   instclsparenteltr   r   r   _runM   s   zTestXmlClothToParent._runc                 C   s"   d}|  |t}|j|ksJ d S )Npunk.)rJ   r   text)r%   vrI   r   r   r   test_simpleZ   s   z TestXmlClothToParent.test_simplec                 C   s:   G dd dt }d}| ||d}|d j|ksJ d S )Nc                   @      e Zd ZeZdS )z?TestXmlClothToParent.test_complex_primitive.<locals>.SomeObjectNr   r   r   r   sr   r   r   r   r   a       r   rK   rQ   r   r   rJ   rL   r%   r   rM   rI   r   r   r   test_complex_primitive`   s   z+TestXmlClothToParent.test_complex_primitivec                 C   sv   G dd dt }G dd d|}d}d}| |||d}t|dks%J |d	 jt|ks0J |d
 j|ks9J d S )Nc                   @   rO   )z8TestXmlClothToParent.test_complex_inheritance.<locals>.ANr   r   r   r
   ir   r   r   r   Aj   rR   rY   c                   @   rO   )z8TestXmlClothToParent.test_complex_inheritance.<locals>.BNrP   r   r   r   r   Bm   rR   rZ   *   rK   )rX   rQ      r      )r   rJ   lenrL   str)r%   rY   rZ   rX   rQ   rI   r   r   r   test_complex_inheritancei   s   z-TestXmlClothToParent.test_complex_inheritance)N)r   r   r   r;   rJ   rN   rV   r`   r   r   r   r   r0   G   s    
	r0   c                   @   s   e Zd Zdd Zd6d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d4d5 ZdS )7TestXmlClothc                 C   r1   r2   r4   r:   r   r   r   r;      r<   zTestXmlCloth.setUpNc                 C   s   |j }|d u r|d usJ td| }n|d u sJ t| j}t|dd| j||| W d    n1 s;w   Y  t| j	 }t
tj|dd |S )Nz<a><b spyne_id="%s"></b></a>clothspyne_Tr>   )r@   r   r   rA   r6   r   set_identifier_prefixrB   r5   rC   rD   rE   )r%   rF   spidrc   rG   rH   rI   r   r   r   rJ      s   zTestXmlCloth._runc                 C   s>   G dd dt }d}| j||ddd}|d j|ksJ d S )Nc                   @   rO   )z2TestXmlCloth.test_simple_value.<locals>.SomeObjectNrP   r   r   r   r   r      rR   r   rK   rS   rQ   rf   r   rT   rU   r   r   r   test_simple_value   s   zTestXmlCloth.test_simple_valuec                 C   s4   G dd dt }| j| dd}t|dksJ d S )Nc                   @   rO   )z2TestXmlCloth.test_simple_empty.<locals>.SomeObjectNrP   r   r   r   r   r      rR   r   rQ   rg   r   )r   rJ   r^   r%   r   rI   r   r   r   test_simple_empty   s   zTestXmlCloth.test_simple_emptyc                 C   s6   G dd dt }| j| dd}|d jd u sJ d S )Nc                   @      e Zd ZeddZdS )z?TestXmlCloth._test_simple_empty_nonoptional.<locals>.SomeObjectr]   
min_occursNrP   r   r   r   r   r      r   r   rQ   rg   r   rT   ri   r   r   r   _test_simple_empty_nonoptional   s   z+TestXmlCloth._test_simple_empty_nonoptionalc                 C   s@   G dd dt }td}| j| |d}|d jd u sJ d S )Nc                   @   rk   )zETestXmlCloth._test_simple_empty_nonoptional_clear.<locals>.SomeObjectr]   rl   NrP   r   r   r   r   r      r   r   z#<a><b spyne_id="s">oi punk!</b></a>rb   r   r   r   r   rJ   rL   r%   r   rc   rI   r   r   r   $_test_simple_empty_nonoptional_clear   s   
z1TestXmlCloth._test_simple_empty_nonoptional_clearc                 C   @   G dd dt }td}| j|dd|d}|jdksJ d S )Nc                   @      e Zd ZeeZdS )z2TestXmlCloth.test_xml_data_tag.<locals>.SomeObjectNr   r   r   r   r   dr   r   r   r   r          r   z!<a><spyne_data spyne_id="d"/></a>dataru   rb   ro   rp   r   r   r   test_xml_data_tag      
zTestXmlCloth.test_xml_data_tagc                 C   rr   )Nc                   @   rs   )z3TestXmlCloth.test_xml_data_attr.<locals>.SomeObjectNrt   r   r   r   r   r      rv   r   <a spyne_data="d"></a>rw   rx   rb   ro   rp   r   r   r   test_xml_data_attr   rz   zTestXmlCloth.test_xml_data_attrc                 C   rr   )Nc                   @   rO   )z@TestXmlCloth.test_xml_data_attr_undesignated.<locals>.SomeObjectN)r   r   r   r   ru   r   r   r   r   r      rR   r   r{   rw   rx   rb   ro   rp   r   r   r   test_xml_data_attr_undesignated   rz   z,TestXmlCloth.test_xml_data_attr_undesignatedc                 C   H   d}G dd dt }td}| j||d|d}|jd |ks"J d S )NrK   c                   @      e Zd ZeeddZdS )z?TestXmlCloth.test_simple_value_xmlattribute.<locals>.SomeObjectr]   rl   Nr   r   r   r   r   rQ   r   r   r   r   r          r   <a></a>rS   rb   rQ   r   r   r   rJ   attribr%   rM   r   rc   rI   r   r   r   test_simple_value_xmlattribute   
   
z+TestXmlCloth.test_simple_value_xmlattributec                 C   r~   )NrK   c                   @      e Zd ZeedddZdS )zGTestXmlCloth.test_simple_value_xmlattribute_subname.<locals>.SomeObjectr]   foorm   sub_nameNr   r   r   r   r   r          r   r   rS   rb   r   r   r   r   r   r   &test_simple_value_xmlattribute_subname   r   z3TestXmlCloth.test_simple_value_xmlattribute_subnamec                 C   s^   d}G dd dt }td}| j||d|d}|jd |ks"J |d jd |ks-J d S )	NrK   c                   @   r   )zMTestXmlCloth.test_simple_value_xmlattribute_non_immediate.<locals>.SomeObjectr]   r   r   Nr   r   r   r   r   r      r   r   <a><b spyne_attr="s"/></a>rS   rb   r   r   r   r   r   r   r   ,test_simple_value_xmlattribute_non_immediate   s   
z9TestXmlCloth.test_simple_value_xmlattribute_non_immediatec                 C   sZ   d}G dd dt }td}| j||d|d}d|jvs J |d jd |ks+J d S )	NrK   c                   @   s   e Zd ZedddZdS )z\TestXmlCloth.test_simple_value_xmlattribute_non_immediate_non_designated.<locals>.SomeObjectr]   r   r   NrP   r   r   r   r   r     s    r   r   rS   rb   r   r   r   r   r   r   r   ;test_simple_value_xmlattribute_non_immediate_non_designated   s   
zHTestXmlCloth.test_simple_value_xmlattribute_non_immediate_non_designatedc                    s   t jt jt jt jdddddddd}G dd dt G  fdd	d	t}| j|d
 ddd|d}|ddgks?J t|dtddgksNJ d S )NrX   spyne_idc )spyne_tagbagc                   @   rO   )z(TestXmlCloth.test_non_tagbag.<locals>.C2NrW   r   r   r   r   C2  rR   r   c                       s   e Zd ZeZ ZdS )z(TestXmlCloth.test_non_tagbag.<locals>.C1N)r   r   r   r
   rX   r   r   r   r   r   C1      r   r]   r\   )rX   )rX   r   rb   z
//b/text()1z
//d/text()2)	r   abr   ru   r   rJ   xpathset)r%   rc   r   rI   r   r   r   test_non_tagbag
  s"   	"zTestXmlCloth.test_non_tagbagc                 C   sh   t d}G dd dt}ttjtjdddd}| j||d|d}|d	d
d |D ks2J d S )N   c                   @   rs   )z+TestXmlCloth.test_array.<locals>.SomeObjectNr   r   r   r	   r
   rQ   r   r   r   r   r   '  rv   r   integerr   rQ   rS   rb   z
//c/text()c                 S   s   g | ]}t |qS r   )r_   ).0rX   r   r   r   
<listcomp>3  s    z+TestXmlCloth.test_array.<locals>.<listcomp>)ranger   r   r   r   r   rJ   r   r   r   r   r   
test_array$  s   
 zTestXmlCloth.test_arrayc                 C   sD   G dd dt }d}t|}| j| |d}|dg ks J d S )Nc                   @   rs   )z1TestXmlCloth.test_array_empty.<locals>.SomeObjectNr   r   r   r   r   r   6  rv   r   5<a><b spyne_id="s"><c spyne_id="integer"></c></b></a>rb   //cr   r   r   rJ   r   r%   r   elt_strrc   rI   r   r   r   test_array_empty5  s
   
zTestXmlCloth.test_array_emptyc                 C   sN   G dd dt }d}t|}| j| |d}|d|d d gks%J d S )Nc                   @   r   )z>TestXmlCloth._test_array_empty_nonoptional.<locals>.SomeObjectr]   rl   Nr   r   r   r   r   r   B  r   r   r   rb   r   r   r   r   r   r   r   _test_array_empty_nonoptionalA  s
   
 z*TestXmlCloth._test_array_empty_nonoptionalc              
   C   sP  G dd dt }|ddd}tt ttjddt tt tj	ddt
 }| j||d}ttj|d	d
 |d jdksGJ |d jdksPJ |d d jdks[J |d d jdksfJ |d d jdksqJ |d jdkszJ |d d jdksJ |d d jdksJ |d d jdksJ |d d jdksJ d S )Nc                   @      e Zd ZeZeZdS )z5TestXmlCloth.test_simple_two_tags.<locals>.SomeObjectNr   r   r   r   rQ   r
   rX   r   r   r   r   r   M  r   r   rQ      rQ   rX   r   rX   rb   Tr>   r   b1r]   b2c1c2r\   eg1g25g3)r   r   r   r   r   r   r   r   r   r   r   rJ   rD   r   rE   tagrL   r%   r   rM   rc   rI   r   r   r   test_simple_two_tagsL  s4   

z!TestXmlCloth.test_simple_two_tagsc                 C   s  G dd dt }|dd}tt tt t tjddt t	 }| j
||d}ttj|dd |d	 jd
ksAJ |d jdksJJ |d d	 jdksUJ |d d jdks`J |d d jdkskJ |d d jdksvJ |d d jdksJ |d d jdksJ d S )Nc                   @   rO   )z3TestXmlCloth.test_sibling_order.<locals>.SomeObjectNrP   r   r   r   r   r   o  rR   r   rQ   rS   r   rb   Tr>   r   r   r]   r   c0r   r\   r   r   c3   c4)r   r   r   r   r   r   r   r   r   r   rJ   rD   r   rE   r   rL   r   r   r   r   test_sibling_ordern  s,   

zTestXmlCloth.test_sibling_orderc                 C   s   G dd dt }|dd}tdtjdd}ttj|dd | j||d	}ttj|dd |jd
ks7J |j	dks>J |d jdksGJ |d j	dksPJ d S )Nc                   @   rO   )z1TestXmlCloth.test_parent_text.<locals>.SomeObjectNrP   r   r   r   r   r     rR   r   rQ   rS   text 0r   Tr>   rb   r   r   r   )
r   r   r   r   rD   r   rE   rJ   r   rL   r   r   r   r   test_parent_text  s   

zTestXmlCloth.test_parent_textc                 C   s   G dd dt }|dd}ttdtjdd}ttj|dd | j||d	}ttj|dd |d
 j	dks<J |d
 j
dksEJ |d
 d
 j	dksPJ |d
 d
 j
dks[J d S )Nc                   @   rO   )z.TestXmlCloth.test_anc_text.<locals>.SomeObjectNrP   r   r   r   r   r     rR   r   rQ   rS   text 1r   Tr>   rb   r   r   r   )r   r   r   r   r   rD   r   rE   rJ   r   rL   r   r   r   r   test_anc_text  s   

zTestXmlCloth.test_anc_textc              	   C   s   G dd dt }|dd}ttt dtjdd}ttj|dd | j	||d	}ttj|dd |d
 j
dks?J |d
 d
 j
dksJJ |d
 d
 jdksUJ |d
 d jdks`J d S )Nc                   @   rO   )z3TestXmlCloth.test_prevsibl_tail.<locals>.SomeObjectNrP   r   r   r   r   r     rR   r   rQ   rS   text 2r   Tr>   rb   r   r   r   r]   )r   r   r   r   r   r   rD   r   rE   rJ   r   tailrL   r   r   r   r   test_prevsibl_tail  s    

zTestXmlCloth.test_prevsibl_tailc                 C   s   G dd dt }|dd}ttjddd}ttj|dd | j||d	}ttj|dd |d
 jdks9J |d
 j	dksBJ |d
 j
dksKJ d S )Nc                   @   rO   )z8TestXmlCloth.test_sibling_tail_close.<locals>.SomeObjectNrP   r   r   r   r   r     rR   r   rQ   rS   r   text 3Tr>   rb   r   b0)r   r   r   r   rD   r   rE   rJ   r   rL   r   r   r   r   r   test_sibling_tail_close  s   

z$TestXmlCloth.test_sibling_tail_closec                 C   s   G dd dt }|ddd}ttjdddtjdd}ttj|d	d
 | j||d}ttj|d	d
 |d j	dks?J |d j
dksHJ |d jdksQJ d S )Nc                   @   r   )z@TestXmlCloth.test_sibling_tail_close_sibling.<locals>.SomeObjectNr   r   r   r   r   r     r   r   rQ   r   r   r   r   rX   Tr>   rb   r   r   )r   r   r   r   r   rD   r   rE   rJ   r   rL   r   r   r   r   r   test_sibling_tail_close_sibling  s   

z,TestXmlCloth.test_sibling_tail_close_siblingc                 C   s   G dd dt }|ddd}tt dttjdddt d	d
ttjddd}tt	j
|dd | j||d}tt	j
|dd |dd jdksRJ |dd jd	ks^J |dd jdksjJ d S )Nc                   @   r   )z<TestXmlCloth.test_sibling_tail_close_anc.<locals>.SomeObjectNr   r   r   r   r   r     r   r   rQ   r   r   r   r   r   r   r   rX   text 4Tr>   rb   /a/b1/c0r   z/a/b1/c1z/a/b2/c1)r   r   r   r   r   r   r   r   rD   r   rE   rJ   r   r   r   r   r   r   test_sibling_tail_close_anc  s.   

z(TestXmlCloth.test_sibling_tail_close_ancc                 C   s.  G dd dt }|dd|dddd}tt d	ttjd
ddtjtjd
dtjddddddt	tj
ddd}ttj|dd | j||d}ttj|dd |dd jt|jksfJ |dd jt|jjksvJ |dd jt|jjksJ |dd jt|jksJ d S )Nc                   @   s   e Zd ZeZeZeZdS )z6TestXmlCloth.test_nested_conflicts.<locals>.SomeObjectN)	r   r   r   r   rQ   r
   rX   r   r   r   r   r   r   r     s    r   xr]   yr\   r   )rQ   rX   r   r   rQ   r   r   rX   r   r   r   r   Tr>   rb   r   r   z/a/b1/c1/d0z/a/b1/c1/d1z/a/b2/c2)r   r   r   r   r   r   r   d0d1r   r   rD   r   rE   rJ   r   rL   r_   rQ   r   rX   r   r   r   r   test_nested_conflicts  s8   




  "z"TestXmlCloth.test_nested_conflicts)NN)r   r   r   r;   rJ   rh   rj   rn   rq   ry   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ra      s6    
			



"ra   __main__)
__future__r   r7   	getLoggerr   loggerunittestlxmlr   r   lxml.builderr   spyner   r   r   r	   r
   r   r   spyne.protocol.clothr   
spyne.testr   spyne.util.sixr   TestCaser   r0   ra   mainr   r   r   r   <module>   s&   
$";   :