
V]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 m Z d d l m Z e Z d 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   SoupStrainert   Tag(   t   HTMLParserTreeBuilderu-
  A bare string
<!DOCTYPE xsl:stylesheet SYSTEM "htmlent.dtd">
<!DOCTYPE xsl:stylesheet PUBLIC "htmlent.dtd">
<div><![CDATA[A CDATA section where it doesn't belong]]></div>
<div><svg><![CDATA[HTML5 does allow CDATA sections in SVG]]></svg></div>
<div>A <meta> tag</div>
<div>A <br> tag that supposedly has contents.</br></div>
<div>AT&T</div>
<div><textarea>Within a textarea, markup like <b> tags and <&<&amp; should be treated as literal</textarea></div>
<div><script>if (i < 2) { alert("<b>Markup within script tags should be treated as literal.</b>"); }</script></div>
<div>This numeric entity is missing the final semicolon: <x t="pi&#241ata"></div>
<div><a href="http://example.com/</a> that attribute value never got closed</div>
<div><a href="foo</a>, </a><a href="bar">that attribute value was closed by the subsequent tag</a></div>
<! This document starts with a bogus declaration ><div>a</div>
<div>This document contains <!an incomplete declaration <div>(do you see it?)</div>
<div>This document ends with <!an incomplete declaration
<div><a style={height:21px;}>That attribute value was bogus</a></div>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">The doctype is invalid because it contains extra whitespace
<div><table><td nowrap>That boolean attribute had no value</td></table></div>
<div>Here's a nonexistent entity: &#foo; (do you see it?)</div>
<div>This document ends before the entity finishes: &gt
<div><p>Paragraphs shouldn't contain block display elements, but this one does: <dl><dt>you see?</dt></p>
<b b="20" a="1" b="10" a="2" a="3" a="4">Multiple values for the same attribute.</b>
<div><table><tr><td>Here's a table</td></tr></table></div>
<div><table id="1"><tr><td>Here's a nested table:<table id="2"><tr><td>foo</td></tr></table></td></div>
<div>This tag contains nothing but whitespace: <b>    </b></div>
<div><blockquote><p><b>This p tag is cut off by</blockquote></p>the end of the blockquote tag</div>
<div><table><div>This table contains bare markup</div></table></div>
<div><div id="1">
 <a href="link1">This link is never closed.
</div>
<div id="2">
 <div id="3">
   <a href="link2">This link is closed.</a>
  </div>
</div></div>
<div>This document contains a <!DOCTYPE surprise>surprise doctype</div>
<div><a><B><Cd><EFG>Mixed case tags are folded to lowercase</efg></CD></b></A></div>
<div><our☃>Tag name contains Unicode characters</our☃></div>
<div><a ☃="snowman">Attribute name contains Unicode characters</a></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
t   SoupTestc           B   sJ   e  Z e d     Z d   Z d   Z d d  Z d   Z e	 d  Z
 RS(   c         C   s   t  S(   N(   t   default_builder(   t   self(    (    s*   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*   lib/python2.7/site-packages/bs4/testing.pyt   soupD   s    c         K   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   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   document_forI   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*   lib/python2.7/site-packages/bs4/testing.pyt   assertSoupEqualsP   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*   lib/python2.7/site-packages/bs4/testing.pyt   assertConnectednessX   s    c   	      C   s/  d } | j d k r | j d k sB t d j | | j d    | j d k so t d j | | j d    | j d k s t d j | | j d    n  d } d } d } t | j  d } x}| j D]r} d } | d k r| j d k	 r| j	 | k s"t d j | | j	 |    | j | k sOt d j | | j |    | j d k st d j | | j d    qn| j | j | d k st d j | | j | j | d    | j | d j | k st d	 j | j | d | j | d j |    | d k	 r| j | k sUt d
 j | | j | | j j    | j	 | k st d j | | j	 |    n  t
 | t  r| j r|  j | t  } | j d k st d	 j | | j d    n  | d k	 r| } n | } | | k r6| j d k s6t d	 j | | j d    n  | d 7} q W| d k	 rV| n | } | d k rq| } n  | r'| d k	 r'| } x t r"| d k r| j	 d k st d j | | j	 d    PnF | j d k	 r| j	 | j k st d j | | j	 | j    Pn  | j } qWd S| Sd S(   s.   Ensure proper linkage throughout the document.s3   Bad previous_element
