Current File : //usr/lib/python3.6/site-packages/bs4/__pycache__/testing.cpython-36.pyc
3

"6]�~�@s�dZdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZddlmZeZGdd	�d	ej�ZGd
d�de�ZGdd
�d
e�ZGdd�de�Zdd�ZdS)zHelper classes for tests.ZMIT�N)�TestCase)�
BeautifulSoup)�CharsetMetaAttributeValue�Comment�ContentMetaAttributeValue�Doctype�SoupStrainer)�HTMLParserTreeBuilderc@s:eZdZedd��Zdd�Zdd�Zddd	�Zd
d�ZdS)
�SoupTestcCst�S)N)�default_builder)�self�r
�/usr/lib/python3.6/testing.pyrszSoupTest.default_buildercKs"|jd|j�}t|fd|i|��S)z*Build a Beautiful Soup object from markup.�builder)�poprr)r�markup�kwargsrr
r
r�soup sz
SoupTest.soupcCs|jj|�S)z[Turn an HTML fragment into a document.

        The details depend on the builder.
        )rZtest_fragment_to_document)rrr
r
r�document_for%szSoupTest.document_forNcCs8|j}t||d�}|dkr|}|j|j�|j|��dS)N)r)rr�assertEqual�decoder)rZto_parseZcompare_parsed_tor�objr
r
r�assertSoupEquals,s
zSoupTest.assertSoupEqualscCs<d}x2|jD](}|r0|j||j�|j||j�|}qWdS)zyEnsure that next_element and previous_element are properly
        set for all descendants of the given element.
        N)Zdescendantsr�next_element�previous_element)r�elementZearlier�er
r
r�assertConnectedness4szSoupTest.assertConnectedness)N)	�__name__�
__module__�__qualname__�propertyrrrrrr
r
r
rr
s

r
c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFd�ZdGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqS)r�HTMLTreeBuilderSmokeTestaCA basic test of a treebuilder's competence.

    Any HTML treebuilder, present or future, should be able to pass
    these tests. With invalid markup, there's room for interpretation,
    and different parsers can handle it differently. But with the
    markup in these tests, there's not much room for interpretation.
    cCs4x.dD]&}|jd�}|j|�}|jd|j�qWdS)zmVerify that all HTML4 and HTML5 empty element (aka void element) tags
        are handled correctly.
        �area�base�br�col�embed�hr�img�input�keygen�link�menuitem�meta�param�source�track�wbr�spacer�frame�TN)r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4)r�new_tagr�is_empty_element)r�namerr6r
r
r�test_empty_element_tagsIs

z0HTMLTreeBuilderSmokeTest.test_empty_element_tagscCsF|jd�}tj|d�}tj|�}|j|jt�|j|j�|j��dS)Nz
<a><b>foo</a>�)r�pickle�dumps�loadsr�	__class__rr)r�tree�dumped�loadedr
r
r�!test_pickle_and_unpickle_identityUs


z:HTMLTreeBuilderSmokeTest.test_pickle_and_unpickle_identitycCsf|j|�\}}|jd}|j|jt�|j||�|jt|�dt|��|�|j|jjdd�dS)z8Assert that a given doctype string is handled correctly.rN�foo)�_document_with_doctype�contentsrr>r�str�len�p)r�doctype_fragmentZdoctype_strr�doctyper
r
r�assertDoctypeHandled^s
z-HTMLTreeBuilderSmokeTest.assertDoctypeHandledcCs"d|}|d}|j|�}||fS)z5Generate and parse a document with the given doctype.z
<!DOCTYPE %s>z
<p>foo</p>)r)rrIrJrrr
r
rrDls
z/HTMLTreeBuilderSmokeTest._document_with_doctypecCs|jd�|jd�dS)z?Make sure normal, everyday HTML doctypes are handled correctly.�htmlz4html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"N)rK)rr
r
r�test_normal_doctypesss
z-HTMLTreeBuilderSmokeTest.test_normal_doctypescCs(|jd�}|jd}|jd|j��dS)Nz
<!DOCTYPE>rr5)rrEr�strip)rrrJr
r
r�test_empty_doctypeys

