
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>

\[c           @   s  d  Z  d Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 m Z m Z m Z m Z d d l m Z e Z d e j f d	     YZ d
 e f d     YZ d e f d     YZ d e f d     YZ d   Z d S(   s   Helper classes for tests.t   MITiN(   t   TestCase(   t   BeautifulSoup(   t   CharsetMetaAttributeValuet   Commentt   ContentMetaAttributeValuet   Doctypet   SoupStrainer(   t   HTMLParserTreeBuildert   SoupTestc           B   s>   e  Z e d     Z d   Z d   Z d d  Z d   Z RS(   c         C   s   t    S(   N(   t   default_builder(   t   self(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR
      s    c         K   s(   | j  d |  j  } t | d | | S(   s*   Build a Beautiful Soup object from markup.t   builder(   t   popR
   R   (   R   t   markupt   kwargsR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   soup    s    c         C   s   |  j  j |  S(   s[   Turn an HTML fragment into a document.

        The details depend on the builder.
        (   R
   t   test_fragment_to_document(   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   document_for%   s    c         C   sS   |  j  } t | d | } | d  k r0 | } n  |  j | j   |  j |   d  S(   NR   (   R
   R   t   Nonet   assertEqualt   decodeR   (   R   t   to_parset   compare_parsed_toR   t   obj(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   assertSoupEquals,   s
    		c         C   sS   d } xF | j D]; } | rE |  j | | j  |  j | | j  n  | } q Wd S(   sy   Ensure that next_element and previous_element are properly
        set for all descendants of the given element.
        N(   R   t   descendantsR   t   next_elementt   previous_element(   R   t   elementt   earliert   e(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   assertConnectedness4   s    N(	   t   __name__t
   __module__t   propertyR
   R   R   R   R   R    (    (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR	      s
   		t   HTMLTreeBuilderSmokeTestc           B   s  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# d"   Z$ d#   Z d$   Z% d%   Z& d&   Z' d'   Z( d(   Z) d)   Z* d*   Z+ d+   Z, d,   Z- d-   Z. d.   Z/ d/   Z0 d0   Z1 d1   Z2 d2   Z3 d3   Z4 d4   Z5 d5   Z6 d6   Z7 d7   Z8 d8   Z9 RS(9   sC  A 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.
    c         C   s|   xu d d d d d d d d d	 d
 d d d d d d d d g D]7 } |  j  d  } | j |  } |  j t | j  q= Wd S(   sm   Verify that all HTML4 and HTML5 empty element (aka void element) tags
        are handled correctly.
        t   areat   baset   brt   colt   embedt   hrt   imgt   inputt   keygent   linkt   menuitemt   metat   paramt   sourcet   trackt   wbrt   spacert   framet    N(   R   t   new_tagR   t   Truet   is_empty_element(   R   t   nameR   R8   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_empty_element_tagsI   s    0c         C   sc   |  j  d  } t j | d  } t j |  } |  j | j t  |  j | j   | j    d  S(   Ns   <a><b>foo</a>i   (   R   t   picklet   dumpst   loadsR   t	   __class__R   R   (   R   t   treet   dumpedt   loaded(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt!   test_pickle_and_unpickle_identityU   s
    c         C   s   |  j  |  \ } } | j d } |  j | j t  |  j | |  |  j t |  t |   |  |  j | j j d d  d S(   s8   Assert that a given doctype string is handled correctly.i    t   fooN(   t   _document_with_doctypet   contentsR   R@   R   t   strt   lent   p(   R   t   doctype_fragmentt   doctype_strR   t   doctype(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   assertDoctypeHandled^   s     c         C   s-   d | } | d } |  j  |  } | | f S(   s5   Generate and parse a document with the given doctype.s   <!DOCTYPE %s>s   
<p>foo</p>(   R   (   R   RK   RM   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyRF   l   s    

c         C   s   |  j  d  |  j  d  d S(   s?   Make sure normal, everyday HTML doctypes are handled correctly.t   htmls4   html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"N(   RN   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_normal_doctypess   s    c         C   s6   |  j  d  } | j d } |  j d | j    d  S(   Ns
   <!DOCTYPE>i    R7   (   R   RG   R   t   strip(   R   R   RM   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_empty_doctypey   s    c         C   s   d } |  j  |  d  S(   Nsn   html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"(   RN   (   R   RM   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_public_doctype_with_url~   s    c         C   s   |  j  d  d  S(   Ns$   foo SYSTEM "http://www.example.com/"(   RN   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_system_doctype   s    c         C   s   |  j  d  d  S(   Ns#   xsl:stylesheet SYSTEM "htmlent.dtd"(   RN   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_namespaced_system_doctype   s    c         C   s   |  j  d  d  S(   Ns#   xsl:stylesheet PUBLIC "htmlent.dtd"(   RN   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_namespaced_public_doctype   s    c         C   sJ   d } |  j  |  } |  j | j d  j d d  | j d d   d S(   sJ   A 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>s   utf-8s   
R7   N(   R   R   t   encodet   replace(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_real_xhtml_document   s
    c         C   s8   d } |  j  |  } |  j d t | j d    d S(   st   When 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/>i   s   ns1:fooN(   R   R   RI   t   find_all(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_namespaced_html   s    c         C   s]   d } |  j  |  } |  j | | j    d } |  j  |  } |  j | | j d   d  S(   Nu   <?PITarget PIContent?>s   <?PITarget PIContent?>t   utf8(   R   R   R   RW   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_processing_instruction   s    c         C   s   t  j |  j  d S(   s   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(   t   copyt   deepcopyR
   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_deepcopy   s    c         C   s?   |  j  d  } |  j | j j  |  j t | j  d  d S(   s   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.
        s   <p/>s   <p></p>N(   R   t   assertFalseRJ   R:   R   RH   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt!   test_p_tag_is_never_empty_element   s    c         C   s4   |  j  d d  |  j  d d  |  j  d d  d S(   s   A tag that's not closed by the end of the document should be closed.

        This applies to all tags except empty-element tags.
        s   <p>s   <p></p>s   <b>s   <b></b>s   <br>s   <br/>N(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_unclosed_tags_get_closed   s    c         C   s?   |  j  d  } |  j | j j  |  j t | j  d  d S(   s   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.
        s	   <br></br>s   <br/>N(   R   t
   assertTrueR'   R:   R   RH   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt#   test_br_is_always_empty_element_tag   s    c         C   s   |  j  d  d  S(   Ns   <em><em></em></em>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_nested_formatting_elements   s    c         C   s6   d } |  j  |  } |  j d | j d  d  d  S(   Ns   <!DOCTYPE html>
<html>
<head>
<title>Ordinary HEAD element test</title>
</head>
<script type="text/javascript">
alert("Help!");
</script>
<body>
Hello, world!
</body>
</html>
s   text/javascriptt   scriptt   type(   R   R   t   find(   R   RO   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_double_head   s    c         C   s   d } |  j  |  |  j |  } | j d d  } |  j | j t  | j d d  } |  j | | j  | j d d  } |  j | | j  d  S(   Ns   <p>foo<!--foobar-->baz</p>t   textt   foobarRE   t   baz(   R   R   Ri   R   R@   R   R   R   (   R   R   R   t   commentRE   Rm   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_comment   s    c         C   s   d } d } |  j  |  |  j  |  |  j |  } |  j | j j   |  |  j |  } |  j | j j   |  |  j d  } |  j | j j   d  d S(   s   Whitespace must be preserved in <pre> and <textarea> tags,
        even if that would mean not prettifying the markup.
        s   <pre>   </pre>s   <textarea> woo
woo  </textarea>s   <textarea></textarea>N(   R   R   R   t   pret   prettifyt   textarea(   R   t
   pre_markupt   textarea_markupR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt-   test_preserved_whitespace_in_pre_and_textarea   s    c         C   s=   d } |  j  |  d } |  j  |  d } |  j  |  d S(   s+   Inline elements can be nested indefinitely.s   <b>Inside a B tag</b>s!   <p>A <i>nested <b>tag</b></i></p>s/   <p>A <a>doubly <i>nested <b>tag</b></i></a></p>N(   R   (   R   t   b_tagt   nested_b_tagt   double_nested_b_tag(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_nested_inline_elements
  s    c         C   sK   |  j  d  } | j } |  j | j j j d  |  j | j j d  d S(   s   Block elements can be nested.s*   <blockquote><p><b>Foo</b></p></blockquote>t   FooN(   R   t
   blockquoteR   RJ   t   bt   string(   R   R   R{   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt    test_nested_block_level_elements  s    	c         C   s'   d } |  j  | d  |  j  d  d S(   s$   One table can go inside another one.s[   <table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>sh   <table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td></tr></table>s{   <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   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_correctly_nested_tables  s    c         C   s6   d } |  j  |  } |  j d g | j j d  d  S(   Ns1   <table><div><div class="css"></div></div></table>t   csst   class(   R   R   t   div(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt(   test_deeply_nested_multivalued_attribute0  s    c         C   s6   d } |  j  |  } |  j d d g | j d  d  S(   Ns   <html class="a b"></html>t   aR|   R   (   R   R   RO   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt"   test_multivalued_attribute_on_html8  s    c         C   s   |  j  d d  d  S(   Ns   <a b="<a>"></a>s   <a b="&lt;a&gt;"></a>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt3   test_angle_brackets_in_attribute_values_are_escaped@  s    c         C   s   |  j  d d  d  S(   Nu$   <p>&bull; AT&T is in the s&p 500</p>u)   <p>• AT&amp;T is in the s&amp;p 500</p>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt3   test_strings_resembling_character_entity_referencesC  s    c         C   s/   d } |  j  |  } |  j d | j j  d  S(   Ns%   <p>&#147;Hello&#148; &#45;&#9731;</p>u   “Hello” -☃(   R   t   assertEqualsRJ   R}   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt*   test_entities_in_foreign_document_encodingK  s    c         C   sJ   d } |  j  d |  |  j  d |  |  j  d |  |  j  d |  d  S(   Nu   <p id="piñata"></p>s   <p id="pi&#241;ata"></p>s   <p id="pi&#xf1;ata"></p>s   <p id="pi&#Xf1;ata"></p>s   <p id="pi&ntilde;ata"></p>(   R   (   R   t   expect(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt0   test_entities_in_attributes_converted_to_unicodeW  s
    c         C   sJ   d } |  j  d |  |  j  d |  |  j  d |  |  j  d |  d  S(   Nu   <p>piñata</p>s   <p>pi&#241;ata</p>s   <p>pi&#xf1;ata</p>s   <p>pi&#Xf1;ata</p>s   <p>pi&ntilde;ata</p>(   R   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt*   test_entities_in_text_converted_to_unicode^  s
    c         C   s   |  j  d d  d  S(   Ns#   <p>I said &quot;good day!&quot;</p>s   <p>I said "good day!"</p>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt,   test_quot_entity_converted_to_quotation_marke  s    	c         C   s:   d } |  j  d |  |  j  d |  |  j  d |  d  S(   Nu   �s   &#10000000000000;s   &#x10000000000000;s   &#1000000000;(   R   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_out_of_range_entityi  s    c         C   sR   |  j  d  } |  j d | j j j j  |  j d | j j  |  j |  d S(   sD   Mostly to prevent a recurrence of a bug in the html5lib treebuilder.s!   <html><h2>
foo</h2><p></p></html>RJ   N(   R   R   t   h2R}   R   R;   RJ   R    (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_multipart_stringso  s    c         C   s$   |  j  d d  |  j  d d  d S(   sq   Verify consistent handling of empty-element tags,
        no matter how they come in through the markup.
        s   <br/><br/><br/>s   <br /><br /><br />N(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR<   v  s    c         C   s<   d } |  j  |  } |  j d | j j  |  j |  d S(   s8   Prevent recurrence of a bug in the html5lib treebuilder.s?   <html><head></head>
  <link></link>
  <body>foo</body>
</html>
N(   R   t   assertNotEqualR   RO   t   bodyR    (   R   t   contentR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt#   test_head_tag_between_head_and_body}  s    c         C   s)   d } |  j  |  } |  j | j  d S(   s8   Prevent recurrence of a bug in the html5lib treebuilder.s   <!DOCTYPE html>
<html>
 <body>
   <article id="a" >
   <div><a href="1"></div>
   <footer>
     <a href="2"></a>
   </footer>
  </article>
  </body>
</html>
N(   R   R    t   article(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_multiple_copies_of_a_tag  s    c         C   s}   d } |  j  |  } |  j | | j    | j } |  j d | j d  |  j d | j d  |  j d | j d  d S(	   s   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>s   http://www.w3.org/1999/xhtmlt   xmlnss"   http://www.w3.org/1998/Math/MathMLs   xmlns:mathmls   http://www.w3.org/2000/svgs	   xmlns:svgN(   R   R   RW   RO   (   R   R   R   RO   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_basic_namespaces  s    	c         C   s6   d } |  j  |  } |  j d d g | j d  d  S(   Ns   <a class="foo bar">RE   t   barR   (   R   R   R   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt-   test_multivalued_attribute_value_becomes_list  s    c         C   s/   d } |  j  |  } |  j d | j j  d  S(   NuD   <html><head><meta encoding="euc-jp"></head><body>Sacré bleu!</body>u   Sacré bleu!(   R   R   R   R}   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_can_parse_unicode_document  s    c         C   s;   t  d  } |  j d d | } |  j | j   d  d S(   s2   Parsers should be able to work with SoupStrainers.R|   s&   A <b>bold</b> <meta/> <i>statement</i>t
   parse_onlys   <b>bold</b>N(   R   R   R   R   (   R   t   strainerR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_soupstrainer  s    	c         C   s   |  j  d d  d  S(   Ns   <foo attr='bar'></foo>s   <foo attr="bar"></foo>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt7   test_single_quote_attribute_values_become_double_quotes  s    	c         C   s   d } |  j  |  d  S(   Ns'   <foo attr='bar "brawls" happen'>a</foo>(   R   (   R   Rk   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt7   test_attribute_values_with_nested_quotes_are_left_alone  s    c         C   s?   d } |  j  |  } d | j d <|  j | j j   d  d  S(   Ns'   <foo attr='bar "brawls" happen'>a</foo>s   Brawls happen at "Bob's Bar"t   attrs:   <foo attr="Brawls happen at &quot;Bob's Bar&quot;">a</foo>(   R   RE   R   R   (   R   Rk   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt:   test_attribute_values_with_double_nested_quotes_get_quoted  s    c         C   s$   |  j  d d  |  j  d d  d  S(   Ns+   <this is="really messed up & stuff"></this>s/   <this is="really messed up &amp; stuff"></this>s.   <a href="http://example.org?a=1&b=2;3">foo</a>s2   <a href="http://example.org?a=1&amp;b=2;3">foo</a>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt.   test_ampersand_in_attribute_value_gets_escaped  s
    	c         C   s   |  j  d  d  S(   Ns/   <a href="http://example.org?a=1&amp;b=2;3"></a>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt7   test_escaped_ampersand_in_attribute_value_is_left_alone  s    c         C   s    d } d } |  j  | |  d  S(   Ns-   <p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>u#   <p>&lt;&lt;sacré bleu!&gt;&gt;</p>(   R   (   R   Rk   t   expected(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt1   test_entities_in_strings_converted_during_parsing  s    c         C   s/   d } |  j  |  } |  j | j j d  d  S(   Ns   <p>Foo</p>u	   ‘Foo’(   R   R   RJ   R}   (   R   t   quoteR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt)   test_smart_quotes_converted_on_the_way_in  s
    	c         C   s)   |  j  d  } |  j | j j d  d  S(   Ns   <a>&nbsp;&nbsp;</a>u    i   u     (   R   R   R   R}   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt0   test_non_breaking_spaces_converted_on_the_way_in  s    c         C   sD   d } d j  d  } |  j |  } |  j | j j  d  |  d  S(   Ns-   <p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>u#   <p>&lt;&lt;sacré bleu!&gt;&gt;</p>s   utf-8(   RW   R   R   RJ   (   R   Rk   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt&   test_entities_converted_on_the_way_out  s    c         C   sh   d } | j  d  } |  j |  } | j  d  } | j d d  } | j  d  } |  j | |  d  S(   Nu   <html><head><meta content="text/html; charset=ISO-Latin-1" http-equiv="Content-type"/></head><body><p>Sacré bleu!</p></body></html>s
   iso-8859-1s   utf-8s   ISO-Latin-1(   RW   R   RX   R   (   R   t   unicode_htmlt   iso_latin_htmlR   t   resultR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_real_iso_latin_document  s    c         C   sl   d } | j  d  } |  j |  } |  j | j d  | j d   |  j | j d  | j d   d  S(   Nsk   <html><head></head><body><pre>Shift-JISŃR[fBOꂽ{̃t@CłB</pre></body></html>s	   shift-jiss   utf-8t   euc_jp(   R   R   R   RW   (   R   t   shift_jis_htmlR   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_real_shift_jis_document  s
    "c         C   s_   d } |  j  | d d } | j d k s0 t  |  j | j d  | j d  j d   d  S(   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>t   from_encodings	   iso8859-8s
   iso-8859-8s   utf-8(   s	   iso8859-8s
   iso-8859-8(   R   t   original_encodingt   AssertionErrorR   RW   R   (   R   t   hebrew_documentR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_real_hebrew_document$  s    c         C   s   d } d | } |  j  |  } | j d i d d 6 } | d } |  j d |  |  j t | t   |  j d | j d	   d  S(
   NsE   <meta content="text/html; charset=x-sjis" http-equiv="Content-type"/>sj   <html><head>
%s
<meta http-equiv="Content-language" content="ja"/></head><body>Shift-JIS markup goes here.R0   s   Content-types
   http-equivR   s   text/html; charset=x-sjiss   text/html; charset=utf8R\   (   R   Ri   R   Rd   t
   isinstanceR   RW   (   R   t   meta_tagR   R   t   parsed_metaR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt'   test_meta_tag_reflects_current_encoding1  s    
c         C   s   d } d | } |  j  |  } | j d d d } | d } |  j d |  |  j t | t   |  j d | j d   d  S(	   Ns'   <meta id="encoding" charset="x-sjis" />sj   <html><head>
%s
<meta http-equiv="Content-language" content="ja"/></head><body>Shift-JIS markup goes here.R0   t   idt   encodingt   charsets   x-sjisR\   (   R   Ri   R   Rd   R   R   RW   (   R   R   R   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt3   test_html5_style_meta_tag_reflects_current_encodingM  s    
c         C   s9   |  j  d  } d | j d <|  j d | j j    d  S(   Ns   <a>text</a>R   RE   s   <a foo="bar">text</a>(   R   R   R   R   (   R   t   data(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt5   test_tag_with_no_attributes_can_have_attributes_addede  s    (:   R!   R"   t   __doc__R<   RD   RN   RF   RP   RR   RS   RT   RU   RV   RY   R[   R]   R`   Rb   Rc   Re   Rf   Rj   Ro   Ru   Ry   R~   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR$   ?   sr   																
	
	
																																							t   XMLTreeBuilderSmokeTestc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   sc   |  j  d  } t j | d  } t j |  } |  j | j t  |  j | j   | j    d  S(   Ns   <a><b>foo</a>i   (   R   R=   R>   R?   R   R@   R   R   (   R   RA   RB   RC   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyRD   l  s
    c         C   s)   |  j  d  } |  j | j   d  d  S(   Ns   <root/>s.   <?xml version="1.0" encoding="utf-8"?>
<root/>(   R   R   RW   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_docstring_generatedu  s    c         C   s2   d } |  j  |  } |  j | | j d   d  S(   Ns,   <?xml version="1.0" encoding="utf8"?>
<foo/>R\   (   R   R   RW   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_xml_declarationz  s    c         C   s2   d } |  j  |  } |  j | | j d   d  S(   Ns<   <?xml version="1.0" encoding="utf8"?>
<?PITarget PIContent?>R\   (   R   R   RW   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR]     s    c         C   s2   d } |  j  |  } |  j | j d  |  d S(   sG   A 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>s   utf-8N(   R   R   RW   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyRY     s    c         C   s/   d } |  j  |  } |  j | | j    d  S(   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>(   R   R   RW   (   R   t   docR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_nested_namespaces  s    c         C   sD   d } t  | d  } d | j _ | j   } |  j d | k  d  S(   Ns/   
  <script type="text/javascript">
  </script>
s   lxml-xmls   console.log("< < hey > > ");s   &lt; &lt; hey &gt; &gt;(   R   Rg   R}   RW   Rd   (   R   R   R   t   encoded(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt5   test_formatter_processes_script_tag_for_xml_documents  s
    c         C   s/   d } |  j  |  } |  j d | j j  d  S(   Nu?   <?xml version="1.0" encoding="euc-jp"><root>Sacré bleu!</root>u   Sacré bleu!(   R   R   t   rootR}   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR     s    c         C   s2   d } |  j  |  } |  j t | j  |  d  S(   Ns   <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>(   R   R   t   unicodet   rss(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_popping_namespaced_tag  s    c         C   s,   |  j  d  } |  j | j d  d  d  S(   Ns   <root/>t   latin1s/   <?xml version="1.0" encoding="latin1"?>
<root/>(   R   R   RW   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt(   test_docstring_includes_correct_encoding  s    c         C   s>   d d d d } |  j  |  } |  j | j d  |  d S(	   s<   A large XML document should come out the same as it went in.s-   <?xml version="1.0" encoding="utf-8"?>
<root>t   0i   i   s   </root>s   utf-8Ni   (   R   R   RW   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_large_xml_document  s    c         C   s!   |  j  d d  |  j  d  d  S(   Ns   <p>s   <p/>s
   <p>foo</p>(   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt9   test_tags_are_empty_element_if_and_only_if_they_are_empty  s    c         C   sJ   d } |  j  |  } | j } |  j d | d  |  j d | d  d  S(   Ns   <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>s   http://example.com/s   xmlns:as   http://example.net/s   xmlns:b(   R   R   R   (   R   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_namespaces_are_preserved  s
    	c         C   s2   d } |  j  |  } |  j t | j  |  d  S(   NsN   <p xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>20010504</dc:date></p>(   R   R   R   RJ   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_closing_namespaced_tag  s    c         C   s2   d } |  j  |  } |  j t | j  |  d  S(   Nss   <foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><bar xsi:schemaLocation="http://www.example.com"/></foo>(   R   R   R   RE   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_namespaced_attributes  s    c         C   s2   d } |  j  |  } |  j t | j  |  d  S(   Ns   <foo xml:lang="fr">bar</foo>(   R   R   R   RE   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt(   test_namespaced_attributes_xml_namespace  s    c         C   s   d } |  j  |  } |  j d t | j d    |  j d t | j d    |  j d t | j d    |  j d t | j d d d	   |  j d t | j d d g    d  S(
   Ns  <?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>
i   t   tagi   s   ns1:tagi   s   ns2:tagt   keyt   value(   R   R   RI   RZ   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_find_by_prefixed_name  s    	%c         C   sG   d } |  j  |  } | j } t j |  } |  j | j | j  d  S(   Nsf   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://example.com/ns0"/>(   R   t   documentR^   R   t   prefix(   R   t   xmlR   R   t	   duplicate(    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt!   test_copy_tag_preserves_namespace  s
    	(   R!   R"   RD   R   R   R]   RY   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR   j  s$   																			t   HTML5TreeBuilderSmokeTestc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s2   Smoke test for a tree builder that supports HTML5.c         C   s   d  S(   N(    (   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyRY      s    c         C   s/   d } |  j  |  } |  j d | j j  d  S(   Ns   <a>s   http://www.w3.org/1999/xhtml(   R   R   R   t	   namespace(   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_html_tags_have_namespace  s    c         C   sK   d } |  j  |  } d } |  j | | j j  |  j | | j j  d  S(   Ns   <svg><circle/></svg>s   http://www.w3.org/2000/svg(   R   R   t   svgR   t   circle(   R   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_svg_tags_have_namespace
  s
    c         C   sK   d } |  j  |  } d } |  j | | j j  |  j | | j j  d  S(   Ns   <math><msqrt>5</msqrt></math>s"   http://www.w3.org/1998/Math/MathML(   R   R   t   mathR   t   msqrt(   R   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   test_mathml_tags_have_namespace  s
    c         C   sj   d } |  j  |  } |  j t | j d t   |  j | j d d  |  j d | j d j j  d  S(   Ns3   <?xml version="1.0" encoding="utf-8"?><html></html>i    s$   ?xml version="1.0" encoding="utf-8"?RO   (   R   Rd   R   RG   R   R   R   R;   (   R   R   R   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt$   test_xml_declaration_becomes_comment  s
    (   R!   R"   R   RY   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyR     s   				c            s   d       f d   } | S(   Nc         _   s   d  S(   N(   R   (   t   testt   argsR   (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   nothing!  s    c            s     r
  S|  Sd  S(   N(    (   t	   test_item(   t	   conditionR   (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt	   decorator$  s    (    (   R   t   reasonR   (    (   R   R   s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   skipIf   s    	(   R   t   __license__R=   R^   t	   functoolst   unittestR   t   bs4R   t   bs4.elementR   R   R   R   R   t   bs4.builderR   R
   R	   t   objectR$   R   R   R   (    (    (    s/   /usr/lib/python2.7/site-packages/bs4/testing.pyt   <module>   s"   (%  -#