
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
cT                 @   s   d Z ddlZddlZddlmZ ddlmZmZm	Z	 yddlm
Z
 dZW n ek
r`   dZY nX yddlmZmZ dZW n ek
r   dZY nX G d	d
 d
ejZG dd dejZdS )zTests of the builder registry.    N)BeautifulSoup)builder_registryHTMLParserTreeBuilderTreeBuilderRegistry)HTML5TreeBuilderTF)LXMLTreeBuilderForXMLLXMLTreeBuilderc               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )BuiltInRegistryTestz@Test the built-in registry with the default builders registered.c             C   s`   t r| jtjddt t r0| jtjddt | jtjddt tr\| jtjddt d S )NfasthtmlZ
permissivexmlstricthtml5lib)	LXML_PRESENTassertEqualregistrylookupr   r   r   HTML5LIB_PRESENTr   )self r   +/usr/lib/python3.6/test_builder_registry.pytest_combination    s    z$BuiltInRegistryTest.test_combinationc             C   sj   t r*| jtjdt | jtjdt n<| jtjdd  trT| jtjdt n| jtjdt d S )Nr   r   )	r   r   r   r   r   r   r   r   r   )r   r   r   r   test_lookup_by_markup_type.   s    z.BuiltInRegistryTest.test_lookup_by_markup_typec             C   sX   t r,| jtjddt | jtjddt trB| jtjdt | jtjdt d S )NZlxmlr   r   r   zhtml.parser)	r   r   r   r   r   r   r   r   r   )r   r   r   r   test_named_library9   s    z&BuiltInRegistryTest.test_named_libraryc             C   sJ   t jdd"}tddd tdddgd W d Q R X | jttddd d S )NT)record r   )featuresr
   zno-such-feature)warningscatch_warningsr   ZassertRaises
ValueError)r   wr   r   r   *test_beautifulsoup_constructor_does_lookupF   s
    z>BuiltInRegistryTest.test_beautifulsoup_constructor_does_lookupN)__name__
__module____qualname____doc__r   r   r   r!   r   r   r   r   r	      s
   r	   c               @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )RegistryTestz.Test the TreeBuilderRegistry class in general.c             C   s   t  | _d S )N)r   r   )r   r   r   r   setUpY   s    zRegistryTest.setUpc             G   s,   t ddj| tfd|i}| jj| |S )NZBuilder__r   )typejoinobjectr   register)r   Zfeature_listclsr   r   r   builder_for_features\   s    z!RegistryTest.builder_for_featuresc             C   s2   | j  }| j| jjdd  | j| jj | d S )Nfoo)r.   r   r   r   )r   builderr   r   r   test_register_with_no_featuresc   s    z+RegistryTest.test_register_with_no_featuresc             C   s8   | j dd}| j| jjd| | j| jjd| d S )Nr/   bar)r.   r   r   r   )r   r0   r   r   r   0test_register_with_features_makes_lookup_succeedn   s    z=RegistryTest.test_register_with_features_makes_lookup_succeedc             C   s$   | j dd}| j| jjdd  d S )Nr/   r2   baz)r.   r   r   r   )r   r0   r   r   r   4test_lookup_fails_when_no_builder_implements_features   s    zARegistryTest.test_lookup_fails_when_no_builder_implements_featurec             C   s*   | j d}| j d}| j| jj | d S )Nr/   r2   )r.   r   r   r   )r   builder1builder2r   r   r   Ctest_lookup_gets_most_recent_registration_when_no_feature_specifiedw   s    

zPRegistryTest.test_lookup_gets_most_recent_registration_when_no_feature_specifiedc             C   s   | j | jj d  d S )N)r   r   r   )r   r   r   r   2test_lookup_fails_when_no_tree_builders_registered|   s    z?RegistryTest.test_lookup_fails_when_no_tree_builders_registeredc             C   sv   | j d}| j d}| j ddd}| j ddd}| j d}| j d}| j| jjdd| | j| jjddd| d S )Nr/   r2   r4   Zquux)r.   r   r   r   )r   Zhas_oneZhas_the_otherZhas_both_earlyZhas_both_lateZ	lacks_oner   r   r   <test_lookup_gets_most_recent_builder_supporting_all_features   s    



zIRegistryTest.test_lookup_gets_most_recent_builder_supporting_all_featuresc             C   s2   | j dd}| j dd}| j| jjddd  d S )Nr/   r2   r4   )r.   r   r   r   )r   r6   r7   r   r   r   :test_lookup_fails_when_cannot_reconcile_requested_features   s    zGRegistryTest.test_lookup_fails_when_cannot_reconcile_requested_featuresN)r"   r#   r$   r%   r'   r.   r1   r3   r5   r8   r9   r:   r;   r   r   r   r   r&   V   s   r&   )r%   Zunittestr   Zbs4r   Zbs4.builderr   r   r   r   r   r   ImportErrorr   r   r   ZTestCaser	   r&   r   r   r   r   <module>   s    

9