z+HTMLTreeBuilderSmokeTest.test_empty_doctypecCsd}|j|�dS)Nznhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")rK)rrJr
r
r�test_public_doctype_with_url~sz5HTMLTreeBuilderSmokeTest.test_public_doctype_with_urlcCs|jd�dS)Nz$foo SYSTEM "http://www.example.com/")rK)rr
r
r�test_system_doctype�sz,HTMLTreeBuilderSmokeTest.test_system_doctypecCs|jd�dS)Nz#xsl:stylesheet SYSTEM "htmlent.dtd")rK)rr
r
r�test_namespaced_system_doctype�sz7HTMLTreeBuilderSmokeTest.test_namespaced_system_doctypecCs|jd�dS)Nz#xsl:stylesheet PUBLIC "htmlent.dtd")rK)rr
r
r�test_namespaced_public_doctype�sz7HTMLTreeBuilderSmokeTest.test_namespaced_public_doctypecCs4d}|j|�}|j|jd�jdd�|jdd��dS)zJA real XHTML document should come out more or less the same as it went in.s�<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Hello.</title></head>
<body>Goodbye.</body>
</html>zutf-8�
�N)rr�encode�replace)rrrr
r
r�test_real_xhtml_document�s

z1HTMLTreeBuilderSmokeTest.test_real_xhtml_documentcCs(d}|j|�}|jdt|jd���dS)ztWhen a namespaced XML document is parsed as HTML it should
        be treated as HTML with weird tag names.
        s.<ns1:foo>content</ns1:foo><ns1:foo/><ns2:foo/>r:zns1:fooN)rrrG�find_all)rrrr
r
r�test_namespaced_html�s
z-HTMLTreeBuilderSmokeTest.test_namespaced_htmlcCsBd}|j|�}|j||j��d}|j|�}|j||jd��dS)Nz<?PITarget PIContent?>s<?PITarget PIContent?>�utf8)rrrrV)rrrr
r
r�test_processing_instruction�s

z4HTMLTreeBuilderSmokeTest.test_processing_instructioncCstj|j�dS)z�Make sure you can copy the tree builder.

        This is important because the builder is part of a
        BeautifulSoup object, and we want to be able to copy that.
        N)�copy�deepcopyr)rr
r
r�
test_deepcopy�sz&HTMLTreeBuilderSmokeTest.test_deepcopycCs.|jd�}|j|jj�|jt|j�d�dS)z�A <p> tag is never designated as an empty-element tag.

        Even if the markup shows it as an empty-element tag, it
        shouldn't be presented that way.
        z<p/>z<p></p>N)rZassertFalserHr7rrF)rrr
r
r�!test_p_tag_is_never_empty_element�s
z:HTMLTreeBuilderSmokeTest.test_p_tag_is_never_empty_elementcCs(|jdd�|jdd�|jdd�dS)z�A tag that's not closed by the end of the document should be closed.

        This applies to all tags except empty-element tags.
        z<p>z<p></p>z<b>z<b></b>z<br>z<br/>N)r)rr
r
r�test_unclosed_tags_get_closed�sz6HTMLTreeBuilderSmokeTest.test_unclosed_tags_get_closedcCs.|jd�}|j|jj�|jt|j�d�dS)z�A <br> tag is designated as an empty-element tag.

        Some parsers treat <br></br> as one <br/> tag, some parsers as
        two tags, but it should always be an empty-element tag.
        z	<br></br>z<br/>N)r�
assertTruer%r7rrF)rrr
r
r�#test_br_is_always_empty_element_tag�s
z<HTMLTreeBuilderSmokeTest.test_br_is_always_empty_element_tagcCs|jd�dS)Nz<em><em></em></em>)r)rr
r
r�test_nested_formatting_elements�sz8HTMLTreeBuilderSmokeTest.test_nested_formatting_elementscCs(d}|j|�}|jd|jd�d�dS)Nz�<!DOCTYPE html>
<html>
<head>
<title>Ordinary HEAD element test</title>
</head>
<script type="text/javascript">
alert("Help!");
</script>
<body>
Hello, world!
</body>
</html>
ztext/javascript�script�type)rr�find)rrLrr
r
r�test_double_head�s