NODE: {}
PREV: {}
EXPECTED: {}s3   Bad previous_sibling
NODE: {}
PREV: {}
EXPECTED: {}s/   Bad next_sibling
NODE: {}
NEXT: {}
EXPECTED: {}i    i   s/   Bad next_element
NODE: {}
NEXT: {}
EXPECTED: {}s2   Bad previous_sibling
NODE: {}
PREV {}
EXPECTED: {}s1   Bad previous_sibling
NODE: {}
PREV {}
EXPECTED {}s-   Bad next_sibling
NODE: {}
NEXT {}
EXPECTED {}s=   Bad previous_element
NODE: {}
PREV {}
EXPECTED {}
CONTENTS {}s-   Bad next_element
NODE: {}
NEXT {}
EXPECTED {}N(   R   t   parentR   t   AssertionErrort   formatt   previous_siblingt   next_siblingt   lent   contentsR   t
   isinstanceR   t   linkage_validatort   True(	   R   t   elt   _recursive_callt
   descendantt   idxt   childt
   last_childt   last_idxt   target(    (    s*   lib/python2.7/site-packages/bs4/testing.pyR*   c   s     +			N(   t   __name__t
   __module__t   propertyR   R   R   R   R   R!   t   FalseR*   (    (    (    s*   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 d9   Z: d:   Z; d;   Z< RS(<   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   R+   t   is_empty_element(   R   t   nameR   RL   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_empty_element_tags   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*   lib/python2.7/site-packages/bs4/testing.pyt!   test_pickle_and_unpickle_identity   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_doctypeR(   R   RS   R   t   strR'   t   p(   R   t   doctype_fragmentt   doctype_strR   t   doctype(    (    s*   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   R\   R^   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyRY     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(   R_   (   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_normal_doctypes
  s    c         C   s6   |  j  d  } | j d } |  j d | j    d  S(   Ns
   <!DOCTYPE>i    RK   (   R   R(   R   t   strip(   R   R   R^   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_empty_doctype  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"(   R_   (   R   R^   (    (    s*   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/"(   R_   (   R   (    (    s*   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"(   R_   (   R   (    (    s*   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"(   R_   (   R   (    (    s*   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   
RK   N(   R   R   t   encodet   replace(   R   R   R   (    (    s*   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   R'   t   find_all(   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_namespaced_html1  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   Rh   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_processing_instruction9  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*   lib/python2.7/site-packages/bs4/testing.pyt   test_deepcopyF  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   assertFalseR[   RM   R   RZ   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt!   test_p_tag_is_never_empty_elementN  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*   lib/python2.7/site-packages/bs4/testing.pyt   test_unclosed_tags_get_closedX  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;   RM   R   RZ   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt#   test_br_is_always_empty_element_tagb  s    c         C   s   |  j  d  d  S(   Ns   <em><em></em></em>(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_nested_formatting_elementsl  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   R`   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_double_heado  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   foobarRX   t   baz(   R   R   Rz   R   RS   R   R   R   (   R   R   R   t   commentRX   R~   (    (    s*   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*   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*   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   R[   t   bt   string(   R   R   R   (    (    s*   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*   lib/python2.7/site-packages/bs4/testing.pyt   test_correctly_nested_tables  s    c         C   sX   d } |  j  |  } |  j d d g | j d  |  j | j | j d d d  d  S(   Ns   <div class=" foo bar	 "></a>RX   t   bart   classt   divt   class_s   foo bar(   R   R   R   Rz   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt*   test_multivalued_attribute_with_whitespace  s    c         C   s6   d } |  j  |  } |  j d g | j j d  d  S(   Ns1   <table><div><div class="css"></div></div></table>t   cssR   (   R   R   R   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt(   test_deeply_nested_multivalued_attribute  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   R`   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt"   test_multivalued_attribute_on_html  s    c         C   s   |  j  d d  d  S(   Ns   <a b="<a>"></a>s   <a b="&lt;a&gt;"></a>(   R   (   R   (    (    s*   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*   lib/python2.7/site-packages/bs4/testing.pyt3   test_strings_resembling_character_entity_references  s    c         C   s   |  j  d d  d  S(   Nu   <p>Bob&apos;s Bar</p>u   <p>Bob's Bar</p>(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_apos_entity  s    c         C   s/   d } |  j  |  } |  j d | j j  d  S(   Ns%   <p>&#147;Hello&#148; &#45;&#9731;</p>u   “Hello” -☃(   R   t   assertEqualsR[   R   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt*   test_entities_in_foreign_document_encoding  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*   lib/python2.7/site-packages/bs4/testing.pyt0   test_entities_in_attributes_converted_to_unicode   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*   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*   lib/python2.7/site-packages/bs4/testing.pyt,   test_quot_entity_converted_to_quotation_mark  s    	c         C   s:   d } |  j  d |  |  j  d |  |  j  d |  d  S(   Nu   �s   &#10000000000000;s   &#x10000000000000;s   &#1000000000;(   R   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_out_of_range_entity  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>R[   N(   R   R   t   h2R   R   RN   R[   R!   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_multipart_strings  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*   lib/python2.7/site-packages/bs4/testing.pyRO     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   R`   t   bodyR!   (   R   t   contentR   (    (    s*   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*   lib/python2.7/site-packages/bs4/testing.pyt   test_multiple_copies_of_a_tag1  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   Rh   R`   (   R   R   R   R`   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_basic_namespacesB  s    	c         C   s6   d } |  j  |  } |  j d d g | j d  d  S(   Ns   <a class="foo bar">RX   R   R   (   R   R   R   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt-   test_multivalued_attribute_value_becomes_listQ  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*   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*   lib/python2.7/site-packages/bs4/testing.pyt   test_soupstrainere  s    	c         C   s   |  j  d d  d  S(   Ns   <foo attr='bar'></foo>s   <foo attr="bar"></foo>(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt7   test_single_quote_attribute_values_become_double_quotesl  s    	c         C   s   d } |  j  |  d  S(   Ns'   <foo attr='bar "brawls" happen'>a</foo>(   R   (   R   R|   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt7   test_attribute_values_with_nested_quotes_are_left_alonep  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   RX   R   R   (   R   R|   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt:   test_attribute_values_with_double_nested_quotes_get_quotedt  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*   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*   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   R|   t   expected(    (    s*   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   R[   R   (   R   t   quoteR   (    (    s*   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*   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(   Rh   R   R   R[   (   R   R|   R   R   (    (    s*   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(   Rh   R   Ri   R   (   R   t   unicode_htmlt   iso_latin_htmlR   t   resultR   (    (    s*   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   Rh   (   R   t   shift_jis_htmlR   R   (    (    s*   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_encodingR#   R   Rh   R   (   R   t   hebrew_documentR   (    (    s*   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.RD   s   Content-types
   http-equivR   s   text/html; charset=x-sjiss   text/html; charset=utf8Rm   (   R   Rz   R   Ru   R)   R   Rh   (   R   t   meta_tagR   R   t   parsed_metaR   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt'   test_meta_tag_reflects_current_encoding  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.RD   t   idt   encodingt   charsets   x-sjisRm   (   R   Rz   R   Ru   R)   R   Rh   (   R   R   R   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt3   test_html5_style_meta_tag_reflects_current_encoding  s    
c         C   s9   |  j  d  } d | j d <|  j d | j j    d  S(   Ns   <a>text</a>R   RX   s   <a foo="bar">text</a>(   R   R   R   R   (   R   t   data(    (    s*   lib/python2.7/site-packages/bs4/testing.pyt5   test_tag_with_no_attributes_can_have_attributes_added  s    c         C   s    |  j  t  } |  j |  d S(   s3   Test the worst case (currently) for linking issues.N(   R   t   BAD_DOCUMENTR*   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_worst_case  s    (=   R4   R5   t   __doc__RO   RW   R_   RY   Ra   Rc   Rd   Re   Rf   Rg   Rj   Rl   Rn   Rq   Rs   Rt   Rv   Rw   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   R   R   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/testing.pyR8      sx   																
	
	
																																										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 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   RP   RQ   RR   R   RS   R   R   (   R   RT   RU   RV   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyRW     s
    c         C   s)   |  j  d  } |  j | j   d  d  S(   Ns   <root/>s.   <?xml version="1.0" encoding="utf-8"?>
<root/>(   R   R   Rh   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_docstring_generated%  s    c         C   s2   d } |  j  |  } |  j | | j d   d  S(   Ns,   <?xml version="1.0" encoding="utf8"?>
<foo/>Rm   (   R   R   Rh   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_xml_declaration*  s    c         C   s2   d } |  j  |  } |  j | | j d   d  S(   Ns<   <?xml version="1.0" encoding="utf8"?>
<?PITarget PIContent?>Rm   (   R   R   Rh   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyRn   /  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   Rh   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyRj   4  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   Rh   (   R   t   docR   (    (    s*   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   Rx   R   Rh   Ru   (   R   R   R   t   encoded(    (    s*   lib/python2.7/site-packages/bs4/testing.pyt5   test_formatter_processes_script_tag_for_xml_documentsK  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*   lib/python2.7/site-packages/bs4/testing.pyR   W  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*   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   Rh   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt(   test_docstring_includes_correct_encodingb  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   Rh   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   test_large_xml_documenth  s    c         C   s!   |  j  d d  |  j  d  d  S(   Ns   <p>s   <p/>s
   <p>foo</p>(   R   (   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt9   test_tags_are_empty_element_if_and_only_if_they_are_emptyq  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*   lib/python2.7/site-packages/bs4/testing.pyt   test_namespaces_are_preservedu  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   R[   (   R   R   R   (    (    s*   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   RX   (   R   R   R   (    (    s*   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   RX   (   R   R   R   (    (    s*   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   R'   Rk   (   R   R   R   (    (    s*   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   documentRo   R   t   prefix(   R   t   xmlR   R   t	   duplicate(    (    s*   lib/python2.7/site-packages/bs4/testing.pyt!   test_copy_tag_preserves_namespace  s
    	c         C   s    |  j  t  } |  j |  d S(   s3   Test the worst case (currently) for linking issues.N(   R   R   R*   (   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyR     s    (   R4   R5   RW   R   R   Rn   Rj   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/bs4/testing.pyR     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*   lib/python2.7/site-packages/bs4/testing.pyRj     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*   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*   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*   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"?R`   (   R   Ru   R)   R(   R   R   R   RN   (   R   R   R   (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt$   test_xml_declaration_becomes_comment  s
    (   R4   R5   R   Rj   R   R   R   R   (    (    (    s*   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*   lib/python2.7/site-packages/bs4/testing.pyt   nothing  s    c            s     r
  S|  Sd  S(   N(    (   t	   test_item(   t	   conditionR   (    s*   lib/python2.7/site-packages/bs4/testing.pyt	   decorator  s    (    (   R  t   reasonR  (    (   R  R   s*   lib/python2.7/site-packages/bs4/testing.pyt   skipIf  s    	(   R   t   __license__RP   Ro   t	   functoolst   unittestR   t   bs4R   t   bs4.elementR   R   R   R   R   R   t   bs4.builderR	   R   R   R
   t   objectR8   R   R   R  (    (    (    s*   lib/python2.7/site-packages/bs4/testing.pyt   <module>   s$   .	$  F#