o
    .j
                     @   s*   d Z ddlZddlmZ G dd dZdS )z&Tests for Component.register() method.    N)	Componentc                   @   s@   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S )TestComponentRegisterz!Test Component.register() method.c                 C   sX   G dd dt }t | t d}||u sJ | }|jdks"J | dks*J dS )z'Register a custom component and use it.c                   @      e Zd ZdZdd ZdS )zJTestComponentRegister.test_register_custom_component.<locals>.XMyComponentX-MY-COMPONENTc                 S   s   dS )Ncustom_value selfr   r   \/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/test_component_register.pycustom_method   s   zXTestComponentRegister.test_register_custom_component.<locals>.XMyComponent.custom_methodN)__name__
__module____qualname__namer   r   r   r   r
   XMyComponent       r   r   r   N)r   registerget_component_classr   r   )r	   r   	retrievedcompr   r   r
   test_register_custom_component   s   

z4TestComponentRegister.test_register_custom_componentc                 C   N   G dd dt }tjtdd t | W d   dS 1 s w   Y  dS )z?Registering component without name attribute raises ValueError.c                   @   s   e Zd ZdS )zWTestComponentRegister.test_register_component_without_name_raises.<locals>.BadComponentN)r   r   r   r   r   r   r
   BadComponent"   s    r   must have a 'name' attributematchNr   pytestraises
ValueErrorr   r	   r   r   r   r
   +test_register_component_without_name_raises      "zATestComponentRegister.test_register_component_without_name_raisesc                 C   r   )z7Registering component with None name raises ValueError.c                   @   s   e Zd ZdZdS )zYTestComponentRegister.test_register_component_with_none_name_raises.<locals>.BadComponentNr   r   r   r   r   r   r   r
   r   +       r   r   r   Nr   r    r   r   r
   -test_register_component_with_none_name_raises(   r"   zCTestComponentRegister.test_register_component_with_none_name_raisesc                 C   sh   G dd dt }G dd dt }t | tjtdd t | W d   dS 1 s-w   Y  dS )z8Registering same component name twice raises ValueError.c                   @      e Zd ZdZdS )zSTestComponentRegister.test_register_duplicate_component_raises.<locals>.XComponent1X-DUPLICATENr#   r   r   r   r
   XComponent14   r$   r(   c                   @   r&   )zSTestComponentRegister.test_register_duplicate_component_raises.<locals>.XComponent2r'   Nr#   r   r   r   r
   XComponent27   r$   r)   zalready registeredr   N)r   r   r   r   r   )r	   r(   r)   r   r   r
   (test_register_duplicate_component_raises1   s   
"z>TestComponentRegister.test_register_duplicate_component_raisesc                 C   s(   G dd dt }t | t | dS )z?Registering the exact same class twice is allowed (idempotent).c                   @   r&   )zPTestComponentRegister.test_register_same_class_twice_allowed.<locals>.XComponentzX-IDEMPOTENTNr#   r   r   r   r
   
XComponentB   r$   r+   N)r   r   )r	   r+   r   r   r
   &test_register_same_class_twice_allowed?   s   
z<TestComponentRegister.test_register_same_class_twice_allowedc                 C   s\   G dd dt }t | d}t |}t||sJ |jdks"J t| dks,J dS )z3Parsing uses the registered custom component class.c                   @   r   )zKTestComponentRegister.test_parse_uses_registered_component.<locals>.XVendorX-VENDORc                 S   s
   |  dS )NzX-VENDOR-ID)getr   r   r   r
   get_vendor_idN   s   
zYTestComponentRegister.test_parse_uses_registered_component.<locals>.XVendor.get_vendor_idN)r   r   r   r   r/   r   r   r   r
   XVendorK   r   r0   s9   BEGIN:X-VENDOR
UID:123
X-VENDOR-ID:vendor-1
END:X-VENDOR
r-   zvendor-1N)r   r   	from_ical
isinstancer   strr/   )r	   r0   	ical_datar   r   r   r
   $test_parse_uses_registered_componentH   s   

z:TestComponentRegister.test_parse_uses_registered_componentN)
r   r   r   __doc__r   r!   r%   r*   r,   r5   r   r   r   r
   r      s    			r   )r6   r   	icalendarr   r   r   r   r   r
   <module>   s    