z)HTMLTreeBuilderSmokeTest.test_double_headcCsjd}|j|�|j|�}|jdd�}|j|jt�|jdd�}|j||j�|jdd�}|j||j�dS)Nz<p>foo<!--foobar-->baz</p>Zfoobar)�textrC�baz)rrrgrr>rrr)rrrZcommentrCrjr
r
r�test_comment�s

z%HTMLTreeBuilderSmokeTest.test_commentcCstd}d}|j|�|j|�|j|�}|j|jj�|�|j|�}|j|jj�|�|jd�}|j|jj�d�dS)zWhitespace must be preserved in <pre> and <textarea> tags,
        even if that would mean not prettifying the markup.
        z<pre>   </pre>z<textarea> woo
woo  </textarea>z<textarea></textarea>N)rrrZpreZprettifyZtextarea)rZ
pre_markupZtextarea_markuprr
r
r�-test_preserved_whitespace_in_pre_and_textarea�s




zFHTMLTreeBuilderSmokeTest.test_preserved_whitespace_in_pre_and_textareacCs.d}|j|�d}|j|�d}|j|�dS)z+Inline elements can be nested indefinitely.z<b>Inside a B tag</b>z!<p>A <i>nested <b>tag</b></i></p>z/<p>A <a>doubly <i>nested <b>tag</b></i></a></p>N)r)rZb_tagZnested_b_tagZdouble_nested_b_tagr
r
r�test_nested_inline_elements
s

z4HTMLTreeBuilderSmokeTest.test_nested_inline_elementscCs6|jd�}|j}|j|jjjd�|j|jjd�dS)zBlock elements can be nested.z*<blockquote><p><b>Foo</b></p></blockquote>ZFooN)r�
blockquoterrH�b�string)rrrnr
r
r� test_nested_block_level_elementss
z9HTMLTreeBuilderSmokeTest.test_nested_block_level_elementscCsd}|j|d�|jd�dS)z$One table can go inside another one.z[<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>zh<table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td></tr></table>z{<table><thead><tr><td>Foo</td></tr></thead><tbody><tr><td>Bar</td></tr></tbody><tfoot><tr><td>Baz</td></tr></tfoot></table>N)r)rrr
r
r�test_correctly_nested_tablessz5HTMLTreeBuilderSmokeTest.test_correctly_nested_tablescCs(d}|j|�}|jdg|jjd�dS)Nz1<table><div><div class="css"></div></div></table>Zcss�class)rrZdiv)rrrr
r
r�(test_deeply_nested_multivalued_attribute0s
zAHTMLTreeBuilderSmokeTest.test_deeply_nested_multivalued_attributecCs(d}|j|�}|jddg|jd�dS)Nz<html class="a b"></html>�arors)rrrL)rrrr
r
r�"test_multivalued_attribute_on_html8s
z;HTMLTreeBuilderSmokeTest.test_multivalued_attribute_on_htmlcCs|jdd�dS)Nz<a b="<a>"></a>z<a b="&lt;a&gt;"></a>)r)rr
r
r�3test_angle_brackets_in_attribute_values_are_escaped@szLHTMLTreeBuilderSmokeTest.test_angle_brackets_in_attribute_values_are_escapedcCs|jdd�dS)Nz$<p>&bull; AT&T is in the s&p 500</p>z,<p>\u2022 AT&amp;T is in the s&amp;p 500</p>)r)rr
r
r�3test_strings_resembling_character_entity_referencesCszLHTMLTreeBuilderSmokeTest.test_strings_resembling_character_entity_referencescCs"d}|j|�}|jd|jj�dS)Nz%<p>&#147;Hello&#148; &#45;&#9731;</p>u“Hello” -☃)rrrHrp)rrrr
r
r�*test_entities_in_foreign_document_encodingKs
zCHTMLTreeBuilderSmokeTest.test_entities_in_foreign_document_encodingcCs8d}|jd|�|jd|�|jd|�|jd|�dS)Nu<p id="piñata"></p>z<p id="pi&#241;ata"></p>z<p id="pi&#xf1;ata"></p>z<p id="pi&#Xf1;ata"></p>z<p id="pi&ntilde;ata"></p>)r)r�expectr
r
r�0test_entities_in_attributes_converted_to_unicodeWs
zIHTMLTreeBuilderSmokeTest.test_entities_in_attributes_converted_to_unicodecCs8d}|jd|�|jd|�|jd|�|jd|�dS)Nu<p>piñata</p>z<p>pi&#241;ata</p>z<p>pi&#xf1;ata</p>z<p>pi&#Xf1;ata</p>z<p>pi&ntilde;ata</p>)r)rrzr
r
r�*test_entities_in_text_converted_to_unicode^s
zCHTMLTreeBuilderSmokeTest.test_entities_in_text_converted_to_unicodecCs|jdd�dS)Nz#<p>I said &quot;good day!&quot;</p>z<p>I said "good day!"</p>)r)rr
r
r�,test_quot_entity_converted_to_quotation_markeszEHTMLTreeBuilderSmokeTest.test_quot_entity_converted_to_quotation_markcCs,d}|jd|�|jd|�|jd|�dS)Nu�z&#10000000000000;z&#x10000000000000;z
&#1000000000;)r)rrzr
r
r�test_out_of_range_entityisz1HTMLTreeBuilderSmokeTest.test_out_of_range_entitycCs<|jd�}|jd|jjjj�|jd|jj�|j|�dS)zDMostly to prevent a recurrence of a bug in the html5lib treebuilder.z!<html><h2>
foo</h2><p></p></html>rHN)rrZh2rprr8rHr)rrr
r
r�test_multipart_stringsos
z/HTMLTreeBuilderSmokeTest.test_multipart_stringscCs|jdd�|jdd�dS)zqVerify consistent handling of empty-element tags,
        no matter how they come in through the markup.
        z<br/><br/><br/>z<br /><br /><br />N)r)rr
