U
    g                     @   sr   d Z ddlZddlZddlmZ ddlmZ G dd deZdddZ	i fd	d
Z
edkrndd Zejdd dS )zgSelf tests

These tests should perform quickly and can ideally be used every time an
application runs.
    N)import_module)StringIOc                   @   s   e Zd Zdd ZdS )SelfTestErrorc                 C   s   t | || || _|| _d S N)	Exception__init__messageresult)selfr   r	    r   @/tmp/pip-unpacked-wheel-_q8s9isk/Cryptodome/SelfTest/__init__.pyr   &   s    zSelfTestError.__init__N)__name__
__module____qualname__r   r   r   r   r   r   %   s   r   c           	      K   s   |dkri }t  }| dkr:|dkr.t|d}|| n$|dkrV|| j|d ntd|dkrrt |d< n||d< t jf d|i|}||}| s|dkrt	j
|d   td||S )a>  Execute self-tests.

    This raises SelfTestError if any test is unsuccessful.

    You may optionally pass in a sub-module of SelfTest if you only want to
    perform some of the tests.  For example, the following would test only the
    hash modules:

        Cryptodome.SelfTest.run(Cryptodome.SelfTest.Hash)

    Nconfigz5'module' and 'tests' arguments are mutually exclusivestream	verbosityzSelf-test failed)unittest	TestSuite	get_testsZaddTests
ValueErrorr   ZTextTestRunnerrunZwasSuccessfulsysstderrwritegetvaluer   )	moduler   r   testsr   kwargssuiterunnerr	   r   r   r   r   ,   s(    


r   c              	   C   sD   g }ddddddddd	g	}|D ] }t d
| }||j| d7 }q|S )NZCipherZHashProtocolZ	PublicKeyRandomZUtil	SignatureIOZMathzCryptodome.SelfTest.r   )r   r   )r   r   Zmodule_namesnamer   r   r   r   r   R   s           r   __main__c                   C   s   t t S r   )r   r   r   r   r   r   r   r    b   s    r    )ZdefaultTest)Nr   NNN)__doc__r   r   	importlibr   ZCryptodome.Util.py3compatr   r   r   r   r   r   r    mainr   r   r   r   <module>   s   
&