a
    �Ï?e›o  ã                   @   sF  d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd d	lmZmZ d d
lmZmZmZ d dlmZmZ e ¡ �& e d¡ d dlm Z  W d  ƒ n1 sð0    Y  dd„ Z!dd„ Z"dd„ Z#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&dS )é    )Úredirect_stderrÚredirect_stdout)Úmetadata)ÚStringIO)ÚJSONDecodeError)ÚPath)Údedent)ÚTestCaseN)ÚDraft4ValidatorÚDraft202012Validator)ÚSchemaErrorÚValidationErrorÚ_RefResolutionError)Ú_LATEST_VERSIONÚvalidateÚignore)Úclic                     s"   t tˆ ƒƒ‰ G ‡ fdd„dƒ}|S )Nc                       s,   e Zd Zdd„ Z‡ fdd„Zedd„ ƒZdS )z%fake_validator.<locals>.FakeValidatorc                 _   s   d S ©N© )ÚselfÚargsÚkwargsr   r   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jsonschema/tests/test_cli.pyÚ__init__    s    z.fake_validator.<locals>.FakeValidator.__init__c                    s   ˆ rˆ   ¡ S g S r   )Úpop©r   Úinstance©Úerrorsr   r   Úiter_errors#   s    z1fake_validator.<locals>.FakeValidator.iter_errorsc                 S   s   d S r   r   ©r   Úschemar   r   r   Úcheck_schema(   s    z2fake_validator.<locals>.FakeValidator.check_schemaN)Ú__name__Ú
__module__Ú__qualname__r   r   Úclassmethodr"   r   r   r   r   ÚFakeValidator   s   r'   )ÚlistÚreversed)r   r'   r   r   r   Úfake_validator   s    r*   c                    s   ‡ fdd„}|S )Nc                    s"   ˆ   | ¡}|d u rt| ƒ‚t|ƒS r   )ÚgetÚFileNotFoundErrorr   )ÚpathÚcontents©Úall_contentsr   r   Úopen0   s    
zfake_open.<locals>.openr   )r0   r1   r   r/   r   Ú	fake_open/   s    r2   c              
   C   sH   zt  | ¡ W n, ty: } zt|ƒW  Y d }~S d }~0 0 tdƒ‚d S )Nz.Tried and failed to capture a JSON dump error.)ÚjsonÚloadsr   ÚstrÚRuntimeError)Znon_jsonÚerrorr   r   r   Ú_message_for8   s
    r8   c                   @   s€  e Zd Zdeƒ dfdd„Zd^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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,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0dS )_ÚTestCLINr   c           
      K   s¨   t  |¡}| |¡ |  tt dƒ¡ t|p,i ƒt _z(tƒ tƒ  }}t j||||d�}	W t `nt `0 | j	|	|t
d|› d|	› d| ¡ › d| ¡ › d�	ƒd� | ¡ | ¡ fS )	Nr1   )ÚstdinÚstdoutÚstderrz.
                    Expected an exit code of z != z.

                    stdout: z

                    stderr: z
                )Úmsg)r   Ú
parse_argsÚupdateÚassertFalseÚhasattrr2   r1   r   ÚrunÚassertEqualr   Úgetvalue)
r   ÚargvÚfilesr:   Ú	exit_codeÚoverrideÚ	argumentsr;   r<   Zactual_exit_coder   r   r   Úrun_cliB   s6    