r
rr9vscCs,d}|j|�}|jd|jj�|j|�dS)z8Prevent recurrence of a bug in the html5lib treebuilder.z?<html><head></head>
  <link></link>
  <body>foo</body>
</html>
N)rZassertNotEqualrL�bodyr)r�contentrr
r
r�#test_head_tag_between_head_and_body}s
z<HTMLTreeBuilderSmokeTest.test_head_tag_between_head_and_bodycCsd}|j|�}|j|j�dS)z8Prevent recurrence of a bug in the html5lib treebuilder.z�<!DOCTYPE html>
<html>
 <body>
   <article id="a" >
   <div><a href="1"></div>
   <footer>
     <a href="2"></a>
   </footer>
  </article>
  </body>
</html>
N)rrZarticle)rr�rr
r
r�test_multiple_copies_of_a_tag�s

z6HTMLTreeBuilderSmokeTest.test_multiple_copies_of_a_tagcCs^d}|j|�}|j||j��|j}|jd|jd�|jd|jd�|jd|jd�dS)	z�Parsers don't need to *understand* namespaces, but at the
        very least they should not choke on namespaces or lose
        data.s�<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg"><head></head><body><mathml:msqrt>4</mathml:msqrt><b svg:fill="red"></b></body></html>zhttp://www.w3.org/1999/xhtmlZxmlnsz"http://www.w3.org/1998/Math/MathMLzxmlns:mathmlzhttp://www.w3.org/2000/svgz	xmlns:svgN)rrrVrL)rrrrLr
