o
    _"<fÌ  ã                   @   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ƒZG dd„ deƒ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 )ÚTestBuiltInRegistryz@Test the built-in registry with the default builders registered.c                 C   s`   t  dd¡tks
J ‚tr t  dd¡tksJ ‚t  dd¡tks J ‚tr,t  dd¡tks.J ‚d S d S )NÚstrictÚhtmlÚfastÚ
permissiveÚxmlÚhtml5lib)ÚregistryÚlookupr   ÚLXML_PRESENTr   r   ÚHTML5LIB_PRESENTr   ©Úself© r   úV/var/www/html/kck/venv/lib/python3.10/site-packages/bs4/tests/test_builder_registry.pyÚtest_combination    s   ÿz$TestBuiltInRegistry.test_combinationc                 C   sn   t rt d¡tksJ ‚t d¡tksJ ‚d S t d¡d ksJ ‚tr,t d¡tks*J ‚d S t d¡tks5J ‚d S )Nr   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J ‚t dd¡tksJ ‚tr!t d¡tks!J ‚t d¡tks*J ‚d S )NÚlxmlr   r   r   zhtml.parser)r   r   r   r   r   r   r   r   r   r   r   r   Útest_named_library3   s   z&TestBuiltInRegistry.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  t t¡ tddd W d   ƒ d S 1 s;w   Y  d S )NT)ÚrecordÚ r   )Úfeaturesr   zno-such-feature)ÚwarningsÚcatch_warningsr   ÚpytestÚraisesÚ
ValueError)r   Úwr   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                   @   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 )ÚTestRegistryz.Test the TreeBuilderRegistry class in general.c                 C   s   t ƒ | _d S ©N)r   r   r   r   r   r   Úsetup_methodP   s   zTestRegistry.setup_methodc                 G   s,   t dd |¡ tfd|iƒ}| j |¡ |S )NÚBuilder_Ú_r   )ÚtypeÚjoinÚobjectr   Úregister)r   Úfeature_listÚclsr   r   r   Úbuilder_for_featuresS   s
   
ÿz!TestRegistry.builder_for_featuresc                 C   s2   |   ¡ }| j d¡d u sJ ‚| j ¡ |ksJ ‚d S )NÚfoo©r5   r   r   ©r   Úbuilderr   r   r   Útest_register_with_no_featuresZ   s   z+TestRegistry.test_register_with_no_featuresc                 C   s8   |   dd¡}| j d¡|u sJ ‚| j d¡|u sJ ‚d S ©Nr6   Úbarr7   r8   r   r   r   Ú0test_register_with_features_makes_lookup_succeede   s   z=TestRegistry.test_register_with_features_makes_lookup_succeedc                 C   s$   |   dd¡}| j d¡d u sJ ‚d S ©Nr6   r<   Úbazr7   r8   r   r   r   Ú4test_lookup_fails_when_no_builder_implements_featurej   s   zATestRegistry.test_lookup_fails_when_no_builder_implements_featurec                 C   s*   |   d¡}|   d¡}| j ¡ |ksJ ‚d S r;   r7   ©r   Úbuilder1Úbuilder2r   r   r   ÚCtest_lookup_gets_most_recent_registration_when_no_feature_specifiedn   s   

zPTestRegistry.test_lookup_gets_most_recent_registration_when_no_feature_specifiedc                 C   s   | j  ¡ d u s	J ‚d S r+   )r   r   r   r   r   r   Ú2test_lookup_fails_when_no_tree_builders_registereds   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s-J ‚| j ddd¡|ks9J ‚d S )Nr6   r<   r?   Úquuxr7   )r   Úhas_oneÚhas_the_otherÚhas_both_earlyÚhas_both_lateÚ	lacks_oner   r   r   Ú<test_lookup_gets_most_recent_builder_supporting_all_featuresv   s   



zITestRegistry.test_lookup_gets_most_recent_builder_supporting_all_featuresc                 C   s2   |   dd¡}|   dd¡}| j dd¡d u sJ ‚d S r>   r7   rA   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,   r5   r:   r=   r@   rD   rE   rL   rM   r   r   r   r   r*   M   s    r*   )r)   r!   r   Úbs4r   Úbs4.builderr   r   r   r   r   r   ÚImportErrorr   r   r   r1   r	   r*   r   r   r   r   Ú<module>   s&    ÿÿ0