üÿÿýûÿÿzTestCLI.run_cliÚ c                 K   s(   |   | jf i |¤Žt|ƒt|ƒf¡ d S r   )rC   rJ   r   )r   r;   r<   r   r   r   r   ÚassertOutputsb   s    þzTestCLI.assertOutputsc                 C   s>   t ddd�}| jtdt |j¡d�t|gƒg d¢ddd	� d S )
NúI am an error!é   ©r   ú*{"does not": "matter since it is stubbed"}©Úsome_schemaÚsome_instance©ú-irS   rR   é   ú12: I am an error!
©rF   Ú	validatorrE   rG   r<   ©r   rL   Údictr3   Údumpsr   r*   ©r   r7   r   r   r   Útest_invalid_instanceh   s    
þözTestCLI.test_invalid_instancec                 C   s>   t ddd�}| jtdt |j¡d�t|gƒg d¢ddd	� d S )
NrM   rN   rO   rP   rQ   ©rU   rS   ú--outputÚprettyrR   rV   z”                ===[ValidationError]===(some_instance)===

                I am an error!
                -----------------------------
            rX   rZ   r]   r   r   r   Ú#test_invalid_instance_pretty_outputw   s    
þöz+TestCLI.test_invalid_instance_pretty_outputc                 C   s>   t ddd�}| jtdt |j¡d�t|gƒg d¢ddd	� d S )
NrM   rN   rO   rP   rQ   )r`   ÚplainrU   rS   rR   rV   rW   rX   rZ   r]   r   r   r   Ú+test_invalid_instance_explicit_plain_output‹   s    
þöz3TestCLI.test_invalid_instance_explicit_plain_outputc                 C   sN   d}t d|d�}t d|d�}| jtdt |¡d�t||gƒg d¢dd	d
� d S )NrN   úFirst errorrO   úSecond errorrP   rQ   rT   rV   zM                12: First error
                12: Second error
            rX   ©r   rL   r[   r3   r\   r*   ©r   r   ÚfirstÚsecondr   r   r   Ú%test_invalid_instance_multiple_errorsš   s    þ
öz-TestCLI.test_invalid_instance_multiple_errorsc                 C   sN   d}t d|d�}t d|d�}| jtdt |¡d�t||gƒg d¢dd	d
� d S )NrN   re   rO   rf   rP   rQ   r_   rV   a                  ===[ValidationError]===(some_instance)===

                First error
                -----------------------------
                ===[ValidationError]===(some_instance)===

                Second error
                -----------------------------
            rX   rg   rh   r   r   r   Ú3test_invalid_instance_multiple_errors_pretty_output¯   s    þ
öz;TestCLI.test_invalid_instance_multiple_errors_pretty_outputc                 C   sf   d}t d|d�t d|d�g}d}t d|d�g}| jtdt |¡t |¡d�t||ƒg d	¢d
dd� d S )NrN   úAn errorrO   úAnother errorÚfooÚBOOMrP   ©rR   Úsome_first_instanceÚsome_second_instance)rU   rr   rU   rs   rR   rV   ze                12: An error
                12: Another error
                foo: BOOM
            rX   rg   ©r   Úfirst_instanceZfirst_errorsÚsecond_instanceZsecond_errorsr   r   r   Útest_multiple_invalid_instancesÊ   s"    

þýñz'TestCLI.test_multiple_invalid_instancesc                 C   sf   d}t d|d�t d|d�g}d}t d|d�g}| jtdt |¡t |¡d�t||ƒg d	¢d
dd� d S )NrN   rm   rO   rn   ro   rp   rP   rq   )r`   ra   rU   rr   rU   rs   rR   rV   a¦                  ===[ValidationError]===(some_first_instance)===

                An error
                -----------------------------
                ===[ValidationError]===(some_first_instance)===

                Another error
                -----------------------------
                ===[ValidationError]===(some_second_instance)===

                BOOM
                -----------------------------
            rX   rg   rt   r   r   r   Ú-test_multiple_invalid_instances_pretty_outputé   s"    

þýðz5TestCLI.test_multiple_invalid_instances_pretty_outputc                 C   sf   d}t d|d�t d|d�g}d}t d|d�g}| jtdt |¡t |¡d�t||ƒg d	¢d
dd� d S )NrN   rm   rO   rn   ro   rp   rP   rq   )ú--error-formatú&:{error.message}._-_.{error.instance}:rU   rr   rU   rs   rR   rV   z5:An error._-_.12::Another error._-_.12::BOOM._-_.foo:rX   rg   rt   r   r   r   Útest_custom_error_format  s"    