r
r�test_basic_namespaces�s
z.HTMLTreeBuilderSmokeTest.test_basic_namespacescCs(d}|j|�}|jddg|jd�dS)Ns<a class="foo bar">rC�barrs)rrru)rrrr
r
r�-test_multivalued_attribute_value_becomes_list�s
zFHTMLTreeBuilderSmokeTest.test_multivalued_attribute_value_becomes_listcCs"d}|j|�}|jd|jj�dS)NuD<html><head><meta encoding="euc-jp"></head><body>Sacré bleu!</body>uSacré bleu!)rrr�rp)rrrr
r
r�test_can_parse_unicode_document�s
z8HTMLTreeBuilderSmokeTest.test_can_parse_unicode_documentcCs*td�}|jd|d�}|j|j�d�dS)z2Parsers should be able to work with SoupStrainers.roz&A <b>bold</b> <meta/> <i>statement</i>)Z
parse_onlyz<b>bold</b>N)rrrr)rZstrainerrr
r
r�test_soupstrainer�sz*HTMLTreeBuilderSmokeTest.test_soupstrainercCs|jdd�dS)Nz<foo attr='bar'></foo>z<foo attr="bar"></foo>)r)rr
r
r�7test_single_quote_attribute_values_become_double_quotes�szPHTMLTreeBuilderSmokeTest.test_single_quote_attribute_values_become_double_quotescCsd}|j|�dS)Nz'<foo attr='bar "brawls" happen'>a</foo>)r)rrir
r
r�7test_attribute_values_with_nested_quotes_are_left_alone�szPHTMLTreeBuilderSmokeTest.test_attribute_values_with_nested_quotes_are_left_alonecCs.d}|j|�}d|jd<|j|jj�d�dS)Nz'<foo attr='bar "brawls" happen'>a</foo>zBrawls happen at "Bob's Bar"�attrz:<foo attr="Brawls happen at &quot;Bob's Bar&quot;">a</foo>)rrCrr)rrirr
r
r�:test_attribute_values_with_double_nested_quotes_get_quoted�s

zSHTMLTreeBuilderSmokeTest.test_attribute_values_with_double_nested_quotes_get_quotedcCs|jdd�|jdd�dS)Nz+<this is="really messed up & stuff"></this>z/<this is="really messed up &amp; stuff"></this>z.<a href="http://example.org?a=1&b=2;3">foo</a>z2<a href="http://example.org?a=1&amp;b=2;3">foo</a>)r)rr
r
r�.test_ampersand_in_attribute_value_gets_escaped�s
zGHTMLTreeBuilderSmokeTest.test_ampersand_in_attribute_value_gets_escapedcCs|jd�dS)Nz/<a href="http://example.org?a=1&amp;b=2;3"></a>)r)rr
r
r�7test_escaped_ampersand_in_attribute_value_is_left_alone�szPHTMLTreeBuilderSmokeTest.test_escaped_ampersand_in_attribute_value_is_left_alonecCsd}d}|j||�dS)Nz-<p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>u#<p>&lt;&lt;sacré bleu!&gt;&gt;</p>)r)rri�expectedr
r
r�1test_entities_in_strings_converted_during_parsing�szJHTMLTreeBuilderSmokeTest.test_entities_in_strings_converted_during_parsingcCs"d}|j|�}|j|jjd�dS)Ns<p>�Foo�</p>u	‘Foo’)rrrHrp)rZquoterr
r
r�)test_smart_quotes_converted_on_the_way_in�s

zBHTMLTreeBuilderSmokeTest.test_smart_quotes_converted_on_the_way_incCs|jd�}|j|jjd�dS)Nz<a>&nbsp;&nbsp;</a>� r:u  )rrrurp)rrr
r
r�0test_non_breaking_spaces_converted_on_the_way_in�s
zIHTMLTreeBuilderSmokeTest.test_non_breaking_spaces_converted_on_the_way_incCs0d}djd�}|j|�}|j|jjd�|�dS)Nz-<p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>u#<p>&lt;&lt;sacré bleu!&gt;&gt;</p>zutf-8)rVrrrH)rrir�rr
r
r�&test_entities_converted_on_the_way_out�s

