o
    MK&h                     @   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 g d!d"d# Zd$d% Zd&S )'TestFormatterc                 C   s`   t  }tdd}d|d< d|d< ddg||ksJ d |_g ||ks'J d	|jks.J d S )
Ntag)name1b2a)r   r   )r   r    )r   r   
attributesattrsindent)self	formatterr	    r   K/var/www/html/venv/lib/python3.10/site-packages/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J d|ks$J d S )Nc                   @   s   e Zd Zdd ZdS )z=TestFormatter.test_sort_attributes.<locals>.UnsortedFormatterc                 s   s8    || _ 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   p)r   r!   r#   r   decodedr   r   r   test_sort_attributes    s   
z"TestFormatter.test_sort_attributesc                 C   s   dD ]}t j| }d|ju sJ qtjd  }d|ju sJ t jd }d|ju s)J tdd}d|ju s5J dD ]"}| |}dD ]}d|jjd	d
ksMJ d|jjdd
ksXJ q@q7d 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#   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>
)r2   )r   r2   ) r2   )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>
r5   )s   bytesr5   c                 C   s@   |  d}t|d}|j|d|ksJ |j|d|ksJ d S )Nz<a><b>text</b></a>r   r"   )r#   r   prettifyr/   )r   r   expectr#   r   r   r   r   test_indentQ   s   

zTestFormatter.test_indentc                 C   s   t  }|jdks
J d S )Nr   )r   r   )r   r   r   r   r   test_default_indent_valuel   s   z'TestFormatter.test_default_indent_valuezformatter,expectr   r9   z<p>
 a
</p>
r6   z<p>
  a
</p>
r7   z<p>
	a
</p>
c                 C   s$   |  d}||jj|dksJ d S )Nz<p>a</p>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;r@   )
foo&&& barzfoo&amp;&amp;&amp; barrA   )x=1&y=2zx=1&amp;y=2rB   )&123z&amp;123rC   )&abcz&amp;abcrD   )
foo &0 barzfoo &amp;0 barrE   )foo &lolwat barzfoo &amp;lolwat barrF   )z&nosuchentity;&amp;nosuchentity;rG   c                 C   sL   t jd ||ksJ t jd ||ksJ t jd ||ks$J d S )Nr(   r*   z
html5-4.12)r   r-   
substitute)r   sexpect_htmlexpect_html5r   r   r   test_entity_substitution{   s   z&TestFormatter.test_entity_substitutionc                 C   s   d}|  |}d|jjksJ |jjd |j_d|jjksJ d}||jjddks,J ||jjddks7J d	}|  |}d
|jjddksIJ d	|jjddksTJ 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   r0   r#   r;   r   r   r   test_entity_round_trip   s    

z$TestFormatter.test_entity_round_tripN)r   r   r    r   r'   r1   pytestmarkparametrizeobjectr<   r=   r   r   r>   rL   rN   r   r   r   r   r      sD    


r   )
rO   bs4.elementr   bs4.formatterr   r   r   r4   r   r   r   r   r   r   <module>   s
    