þýðz TestCLI.test_custom_error_formatc                 C   s   | j tdd�dgddd� d S )Nz{"type": 12}©rR   rR   rV   úO                12: 12 is not valid under any of the given schemas
            ©rF   rE   rG   r<   ©rL   r[   ©r   r   r   r   Útest_invalid_schema.  s    ûzTestCLI.test_invalid_schemac                 C   sz   ddi}|   t¡�}t|dd� W d   ƒ n1 s40    Y  t|jƒ}| jtt |¡d�g d¢ddt|ƒ d	 d
� d S )NÚtyperN   rK   ©r!   r   r|   ©r`   ra   rR   rV   ú%===[SchemaError]===(some_schema)===

ú
-----------------------------
r~   ©	ÚassertRaisesr   r   r5   Ú	exceptionrL   r[   r3   r\   ©r   r!   Úer7   r   r   r   Ú!test_invalid_schema_pretty_output9  s    *
ÿþúz)TestCLI.test_invalid_schema_pretty_outputc                 C   s   | j tdd�dgddd� d S )Nz{"type": 12, "items": 57}r|   rR   rV   zF                57: 57 is not of type 'object', 'boolean'
            r~   r   r€   r   r   r   Ú#test_invalid_schema_multiple_errorsL  s    ûz+TestCLI.test_invalid_schema_multiple_errorsc                 C   s|   dddœ}|   t¡�}t|dd� W d   ƒ n1 s60    Y  t|jƒ}| jtt |¡d�g d¢dd	t|ƒ d
 d� d S )NrN   é9   )r‚   ÚitemsrK   rƒ   r|   r„   rV   r…   r†   r~   r‡   rŠ   r   r   r   Ú1test_invalid_schema_multiple_errors_pretty_outputW  s    
*
ÿþúz9TestCLI.test_invalid_schema_multiple_errors_pretty_outputc                 C   s"   | j tddd�g d¢ddd� dS )	zv
        "Validating" an instance that's invalid under an invalid schema
        just shows the schema error.
        z{"type": 12, "minimum": 30}Z13rQ   rT   rV   r}   r~   Nr   r€   r   r   r   Ú)test_invalid_schema_with_invalid_instancej  s    þøz1TestCLI.test_invalid_schema_with_invalid_instancec                 C   sŠ   ddddœ }}|   t¡�}t||d� W d   ƒ n1 s<0    Y  t|jƒ}| jtt |¡t |¡d�g d¢dd	t|ƒ d
 d� d S )Né   rN   é   ©r‚   Zminimumrƒ   rQ   ©r`   ra   rU   rS   rR   rV   r…   r†   r~   r‡   )r   r   r!   r‹   r7   r   r   r   Ú7test_invalid_schema_with_invalid_instance_pretty_output|  s"    *
þÿþ÷z?TestCLI.test_invalid_schema_with_invalid_instance_pretty_outputc                 C   s.   | j tdddd�g d¢dd tdƒ¡d� d S )	Nz{"minimum": 30}únot valid JSON!Z12)rR   ru   rv   )rU   ru   rU   rv   rR   rV   zw                Failed to parse 'first_instance': {}
                12: 12 is less than the minimum of 30
            r~   )rL   r[   Úformatr8   r€   r   r   r   Ú-test_invalid_instance_continues_with_the_rest’  s    ýýóz5TestCLI.test_invalid_instance_continues_with_the_restc                 C   sl   ddddœ }}|   t¡� t||d� W d   ƒ n1 s<0    Y  | jtt |¡d�g d¢dd	d
