o
    üeÎ  ã                   @   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	 z
ddlm
Z
 dZW n ey/   dZY nw zddlmZmZ dZW n eyG   dZY nw 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   sd   t r|  t dd¡t¡ t r|  t dd¡t¡ |  t dd¡t¡ tr0|  t dd¡t¡ d S d S )NÚfastÚhtmlZ
permissiveÚxmlÚstrictÚhtml5lib)	ÚLXML_PRESENTÚassertEqualÚregistryÚlookupr   r   r   ÚHTML5LIB_PRESENTr   ©Úself© r   úOD:\Projects\ConvertPro\env\Lib\site-packages\bs4/tests/test_builder_registry.pyÚtest_combination    s    ÿÿÿÿÿz$BuiltInRegistryTest.test_combinationc                 C   sn   t r|  t d¡t¡ |  t d¡t¡ d S |  t d¡d ¡ tr,|  t d¡t¡ d S |  t 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|  t dd¡t¡ |  t dd¡t¡ tr!|  t d¡t¡ |  t 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   s^   t jdd}tddd tdddgd W d   ƒ n1 sw   Y  | jttddd d S )NT)ÚrecordÚ r   )Úfeaturesr
   zno-such-feature)ÚwarningsÚcatch_warningsr   Ú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 |¡ tfd|iƒ}| 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 d¡d ¡ |  | j ¡ |¡ d S )NÚfoo©r1   r   r   r   ©r   Zbuilderr   r   r   Útest_register_with_no_featuresc   s   z+RegistryTest.test_register_with_no_featuresc                 C   s8   |   dd¡}|  | j d¡|¡ |  | j d¡|¡ d S ©Nr2   Úbarr3   r4   r   r   r   Ú0test_register_with_features_makes_lookup_succeedn   s   z=RegistryTest.test_register_with_features_makes_lookup_succeedc                 C   s$   |   dd¡}|  | j d¡d ¡ d S ©Nr2   r7   Úbazr3   r4   r   r   r   Ú4test_lookup_fails_when_no_builder_implements_features   s   zARegistryTest.test_lookup_fails_when_no_builder_implements_featurec                 C   s*   |   d¡}|   d¡}|  | j ¡ |¡ d S r6   r3   ©r   Zbuilder1Z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 ¡ d ¡ d S r)   )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   |   d¡}|   d¡}|   ddd¡}|   ddd¡}|   d¡}|   d¡}|  | j dd¡|¡ |  | j ddd¡|¡ d S )Nr2   r7   r:   Zquuxr3   )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   |   dd¡}|   dd¡}|  | j dd¡d ¡ d S r9   r3   r<   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*   r1   r5   r8   r;   r=   r>   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