z?HTMLTreeBuilderSmokeTest.test_entities_converted_on_the_way_outcCsHd}|jd�}|j|�}|jd�}|jdd�}|jd�}|j||�dS)Nu�<html><head><meta content="text/html; charset=ISO-Latin-1" http-equiv="Content-type"/></head><body><p>Sacré bleu!</p></body></html>z
iso-8859-1zutf-8zISO-Latin-1)rVrrWr)r�unicode_htmlZiso_latin_htmlr�resultr�r
r
r�test_real_iso_latin_document�s



z5HTMLTreeBuilderSmokeTest.test_real_iso_latin_documentcCsLd}|jd�}|j|�}|j|jd�|jd��|j|jd�|jd��dS)Nsk<html><head></head><body><pre>�����Shift-JIS�ŃR�[�f�B���O���ꂽ���{��̃t�@�C���ł��B</pre></body></html>z	shift-jiszutf-8�euc_jp)rrrrV)r�shift_jis_htmlr�rr
r
r�test_real_shift_jis_documents


z5HTMLTreeBuilderSmokeTest.test_real_shift_jis_documentcCsBd}|j|dd�}|jdks t�|j|jd�|jd�jd��dS)Ns�<html><head><title>Hebrew (ISO 8859-8) in Visual Directionality</title></head><body><h1>Hebrew (ISO 8859-8) in Visual Directionality</h1>���</body></html>�	iso8859-8)Z
from_encoding�
iso-8859-8zutf-8)r�r�)rZoriginal_encoding�AssertionErrorrrVr)rZhebrew_documentrr
r
r�test_real_hebrew_document$s
z2HTMLTreeBuilderSmokeTest.test_real_hebrew_documentcCs`d}d|}|j|�}|jdddi�}|d}|jd|�|jt|t��|jd|jd	��dS)
NzE<meta content="text/html; charset=x-sjis" http-equiv="Content-type"/>zj<html><head>
%s
<meta http-equiv="Content-language" content="ja"/></head><body>Shift-JIS markup goes here.r.z
http-equivzContent-typer�ztext/html; charset=x-sjisztext/html; charset=utf8r[)rrgrrb�
isinstancerrV)r�meta_tagr�r�parsed_metar�r
r
r�'test_meta_tag_reflects_current_encoding1s
[email protected]_meta_tag_reflects_current_encodingcCs^d}d|}|j|�}|jddd�}|d}|jd|�|jt|t��|jd|jd��dS)	Nz'<meta id="encoding" charset="x-sjis" />zj<html><head>
%s
<meta http-equiv="Content-language" content="ja"/></head><body>Shift-JIS markup goes here.r.�encoding)�id�charsetzx-sjisr[)rrgrrbr�rrV)rr�r�rr�r�r
r
r�3test_html5_style_meta_tag_reflects_current_encodingMs
zLHTMLTreeBuilderSmokeTest.test_html5_style_meta_tag_reflects_current_encodingcCs*|jd�}d|jd<|jd|jj��dS)Nz<a>text</a>r�rCz<a foo="bar">text</a>)rrurr)r�datar
r
r�5test_tag_with_no_attributes_can_have_attributes_addedes

zNHTMLTreeBuilderSmokeTest.test_tag_with_no_attributes_can_have_attributes_addedN);rrr �__doc__r9rBrKrDrMrOrPrQrRrSrXrZr\r_r`rarcrdrhrkrlrmrqrrrtrvrwrxryr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr"?sr	




	
r"c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�XMLTreeBuilderSmokeTestcCsF|jd�}tj|d�}tj|�}|j|jt�|j|j�|j��dS)Nz
<a><b>foo</a>r:)rr;r<r=rr>rr)rr?r@rAr
r
rrBls


