�
�r�cBp � �R � d dl mZmZ d dlmZ d dlmZ d dlmZ d dl m
Z
d dlmZ d dlZd dl
Z
d dlZd dlZd dlZ d dlmZ n# e$ r d dlZY nw xY wd d lmZ d d
lmZmZmZ d dlmZmZmZ d dlm Z m!Z! d
� Z"d� Z#d� Z$ G d� de� � Z% G d� de� � Z& G d� de� � Z'dS )� )�redirect_stderr�redirect_stdout)�StringIO)�JSONDecodeError)�Path)�dedent)�TestCaseN)�metadata)�m)�Draft4Validator�Draft202012Validator�cli)�RefResolutionError�SchemaError�ValidationError)�_LATEST_VERSION�validatec �j � � t t � � � � � � G � fd�dt � � }|S )Nc �6 �� e Zd Zd� Z� fd�Zed� � � ZdS )�%fake_validator.<locals>.FakeValidatorc � � d S �N� )�self�args�kwargss �;/usr/lib/python3/dist-packages/jsonschema/tests/test_cli.py�__init__z.fake_validator.<locals>.FakeValidator.__init__! s � ��D� c �4 �� �r�� � � S g S r )�pop)r �instance�errorss �r �iter_errorsz1fake_validator.<locals>.FakeValidator.iter_errors$ s �� ��
$��z�z�|�|�#��Ir c � � d S r r �r �schemas r �check_schemaz2fake_validator.<locals>.FakeValidator.check_schema) s � ��Dr N)�__name__�
__module__�__qualname__r r$ �classmethodr( )r# s �r �
FakeValidatorr sX �� � � � � � � � � � � � � �
� � �
�� � � r r- )�list�reversed�object)r# r- s ` r �fake_validatorr1 sT �� �
�(�6�"�"�
#�
#�F�� � � � � � �� � � � �r c � � � � fd�}|S )Nc �n �� �� | � � }|�t | � � �t |� � S r )�get�FileNotFoundErrorr )�path�contents�all_contentss �r �openzfake_open.<locals>.open1 s8 �� ��#�#�D�)�)����#�D�)�)�)���!�!�!r r )r8 r9 s ` r � fake_openr: 0 s# �� �"� "� "� "� "�
�Kr c � � t j | � � t d� � �# t $ r}t |� � cY d }~S d }~ww xY w)Nz.Tried and failed to capture a JSON dump error.)�json�loads�RuntimeErrorr �str)�non_json�errors r �_message_forrB 9 se � �M��
�8���� �K�L�L�L�� � � � ��5�z�z��������������s �% �
A�A�A�Ac �F � e Zd Z e� � e� � dfd�Zd1d�Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� Z
d� Zd
� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Z d� Z!d � Z"d!� Z#d"� Z$d#� Z%d$� Z&d%� Z'd&� Z(d'� Z)d(� Z*d)� Z+d*� Z,d+� Z-d,� Z.d-� Z/d.� Z0d/� Z1d0S )2�TestCLIr c
�v � t j |� � }|� |� � | � t t d� � � � t |� � t _ t � � t � � }}t j ||||�� � } t `n# t `w xY w| � | |t d� || |� � � |� � � � � � � �� � |� � � |� � � fS )Nr9 )�stdin�stdout�stderrz�
Expected an exit code of {} != {}.
stdout: {}
stderr: {}
)�msg)
r �
parse_args�update�assertFalse�hasattrr: r9 r �run�assertEqualr �format�getvalue)
r �argv�filesrF � exit_code�override� argumentsrG rH �actual_exit_codes
r �run_clizTestCLI.run_cliC s( � � �N�4�(�(� �����"�"�"������f�-�-�.�.�.��U�#�#��� �%�Z�Z����F�F�"�w����� � � �� ������L�L�L�L�����i�V�� �F��$��O�O�%�%��O�O�%�%� � �
.�
.� �
�
�
� ��� � �&�/�/�"3�"3�3�3s �,4B( �( B1� c � � | � | j di |��t |� � t |� � f� � d S )Nr )rO rX r )r rG rH r s r �
assertOutputszTestCLI.assertOutputsh sM � �����D�L�"�"�6�"�"�
�F�^�^�V�F�^�^�,�
�
�
�
�
r c �� � t dd�� � }| � t dt j |j � � �� � t
|g� � g d�dd� � � d S )
N�I am an error!� �r" |