U
    }g                     @   sH   d dl Z d dlmZ d dlmZmZmZ ddlmZ G dd deZ	dS )    N)Tag)	FormatterHTMLFormatterXMLFormatter   )SoupTestc                   @   s   e Zd Zdd Zdd Zdd Zejddd	d
ddddde	 dfdg
dd Z
dd Zejdedddfedddfedddfedddfgdd Zejd d!d"d#d$d%d&d'd(d)g	d*d+ Zd,d- Zd.S )/TestFormatterc                 C   s`   t  }tdd}d|d< d|d< ddg||ks6td |_g ||ksNtd	|jks\td S )
Ntag)name1b2a)r   r   )r   r    )r   r   
attributesAssertionErrorattrsindent)self	formatterr	    r   </tmp/pip-unpacked-wheel-kgiupv3k/bs4/tests/test_formatter.pytest_default_attributes   s    
z%TestFormatter.test_default_attributesc                 C   sL   G dd dt }| d}| }|j|d}|j|jks<td|ksHtd S )Nc                   @   s   e Zd Zdd ZdS )z=TestFormatter.test_sort_attributes.<locals>.UnsortedFormatterc                 s   s6   || _ t|j D ]\}}|dkr&q||fV  qd S )Nignore)called_withsortedr   items)r   r	   kvr   r   r   r   $   s
    zHTestFormatter.test_sort_attributes.<locals>.UnsortedFormatter.attributesN)__name__
__module____qualname__r   r   r   r   r   UnsortedFormatter#   s   r"   z*<p cval="1" aval="2" ignore="ignored"></p>r   z<p aval="2" cval="1"></p>)r   soupdecoder   pr   )r   r"   r$   r   decodedr   r   r   test_sort_attributes    s    
z"TestFormatter.test_sort_attributesc                 C   s   dD ]}t j| }d|jkstqtjd  }d|jks:tt jd }d|jksRttdd}d|jksjtdD ]D}| |}dD ]0}d|jjd	d
kstd|jjdd
kstqqnd S )N)htmlminimalNFhtml5T)empty_attributes_are_booleans)z<option selected></option>z<option selected=""></option>)r)   r*   xmlNs   <option selected=""></option>r)   r#   s   <option selected></option>)	r   REGISTRYr,   r   r   r   r$   optionencode)r   r
   r   markupr$   r   r   r   "test_empty_attributes_are_booleans4   s$    




z0TestFormatter.test_empty_attributes_are_booleanszindent,expect)N<a>
<b>
text
</b>
</a>
)r3   )r   r3   ) r3   )r   <a>
 <b>
  text
 </b>
</a>
)   z<a>
  <b>
    text
  </b>
</a>
)	z<a>
	<b>
		text
	</b>
</a>
)abcz#<a>
abc<b>
abcabctext
abc</b>
</a>
r6   )s   bytesr6   c                 C   s@   |  d}t|d}|j|d|ks(t|j|d|ks<td S )Nz<a><b>text</b></a>r   r#   )r$   r   prettifyr   r0   )r   r   expectr$   r   r   r   r   test_indentQ   s    

zTestFormatter.test_indentc                 C   s   t  }|jdkstd S )Nr   )r   r   r   )r   r   r   r   r   test_default_indent_valuel   s    z'TestFormatter.test_default_indent_valuezformatter,expectr   r:   z<p>
 a
</p>
r7   z<p>
  a
</p>
r8   z<p>
	a
</p>
c                 C   s$   |  d}||jj|dks td S )Nz<p>a</p>r#   )r$   r&   r;   r   )r   r   r<   r$   r   r   r   test_indent_subclassesp   s    
z$TestFormatter.test_indent_subclasseszs,expect_html,expect_html5)	foo & barzfoo &amp; barr@   )foo&zfoo&amp;rA   )
foo&&& barzfoo&amp;&amp;&amp; barrB   )x=1&y=2zx=1&amp;y=2rC   )&123z&amp;123rD   )&abcz&amp;abcrE   )
foo &0 barzfoo &amp;0 barrF   )foo &lolwat barzfoo &amp;lolwat barrG   )z&nosuchentity;&amp;nosuchentity;rH   c                 C   sL   t jd ||kstt jd ||ks0tt jd ||ksHtd S )Nr)   r+   z
html5-4.12)r   r.   
substituter   )r   sZexpect_htmlZexpect_html5r   r   r   test_entity_substitution{   s    z&TestFormatter.test_entity_substitutionc                 C   s   d}|  |}d|jjkst|jjd |j_d|jjks>td}||jjddksXt||jjddksntd	}|  |}d
|jjddkstd	|jjddkstd S )Nuf   <p>Some division signs: ÷ &divide; &#247; &#xf7;. These are made with: ÷ &amp;divide; &amp;#247;</p>uI   Some division signs: ÷ ÷ ÷ ÷. These are made with: ÷ &divide; &#247;z &#xf7;uP   Some division signs: ÷ ÷ ÷ ÷. These are made with: ÷ &divide; &#247; &#xf7;z<p>Some division signs: &divide; &divide; &divide; &divide;. These are made with: &divide; &amp;divide; &amp;#247; &amp;#xf7;</p>r)   r#   r+   z<p>a & b</p>z<p>a &amp; b</p>)r$   r&   stringr   r%   )r   r1   r$   r<   r   r   r   test_entity_round_trip   s$    

z$TestFormatter.test_entity_round_tripN)r   r    r!   r   r(   r2   pytestmarkZparametrizeobjectr=   r>   r   r   r?   rK   rM   r   r   r   r   r      sT   


r   )
rN   Zbs4.elementr   Zbs4.formatterr   r   r   r5   r   r   r   r   r   r   <module>   s   