� d S )Nr’   rN   r“   r”   rƒ   r|   )ry   rz   rR   rV   z7:12 is not valid under any of the given schemas._-_.12:r~   )rˆ   r   r   rL   r[   r3   r\   )r   r   r!   r   r   r   Ú1test_custom_error_format_applies_to_schema_errors¦  s    *÷z9TestCLI.test_custom_error_format_applies_to_schema_errorsc                 C   s2   d}| j td|d�g d¢ddt|ƒ› d�d� d S )	Nr—   ú{}rQ   rT   rV   z1                Failed to parse 'some_instance': ú
            r~   ©rL   r[   r8   r   r   r   r   Útest_instance_is_invalid_JSON¸  s    
ÿûz%TestCLI.test_instance_is_invalid_JSONc                 C   sF   | j tddd�g d¢dd�\}}|  |¡ |  d|¡ |  d|¡ d S )	Nr›   r—   rQ   r•   rV   ©rF   rE   rG   z7(some_instance)===

Traceback (most recent call last):
rR   ©rJ   r[   r@   ÚassertInÚassertNotIn©r   r;   r<   r   r   r   Ú+test_instance_is_invalid_JSON_pretty_outputÅ  s    þø


þz3TestCLI.test_instance_is_invalid_JSON_pretty_outputc                 C   s4   d}| j tdd�t|ƒdgddt|ƒ› d�d� d S )	Nr—   r›   r|   rR   rV   z)                Failed to parse <stdin>: rœ   )rF   r:   rE   rG   r<   )rL   r[   r   r8   r   r   r   r   Ú&test_instance_is_invalid_JSON_on_stdin×  s    ÿùz.TestCLI.test_instance_is_invalid_JSON_on_stdinc                 C   sJ   | j tdd�tdƒg d¢dd�\}}|  |¡ |  d|¡ |  d|¡ d S )	Nr›   r|   r—   r„   rV   )rF   r:   rE   rG   z1(<stdin>)===

Traceback (most recent call last):
rR   )rJ   r[   r   r@   r¡   r¢   r£   r   r   r   Ú4test_instance_is_invalid_JSON_on_stdin_pretty_outputæ  s    ú

þz<TestCLI.test_instance_is_invalid_JSON_on_stdin_pretty_outputc                 C   s.   d}| j t|d�dgddt|ƒ› d�d� d S )Nr—   r|   rR   rV   ú/                Failed to parse 'some_schema': rœ   r~   r�   r    r   r   r   Útest_schema_is_invalid_JSONö  s    ÿúz#TestCLI.test_schema_is_invalid_JSONc                 C   s8   | j tdd�g d¢dd�\}}|  |¡ |  d|¡ d S )Nr—   r|   r„   rV   rŸ   ú5(some_schema)===

Traceback (most recent call last):
)rJ   r[   r@   r¡   r£   r   r   r   Ú)test_schema_is_invalid_JSON_pretty_output  s    û

þz1TestCLI.test_schema_is_invalid_JSON_pretty_outputc                 C   s4   d\}}| j t||d�dgddt|ƒ› d�d� dS )	úM
        Only the schema error is reported, as we abort immediately.
        )r—   úalso not valid JSON!rQ   rR   rV   r§   rœ   r~   Nr�   ©r   r!   r   r   r   r   Ú.test_schema_and_instance_are_both_invalid_JSON  s    
ÿúz6TestCLI.test_schema_and_instance_are_both_invalid_JSONc                 C   sF   | j tddd�g d¢dd�\}}|  |¡ |  d|¡ |  d|¡ d	S )
r«   r—   r¬   rQ   r•   rV   rŸ   r©   rS   Nr    r£   r   r   r   Ú<test_schema_and_instance_are_both_invalid_JSON_pretty_output"  s    þø