z9XMLTreeBuilderSmokeTest.test_pickle_and_unpickle_identitycCs|jd�}|j|j�d�dS)Nz<root/>s.<?xml version="1.0" encoding="utf-8"?>
<root/>)rrrV)rrr
r
r�test_docstring_generatedus
z0XMLTreeBuilderSmokeTest.test_docstring_generatedcCs$d}|j|�}|j||jd��dS)Ns,<?xml version="1.0" encoding="utf8"?>
<foo/>r[)rrrV)rrrr
r
r�test_xml_declarationzs
z,XMLTreeBuilderSmokeTest.test_xml_declarationcCs$d}|j|�}|j||jd��dS)Ns<<?xml version="1.0" encoding="utf8"?>
<?PITarget PIContent?>r[)rrrV)rrrr
r
rr\s
z3XMLTreeBuilderSmokeTest.test_processing_instructioncCs$d}|j|�}|j|jd�|�dS)zGA real XHTML document should come out *exactly* the same as it went in.s�<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Hello.</title></head>
<body>Goodbye.</body>
</html>zutf-8N)rrrV)rrrr
r
rrX�s
z0XMLTreeBuilderSmokeTest.test_real_xhtml_documentcCs"d}|j|�}|j||j��dS)Ns<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<parent xmlns="http://ns1/">
<child xmlns="http://ns2/" xmlns:ns3="http://ns3/">
<grandchild ns3:attr="value" xmlns="http://ns4/"/>
</child>
</parent>)rrrV)r�docrr
r
r�test_nested_namespaces�s
z.XMLTreeBuilderSmokeTest.test_nested_namespacescCs0d}t|d�}d|j_|j�}|jd|k�dS)Nz/
  <script type="text/javascript">
  </script>
zlxml-xmlzconsole.log("< < hey > > ");s&lt; &lt; hey &gt; &gt;)rrerprVrb)rr�rZencodedr
r
r�5test_formatter_processes_script_tag_for_xml_documents�s

zMXMLTreeBuilderSmokeTest.test_formatter_processes_script_tag_for_xml_documentscCs"d}|j|�}|jd|jj�dS)Nu?<?xml version="1.0" encoding="euc-jp"><root>Sacré bleu!</root>uSacré bleu!)rr�rootrp)rrrr
r
rr��s
z7XMLTreeBuilderSmokeTest.test_can_parse_unicode_documentcCs$d}|j|�}|jt|j�|�dS)Nz�<rss xmlns:dc="foo"><dc:creator>b</dc:creator><dc:date>2012-07-02T20:33:42Z</dc:date><dc:rights>c</dc:rights><image>d</image></rss>)rrrFZrss)rrrr
r
r�test_popping_namespaced_tag�s
z3XMLTreeBuilderSmokeTest.test_popping_namespaced_tagcCs |jd�}|j|jd�d�dS)Nz<root/>�latin1s/<?xml version="1.0" encoding="latin1"?>
<root/>)rrrV)rrr
r
r�(test_docstring_includes_correct_encoding�s
[email protected]_docstring_includes_correct_encodingcCs0dddd}|j|�}|j|jd�|�dS)	z<A large XML document should come out the same as it went in.s-<?xml version="1.0" encoding="utf-8"?>
<root>�0r:�s</root>zutf-8Ni)rrrV)rrrr
r
r�test_large_xml_document�s
z/XMLTreeBuilderSmokeTest.test_large_xml_documentcCs|jdd�|jd�dS)Nz<p>z<p/>z
<p>foo</p>)r)rr
r
r�9test_tags_are_empty_element_if_and_only_if_they_are_empty�szQXMLTreeBuilderSmokeTest.test_tags_are_empty_element_if_and_only_if_they_are_emptycCs8d}|j|�}|j}|jd|d�|jd|d�dS)Nz�<root xmlns:a="http://example.com/" xmlns:b="http://example.net/"><a:foo>This tag is in the a namespace</a:foo><b:foo>This tag is in the b namespace</b:foo></root>zhttp://example.com/zxmlns:azhttp://example.net/zxmlns:b)rr�r)rrrr�r
r
r�test_namespaces_are_preserved�s

