U
    }ÄúgÈ  ã                   @   s¤   d 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 ddlmZ ddlmZmZ erldd	lmZ er€dd
lmZmZ G dd„ deƒZG dd„ deƒZdS )zTests of the builder registry.é    N)ÚType)ÚBeautifulSoup)Úbuilder_registryÚTreeBuilderÚTreeBuilderRegistry)ÚHTMLParserTreeBuilderé   )ÚHTML5LIB_PRESENTÚLXML_PRESENT)ÚHTML5TreeBuilder)ÚLXMLTreeBuilderForXMLÚLXMLTreeBuilderc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTestBuiltInRegistryz@Test the built-in registry with the default builders registered.c                 C   s\   t  dd¡tkst‚tr@t  dd¡tks,t‚t  dd¡tks@t‚trXt  dd¡tksXt‚d S )NÚstrictÚhtmlÚfastZ
permissiveÚxmlÚhtml5lib)	ÚregistryÚlookupr   ÚAssertionErrorr
   r   r   r	   r   ©Úself© r   úC/tmp/pip-unpacked-wheel-kgiupv3k/bs4/tests/test_builder_registry.pyÚtest_combination#   s    z$TestBuiltInRegistry.test_combinationc                 C   sj   t r*t d¡tkst‚t d¡tksft‚n<t d¡d ks<t‚trTt d¡tksft‚nt d¡tksft‚d S )Nr   r   )	r
   r   r   r   r   r   r	   r   r   r   r   r   r   Útest_lookup_by_markup_type+   s    z.TestBuiltInRegistry.test_lookup_by_markup_typec                 C   sX   t r,t dd¡tkst‚t dd¡tks,t‚trBt d¡tksBt‚t d¡tksTt‚d S )NÚlxmlr   r   r   zhtml.parser)	r
   r   r   r   r   r   r	   r   r   r   r   r   r   Útest_named_library6   s    z&TestBuiltInRegistry.test_named_libraryc              	   C   sZ   t jdd" tddd tdddgd W 5 Q R X t t¡ tddd W 5 Q R X d S )NT)ÚrecordÚ r   )Úfeaturesr   zno-such-feature)ÚwarningsÚcatch_warningsr   ÚpytestZraisesÚ
ValueErrorr   r   r   r   Ú*test_beautifulsoup_constructor_does_lookup?   s    
z>TestBuiltInRegistry.test_beautifulsoup_constructor_does_lookupN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r   r   r   r   r       s
   	r   c                   @   sd   e Zd ZdZdd„ Zeee dœ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 )ÚTestRegistryz.Test the TreeBuilderRegistry class in general.c                 C   s   t ƒ | _d S ©N)r   r   r   r   r   r   Úsetup_methodS   s    zTestRegistry.setup_method)Úfeature_listÚreturnc                 G   s,   t dd |¡ tfd|iƒ}| j |¡ |S )NZBuilder_Ú_r!   )ÚtypeÚjoinÚobjectr   Úregister)r   r.   Úclsr   r   r   Úbuilder_for_featuresV   s      ÿz!TestRegistry.builder_for_featuresc                 C   s2   |   ¡ }| j d¡d kst‚| j ¡ |ks.t‚d S )NÚfoo©r6   r   r   r   ©r   Zbuilderr   r   r   Útest_register_with_no_features^   s    z+TestRegistry.test_register_with_no_featuresc                 C   s8   |   dd¡}| j d¡|ks t‚| j d¡|ks4t‚d S ©Nr7   Úbarr8   r9   r   r   r   Ú0test_register_with_features_makes_lookup_succeedi   s    z=TestRegistry.test_register_with_features_makes_lookup_succeedc                 C   s   | j  d¡d kst‚d S )NÚbaz©r   r   r   r   r   r   r   Ú4test_lookup_fails_when_no_builder_implements_featuren   s    zATestRegistry.test_lookup_fails_when_no_builder_implements_featurec                 C   s*   |   d¡ |   d¡}| j ¡ |ks&t‚d S r;   r8   )r   Zbuilder2r   r   r   ÚCtest_lookup_gets_most_recent_registration_when_no_feature_specifiedq   s    

zPTestRegistry.test_lookup_gets_most_recent_registration_when_no_feature_specifiedc                 C   s   | j  ¡ d kst‚d S r,   r?   r   r   r   r   Ú2test_lookup_fails_when_no_tree_builders_registeredv   s    z?TestRegistry.test_lookup_fails_when_no_tree_builders_registeredc                 C   sv   |   d¡ |   d¡ |   ddd¡}|   ddd¡}|   d¡ |   d¡ | j dd¡|ksZt‚| j ddd¡|ksrt‚d S )Nr7   r<   r>   Zquuxr8   )r   Zhas_both_earlyZhas_both_later   r   r   Ú<test_lookup_gets_most_recent_builder_supporting_all_featuresy   s    



zITestRegistry.test_lookup_gets_most_recent_builder_supporting_all_featuresc                 C   s2   |   dd¡ |   dd¡ | j dd¡d ks.t‚d S )Nr7   r<   r>   r8   r   r   r   r   Ú:test_lookup_fails_when_cannot_reconcile_requested_featuresˆ   s    zGTestRegistry.test_lookup_fails_when_cannot_reconcile_requested_featuresN)r'   r(   r)   r*   r-   Ústrr   r   r6   r:   r=   r@   rA   rB   rC   rD   r   r   r   r   r+   P   s   r+   )r*   r$   r"   Útypingr   Zbs4r   Zbs4.builderr   r   r   r   Zbs4.builder._htmlparserr   r    r	   r
   Zbs4.builder._html5libr   Zbs4.builder._lxmlr   r   r3   r   r+   r   r   r   r   Ú<module>   s   0