þzDTestCLI.test_schema_and_instance_are_both_invalid_JSON_pretty_outputc                 C   s    | j tdd�g d¢ddd� d S )Nr›   r|   )rU   Únonexisting_instancerR   rV   zC                'nonexisting_instance' does not exist.
            r~   r   r€   r   r   r   Útest_instance_does_not_exist7  s    ûz$TestCLI.test_instance_does_not_existc                 C   s    | j tdd�g d¢ddd� d S )Nr›   r|   )r`   ra   rU   r°   rR   rV   zµ                ===[FileNotFoundError]===(nonexisting_instance)===

                'nonexisting_instance' does not exist.
                -----------------------------
            r~   r   r€   r   r   r   Ú*test_instance_does_not_exist_pretty_outputB  s    ÷z2TestCLI.test_instance_does_not_exist_pretty_outputc                 C   s   | j dgddd� d S )NÚnonexisting_schemarV   ú%'nonexisting_schema' does not exist.
©rE   rG   r<   ©rL   r€   r   r   r   Útest_schema_does_not_existT  s
    üz"TestCLI.test_schema_does_not_existc                 C   s   | j g d¢ddd� d S )N)r`   ra   r³   rV   ú±                ===[FileNotFoundError]===(nonexisting_schema)===

                'nonexisting_schema' does not exist.
                -----------------------------
            rµ   r¶   r€   r   r   r   Ú(test_schema_does_not_exist_pretty_output\  s
    üz0TestCLI.test_schema_does_not_exist_pretty_outputc                 C   s   | j g d¢ddd� d S )N)rU   r°   r³   rV   r´   rµ   r¶   r€   r   r   r   Ú&test_neither_instance_nor_schema_existi  s
    üz.TestCLI.test_neither_instance_nor_schema_existc                 C   s   | j g d¢ddd� d S )N)r`   ra   rU   r°   r³   rV   r¸   rµ   r¶   r€   r   r   r   Ú4test_neither_instance_nor_schema_exist_pretty_outputq  s
    øz<TestCLI.test_neither_instance_nor_schema_exist_pretty_outputc                 C   s"   | j tddd�g d¢ddd� d S ©Nr›   rQ   rT   rK   ©rF   rE   r;   r<   r   r€   r   r   r   Útest_successful_validation‚  s    
üz"TestCLI.test_successful_validationc                 C   s"   | j tddd�g d¢ddd� d S ©Nr›   rQ   r•   z"===[SUCCESS]===(some_instance)===
rK   r½   r   r€   r   r   r   Ú(test_successful_validation_pretty_outputŠ  s    
üz0TestCLI.test_successful_validation_pretty_outputc                 C   s$   | j tdd�tdƒdgddd� d S )Nr›   r|   rR   rK   ©rF   r:   rE   r;   r<   ©rL   r[   r   r€   r   r   r   Ú#test_successful_validation_of_stdin’  s    ûz+TestCLI.test_successful_validation_of_stdinc                 C   s&   | j tdd�tdƒg d¢ddd� d S )Nr›   r|   r„   z===[SUCCESS]===(<stdin>)===
rK   rÁ   rÂ   r€   r   r   r   Ú1test_successful_validation_of_stdin_pretty_output›  s    ûz9TestCLI.test_successful_validation_of_stdin_pretty_outputc                 C   s"   | j tddd�g d¢ddd� d S r¼   r   r€   r   r   r   Ú-test_successful_validation_of_just_the_schema¤  s    
üz5TestCLI.test_successful_validation_of_just_the_schemac                 C   s"   | j tddd�g d¢ddd� d S r¿   r   r€   r   r   r   Ú;test_successful_validation_of_just_the_schema_pretty_output¬  s    
üzCTestCLI.test_successful_validation_of_just_the_schema_pretty_outputc                 C   sx   t jdd�}| ¡  |  tj|j¡ t|jƒ}| d¡ d|j› d�}| j	t
|dd�dd	d
|j ¡ d dgddd� d S )NF©Údeleteú-{"definitions": {"num": {"type": "integer"}}}ú
{"$ref": "ú#/definitions/num"}Ú1rQ   rU   rS   ú
--base-uriú/rR   rK   r½   ©ÚtempfileÚNamedTemporaryFileÚcloseZ
addCleanupÚosÚremoveÚnamer   Ú
write_textrL   r[   ÚparentÚas_uri©r   Zref_schema_fileZref_pathr!   r   r   r   Ú0test_successful_validation_via_explicit_base_uri´  s    


ýøz8TestCLI.test_successful_validation_via_explicit_base_uric                 C   sz   t jdd�}| ¡  |  tj|j¡ t|jƒ}| d¡ d|j› d�}| j	t
|dd�dd	d
|j ¡ d dgdddd� d S )NFrÇ   rÉ   rÊ   rË   z"1"rQ   rU   rS   rÍ   rÎ   rR   rV   rK   z 1: '1' is not of type 'integer'
©rF   rE   rG   r;   r<   rÏ   rÙ   r   r   r   Ú2test_unsuccessful_validation_via_explicit_base_uriÉ  s     


ý÷z:TestCLI.test_unsuccessful_validation_via_explicit_base_uric                 C   s|   d}d}|   t¡�8}| jt||d�dddt ¡  ¡ dgd� W d   ƒ n1 sP0    Y  t|jƒ}|  	t
j› d	�|¡ d S )
Nz4{"$ref": "someNonexistentFile.json#definitions/num"}rÌ   rQ   rU   rS   rÍ   rR   ©rF   rE   zsomeNonexistentFile.json')rˆ   r   rL   r[   r   ÚcwdrØ   r5   r‰   r¡   rÓ   Úsep©r   r!   r   r‹   r7   r   r   r   Ú,test_nonexistent_file_with_explicit_base_uriß  s    þýû$
z4TestCLI.test_nonexistent_file_with_explicit_base_uric                 C   sf   d}d}|   t¡�*}| jt||d�g d¢d� W d   ƒ n1 sB0    Y  t|jƒ}|  |d¡ d S )Nz${"$ref": "foo.json#definitions/num"}rÌ   rQ   )rU   rS   rÍ   znot@UR1rR   rÝ   zunknown url type: 'foo.json')rˆ   r   rL   r[   r5   r‰   rC   rà   r   r   r   Útest_invalid_explicit_base_uriò  s    þû$
ÿz&TestCLI.test_invalid_explicit_base_uric                 C   s0   |   tt¡ | jtddd�g d¢dddd� d S )	Nz{"const": "check"}z"a"rQ   rT   rV   rK   za: 'check' was expected
rÛ   )ÚassertIsr   r   rL   r[   r€   r   r   r   Ú=test_it_validates_using_the_latest_validator_when_unspecified  s    
ûzETestCLI.test_it_validates_using_the_latest_validator_when_unspecifiedc                 C   s,   d}d}| j t||d�g d¢dddd� d	S )
zG
        Specifically, `const` validation applies for Draft 7.
        zŒ
            {
                "$schema": "http://json-schema.org/draft-07/schema#",
                "const": "check"
            }
        ú"foo"rQ   rT   rV   rK   zfoo: 'check' was expected
rÛ   Nr   r­   r   r   r   Ú-test_it_validates_using_draft7_when_specified  s    
ûz5TestCLI.test_it_validates_using_draft7_when_specifiedc                 C   s*   d}d}| j t||d�g d¢ddd� dS )zP
        Specifically, `const` validation *does not* apply for Draft 4.
        z�
            {
                "$schema": "http://json-schema.org/draft-04/schema#",
                "const": "check"
            }
            rå   rQ   rT   rK   r½   Nr   r­   r   r   r   Ú-test_it_validates_using_draft4_when_specified*  s    
üz5TestCLI.test_it_validates_using_draft4_when_specified)rK   rK   )1r#   r$   r%   r   rJ   rL   r^   rb   rd   rk   rl   rw   rx   r{   r�   rŒ   r�   r�   r‘   r–   r™   rš   rž   r¤   r¥   r¦   r¨   rª   r®   r¯   r±   r²   r·   r¹   rº   r»   r¾   rÀ   rÃ   rÄ   rÅ   rÆ   rÚ   rÜ   rá   râ   rä   ræ   rç   r   r   r   r   r9   A   s\   ÿ
 
)		r9   c                   @   s:   e Zd Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dS )Ú
TestParserc                 C   s$   t  g d¢¡}|  |d | j¡ d S )N)ú--validatorz2jsonschema.tests.test_cli.TestParser.FakeValidatorú
--instanceúmem://some/instanceúmem://some/schemarY   )r   r>   rã   r'   ©r   rI   r   r   r   Ú2test_find_validator_by_fully_qualified_object_nameA  s    ÿz=TestParser.test_find_validator_by_fully_qualified_object_namec                 C   s"   t  g d¢¡}|  |d t¡ d S )N)ré   r
   rê   rë   rì   rY   )r   r>   rã   r
   rí   r   r   r   Ú!test_find_validator_in_jsonschemaL  s    ÿz,TestParser.test_find_validator_in_jsonschemac              
   G   s¢   t ƒ t ƒ  }}t|ƒ�l t|ƒ�D |  t¡� t |¡ W d   ƒ n1 sL0    Y  W d   ƒ n1 sj0    Y  W d   ƒ n1 sˆ0    Y  | ¡ | ¡ fS r   )r   r   r   rˆ   Ú
SystemExitr   r>   rD   )r   rE   r;   r<   r   r   r   Úcli_output_forV  s
    dzTestParser.cli_output_forc                 C   s,   |   ddd¡\}}|  d|¡ |  |¡ d S )Nr`   ro   rì   zinvalid choice: 'foo'©rñ   r¡   r@   r£   r   r   r   Útest_unknown_output]  s    þzTestParser.test_unknown_outputc                 C   s0   |   ddddd¡\}}|  d|¡ |  |¡ d S )Nr`   ra   ry   ro   rì   z3--error-format can only be used with --output plainrò   r£   r   r   r   Útest_useless_error_formate  s    ýþz$TestParser.test_useless_error_formatN)
r#   r$   r%   r*   r'   rî   rï   rñ   ró   rô   r   r   r   r   rè   =  s   
rè   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestCLIIntegrationc                 C   s,   t jtjddddgt jd�}|  d|¡ d S )Nú-mÚpipÚshowÚ
jsonschema©r<   s   License: MIT)Ú
subprocessÚcheck_outputÚsysÚ
executableÚSTDOUTr¡   )r   Úoutputr   r   r   Útest_licenses  s
    þzTestCLIIntegration.test_licensec                 C   sB   t jtjdddddgt jd�}| d¡ ¡ }|  |t 	d¡¡ d S )Nz-Wr   rö   rù   z	--versionrú   zutf-8)
rû   rü   rý   rþ   rÿ   ÚdecodeÚstriprC   r   Úversion)r   r  r   r   r   Útest_versionz  s    þzTestCLIIntegration.test_versionc                 C   sB   t jtjddgt jd�}t jtjdddgt jd�}|  ||¡ d S )Nrö   rù   rú   z--help)rû   rü   rý   rþ   rÿ   rC   )r   r   Zoutput_for_helpr   r   r   Ú#test_no_arguments_shows_usage_notes‚  s    
þþz6TestCLIIntegration.test_no_arguments_shows_usage_notesN)r#   r$   r%   r  r  r  r   r   r   r   rõ   r  s   rõ   )'Ú
contextlibr   r   Ú	importlibr   Úior   r3   r   Úpathlibr   Útextwrapr   Zunittestr	   rÓ   rû   rý   rÐ   Úwarningsrù   r
   r   Zjsonschema.exceptionsr   r   r   Zjsonschema.validatorsr   r   Úcatch_warningsÚsimplefilterr   r*   r2   r8   r9   rè   rõ   r   r   r   r   Ú<module>   s<   

*		      5