a
    kÄ#dŒ  ã                   @   sl   d dl Z d dlmZmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ G dd„ deƒZdS )	é    N)ÚAnyÚUnionÚListÚTypeÚSetÚcast)Úlog_automotive)ÚGraph)ÚAutomotiveTestCaseABC)ÚStagedAutomotiveTestCasec                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )Ú'AutomotiveTestCaseExecutorConfigurationa€  
    Configuration storage for AutomotiveTestCaseExecutor.

    The following keywords are used in the AutomotiveTestCaseExecutor:
        verbose: Enables verbose output and logging
        debug:  Will raise Exceptions on internal errors

    :param test_cases: List of AutomotiveTestCase classes or instances.
                       Classes will get instantiated in this initializer.
    :param kwargs: Configuration for every AutomotiveTestCase in test_cases
                   and for the AutomotiveTestCaseExecutor. TestCase local
                   configuration and global configuration for all TestCase
                   objects are possible. All keyword arguments given will
                   be stored for every TestCase. To define a local
                   configuration for one TestCase only, the keyword
                   arguments need to be provided in a dictionary.
                   To assign a configuration dictionary to a TestCase, the
                   keyword need to identify the TestCase by the following
                   pattern.
                   ``MyTestCase_kwargs={"someConfig": 42}``
                   The keyword is composed from the TestCase class name and
                   the postfix '_kwargs'.

    Example:
        >>> config = AutomotiveTestCaseExecutorConfiguration([MyTestCase], global_config=42, MyTestCase_kwargs={"localConfig": 1337})  # noqa: E501
    c                 C   s   || j |< d S ©N©Ú__dict__)ÚselfÚkeyÚvalue© r   úe/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/contrib/automotive/scanner/configuration.pyÚ__setitem__-   s    z3AutomotiveTestCaseExecutorConfiguration.__setitem__c                 C   s
   | j | S r   r   )r   r   r   r   r   Ú__getitem__1   s    z3AutomotiveTestCaseExecutorConfiguration.__getitem__c                 C   sŽ   || j v rd S | j  |¡ |jd }|  |j| j |tƒ ¡¡ |  |j¡}| j ¡ D ]&\}}d|v rfqT|| 	¡ vrT|||< qT|  |j|¡ d S )NÚ_kwargs)
Útest_case_clssÚaddÚ__name__Ú__setattr__Úglobal_kwargsÚpopÚdictÚ__getattribute__ÚitemsÚkeys)r   Ztest_case_clsZkwargs_nameÚvalZ
kwargs_keyZ
kwargs_valr   r   r   Ú_generate_test_case_config5   s    

ÿ
zBAutomotiveTestCaseExecutorConfiguration._generate_test_case_configc                 C   sÈ   t  |¡r^tttt tt f |ƒ}t|tƒr<|  |ƒ ¡ qÄt|tƒrT|  |ƒ ¡ qÄt	dƒ‚nft
|tƒr¼| j |¡ |  |j¡ t
|tƒrÄ| j |¡ |jD ]}| j |¡ |  |j¡ qœnt	dƒ‚d S )Nz[Provided class is not in Union[Type[AutomotiveTestCaseABC], Type[StagedAutomotiveTestCase]]zOProvided instance or class of StagedAutomotiveTestCase or AutomotiveTestCaseABC)ÚinspectÚisclassr   r   r   r
   r   Ú
issubclassÚadd_test_caseÚ	TypeErrorÚ
isinstanceÚ
test_casesÚappendr#   Ú	__class__ÚstagesÚstaged_test_cases)r   Z	test_caseZtest_case_classÚtcr   r   r   r'   J   s0    

ÿþ

ÿ


ÿz5AutomotiveTestCaseExecutorConfiguration.add_test_casec                 K   s†   |  dd¡| _|  dd¡| _| dd¡| _tƒ | _tƒ | _tƒ | _	tƒ | _
tƒ | _|| _|D ]}|  |¡ q\t d¡ t | j¡ d S )NÚverboseFÚdebugÚunittestz'The following configuration was created)Úgetr0   r1   r   r2   r	   Zstate_graphÚlistr*   r-   r.   Úsetr   r   r'   r   r   )r   r*   Úkwargsr/   r   r   r   Ú__init__g   s    
z0AutomotiveTestCaseExecutorConfiguration.__init__N)	r   Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r'   r7   r   r   r   r   r      s   r   )r$   Zscapy.compatr   r   r   r   r   r   Zscapy.contrib.automotiver   Z&scapy.contrib.automotive.scanner.graphr	   Z*scapy.contrib.automotive.scanner.test_caser
   Z1scapy.contrib.automotive.scanner.staged_test_caser   Úobjectr   r   r   r   r   Ú<module>	   s    