z5XMLTreeBuilderSmokeTest.test_namespaces_are_preservedcCs$d}|j|�}|jt|j�|�dS)NzN<p xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>20010504</dc:date></p>)rrrFrH)rrrr
r
r�test_closing_namespaced_tag�s
z3XMLTreeBuilderSmokeTest.test_closing_namespaced_tagcCs$d}|j|�}|jt|j�|�dS)Nzs<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><bar xsi:schemaLocation="http://www.example.com"/></foo>)rrrFrC)rrrr
r
r�test_namespaced_attributes�s
z2XMLTreeBuilderSmokeTest.test_namespaced_attributescCs$d}|j|�}|jt|j�|�dS)Nz<foo xml:lang="fr">bar</foo>)rrrFrC)rrrr
r
r�(test_namespaced_attributes_xml_namespace�s
[email protected]_namespaced_attributes_xml_namespacecCs�d}|j|�}|jdt|jd���|jdt|jd���|jdt|jd���|jdt|jddd	���|jdt|jddg���dS)
Na<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="http://example.com/ns0"
    xmlns:ns1="http://example.com/ns1"
    xmlns:ns2="http://example.com/ns2"
    <ns1:tag>foo</ns1:tag>
    <ns1:tag>bar</ns1:tag>
    <ns2:tag key="value">baz</ns2:tag>
</Document>
��tagr:zns1:tag�zns2:tag�value)�key)rrrGrY)rr�rr
r
r�test_find_by_prefixed_name�s	
z2XMLTreeBuilderSmokeTest.test_find_by_prefixed_namecCs2d}|j|�}|j}tj|�}|j|j|j�dS)Nzf<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://example.com/ns0"/>)rZdocumentr]r�prefix)rZxmlrr�Z	duplicater
r
r�!test_copy_tag_preserves_namespace�s


z9XMLTreeBuilderSmokeTest.test_copy_tag_preserves_namespaceN)rrr rBr�r�r\rXr�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr�js$		r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�HTML5TreeBuilderSmokeTestz2Smoke test for a tree builder that supports HTML5.cCsdS)Nr
)rr
r
rrXsz2HTML5TreeBuilderSmokeTest.test_real_xhtml_documentcCs"d}|j|�}|jd|jj�dS)Nz<a>zhttp://www.w3.org/1999/xhtml)rrru�	namespace)rrrr
r
r�test_html_tags_have_namespaces
z7HTML5TreeBuilderSmokeTest.test_html_tags_have_namespacecCs6d}|j|�}d}|j||jj�|j||jj�dS)Nz<svg><circle/></svg>zhttp://www.w3.org/2000/svg)rrZsvgr�Zcircle)rrrr�r
r
r�test_svg_tags_have_namespace
s

z6HTML5TreeBuilderSmokeTest.test_svg_tags_have_namespacecCs6d}|j|�}d}|j||jj�|j||jj�dS)Nz<math><msqrt>5</msqrt></math>z"http://www.w3.org/1998/Math/MathML)rrZmathr�Zmsqrt)rrrr�r
r
r�test_mathml_tags_have_namespaces

z9HTML5TreeBuilderSmokeTest.test_mathml_tags_have_namespacecCsPd}|j|�}|jt|jdt��|j|jdd�|jd|jdjj�dS)Nz3<?xml version="1.0" encoding="utf-8"?><html></html>rz$?xml version="1.0" encoding="utf-8"?rL)rrbr�rErrrr8)rrrr
r
r�$test_xml_declaration_becomes_comments

z>HTML5TreeBuilderSmokeTest.test_xml_declaration_becomes_commentN)	rrr r�rXr�r�r�r�r
r
r
rr��sr�csdd����fdd�}|S)Nc_sdS)Nr
)Ztest�argsrr
r
r�nothing!szskipIf.<locals>.nothingcs�r�S|SdS)Nr
)Z	test_item)�	conditionr�r
r�	decorator$szskipIf.<locals>.decoratorr
)r��reasonr�r
)r�r�r�skipIf sr�)r�Z__license__r;r]�	functoolsZunittestrZbs4rZbs4.elementrrrrrZbs4.builderr	rr
�objectr"r�r�r�r
r
r
r�<module>s(%/#
Page not found – Hello World !