ó
­V]c           @   s¡   d  Z  d d l Z y d d l m Z e Z Wn e k
 rG Z e Z n Xd d l	 m
 Z
 d d l m Z m Z m Z e e d ƒ d e e f d „  ƒ  Yƒ Z d S(	   sD   Tests to ensure that the html5lib tree builder generates good trees.iÿÿÿÿN(   t   HTML5TreeBuilder(   t   SoupStrainer(   t   HTML5TreeBuilderSmokeTestt   SoupTestt   skipIfs?   html5lib seems not to be present, not testing its tree builder.t   HTML5LibBuilderSmokeTestc           B   s‰   e  Z d  Z e 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(   s"   See ``HTML5TreeBuilderSmokeTest``.c         C   s   t  S(   N(   R    (   t   self(    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   default_builder   s    c         C   s…   t  d ƒ } d } t j d t ƒ  } |  j | d | ƒ} Wd  QX|  j | j ƒ  |  j | ƒ ƒ |  j d t	 | d j
 ƒ k ƒ d  S(   Nt   bs   <p>A <b>bold</b> statement.</p>t   recordt
   parse_onlys4   the html5lib tree builder doesn't support parse_onlyi    (   R   t   warningst   catch_warningst   Truet   soupt   assertEqualt   decodet   document_fort
   assertTruet   strt   message(   R   t   strainert   markupt   wR   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_soupstrainer   s    c         C   s'   d } |  j  | d ƒ |  j  d ƒ d S(   s8   html5lib inserts <tbody> tags where other parsers don't.s[   <table id="1"><tr><td>Here's another table:<table id="2"><tr><td>foo</td></tr></table></td>s†   <table id="1"><tbody><tr><td>Here's another table:<table id="2"><tbody><tr><td>foo</td></tr></tbody></table></td></tr></tbody></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(   t   assertSoupEquals(   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_correctly_nested_tables(   s    c         C   s2   d } |  j  | ƒ } |  j d | j j ƒ  ƒ d  S(   Nsy   <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
   <p>foo</p>
  </body>
</html>s
   <p>foo</p>(   R   R   t   pt   encode(   R   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt(   test_xml_declaration_followed_by_doctype<   s    	c         C   sQ   d } |  j  | ƒ } |  j d | j j ƒ  ƒ |  j d t | j d ƒ ƒ ƒ d  S(   Ns%   <p><em>foo</p>
<p>bar<a></a></em></p>uD   <body><p><em>foo</em></p><em>
</em><p><em>bar<a></a></em></p></body>i   R   (   R   R   t   bodyR   t   lent   find_all(   R   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_reparented_markupJ   s    c         C   sQ   d } |  j  | ƒ } |  j d | j j ƒ  ƒ |  j d t | j d ƒ ƒ ƒ d  S(   Ns&   <p><em>foo</p>
<p>bar<a></a></em></p>
uE   <body><p><em>foo</em></p><em>
</em><p><em>bar<a></a></em></p>
</body>i   R   (   R   R   R   R   R   R    (   R   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt+   test_reparented_markup_ends_with_whitespaceQ   s    c         C   sp   d } |  j  | ƒ } | j d d ƒ \ } } | j d ƒ \ } } | j | k sW t ‚ | j | k sl t ‚ d S(   sƒ   Verify that we keep the two whitespace nodes in this
        document distinct when reparenting the adjacent <tbody> tags.
        s,   <table> <tbody><tbody><ims></tbody> </table>t   stringt    t   tbodyN(   R   R    t   next_elementt   AssertionError(   R   R   R   t   space1t   space2t   tbody1t   tbody2(    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt<   test_reparented_markup_containing_identical_whitespace_nodesW   s    c         C   sƒ   d } |  j  | ƒ } | j } |  j d | j ƒ | j d d ƒ } | j d d ƒ d } |  j | | j ƒ |  j | | j ƒ d  S(   NsF   <div><a>aftermath<p><noscript>target</noscript>aftermath</a></p></div>t   targetR#   t	   aftermathiÿÿÿÿ(   R   t   noscriptR   R&   t   findR    t   previous_element(   R   R   R   R/   R-   t   final_aftermath(    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt*   test_reparented_markup_containing_childrenb   s    	c         C   s4   d } |  j  | ƒ } t | ƒ j d ƒ s0 t ‚ d S(   s(   Processing instructions become comments.s   <?PITarget PIContent?>s   <!--?PITarget PIContent?-->N(   R   R   t
   startswithR'   (   R   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_processing_instructionr   s    c         C   sP   d } |  j  | ƒ } | j d ƒ \ } } |  j | | ƒ | | k	 sL t ‚ d  S(   Ns   <a class="my_class"><p></a>t   a(   R   R    R   R'   (   R   R   R   t   a1t   a2(    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_cloned_multivalue_nodex   s
    c         C   s2   d } |  j  | ƒ } |  j d | j j ƒ  ƒ d  S(   Ns   <table><td></tbody>Au>   <body>A<table><tbody><tr><td></td></tr></tbody></table></body>(   R   R   R   R   (   R   R   R   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_foster_parenting   s    c         C   s~   d } |  j  | ƒ } g  | d ƒ D] } | j ƒ  ^ q" g  | d ƒ D] } | j ƒ  ^ qE |  j t | j d ƒ ƒ d ƒ d S(   s€   
        Test that extraction does not destroy the tree.

        https://bugs.launchpad.net/beautifulsoup/+bug/1782928
        sW   
<html><head></head>
<style>
</style><script></script><body><p>hello</p></body></html>
t   scriptt   styleR   i   N(   R   t   extractR   R   R    (   R   R   R   t   s(    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_extraction„   s
    ##c         C   se   d } |  j  | ƒ } g  } x- | j d ƒ D] } | j | j d ƒ ƒ q+ W|  j t | ƒ d ƒ d S(   s‚   
        Test that empty comment does not break structure.

        https://bugs.launchpad.net/beautifulsoup/+bug/1806598
        sI   
<html>
<body>
<form>
<!----><input type="text">
</form>
</body>
</html>
t   formt   inputi   N(   R   R    t   extendR   R   (   R   R   R   t   inputsR@   (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   test_empty_comment–   s    (   t   __name__t
   __module__t   __doc__t   propertyR   R   R   R   R!   R"   R,   R3   R5   R9   R:   R?   RD   (    (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyR      s   											(   RG   R   t   bs4.builderR    R   t   HTML5LIB_PRESENTt   ImportErrort   et   Falset   bs4.elementR   t   bs4.testingR   R   R   R   (    (    (    s6   lib/python2.7/site-packages/bs4/tests/test_html5lib.pyt   <module>   s   

	