Your IP : 216.73.216.213


Current Path : /opt/alt/python310/lib64/python3.10/test/test_json/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/test_json/__pycache__/test_tool.cpython-310.pyc

o

0�i]�@sjddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZGdd�dej�Z
dS)�N)�support)�	os_helper)�assert_python_okc@s�eZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	dd�Z
d)d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Ze�ejd%kd&�d'd(��ZdS)*�TestToolz�

        [["blorpie"],[ "whoops" ] , [
                                 ],	"d-shtaeou",
"d-nthiouh",
        "i-vhbjkhnth", {"nifty":87}, {"morefield" :	false,"field"
            :"yes"}  ]
           a.    [
        [
            "blorpie"
        ],
        [
            "whoops"
        ],
        [],
        "d-shtaeou",
        "d-nthiouh",
        "i-vhbjkhnth",
        {
            "nifty": 87
        },
        {
            "field": "yes",
            "morefield": false
        }
    ]
    a.    [
        [
            "blorpie"
        ],
        [
            "whoops"
        ],
        [],
        "d-shtaeou",
        "d-nthiouh",
        "i-vhbjkhnth",
        {
            "nifty": 87
        },
        {
            "morefield": false,
            "field": "yes"
        }
    ]
    zr    {"ingredients":["frog", "water", "chocolate", "glucose"]}
    {"ingredients":["chocolate","steel bolts"]}
    z�    {
        "ingredients": [
            "frog",
            "water",
            "chocolate",
            "glucose"
        ]
    }
    {
        "ingredients": [
            "chocolate",
            "steel bolts"
        ]
    }
    cCsDtjddf}tj||jdddd�}|�|j|j�|�|jd�dS)N�-m�	json.toolT��inputZcapture_output�textZcheck�)	�sys�
executable�
subprocess�run�data�assertEqual�stdout�expect�stderr��self�args�process�r�?/opt/alt/python310/lib64/python3.10/test/test_json/test_tool.py�test_stdin_stdoutXszTestTool.test_stdin_stdoutNcCsXtj}t|ddd��}|�tj|�|�|p|j�Wd�|S1s%wY|S)N�w�utf-8��encoding)r�TESTFN�open�
addCleanup�os�remove�writer)rr�infile�fprrr�_create_infile^s
��zTestTool._create_infilecCsP|��}tdd|�\}}}|�|d�|�|��|j�����|�|d�dS)Nrrr�)r(rr�
splitlinesr�encode�rr&�rc�out�errrrr�test_infile_stdoutes
zTestTool.test_infile_stdoutcCs^d}t�d���}|�|�}tdd|�\}}}|�|d�|�|��|���|�|d�dS)Nu{"msg": "こんにちは"}zP        {
            "msg": "\u3053\u3093\u306b\u3061\u306f"
        }
        rrrr))�textwrap�dedentr+r(rrr*)rrrr&r-r.r/rrr�test_non_ascii_infilels�
zTestTool.test_non_ascii_infilecCs�|��}tjd}tdd||�\}}}|�tj|�t|ddd��}|�|�	�|j
�Wd�n1s5wY|�|d�|�|d�|�|d�dS)	N�.outrr�rrrrr))r(rr rr"r#r$r!r�readr)rr&�outfiler-r.r/r'rrr�test_infile_outfile{s
�zTestTool.test_infile_outfilecCs�|��}tdd||�\}}}t|ddd��}|�|��|j�Wd�n1s)wY|�|d�|�|d�|�|d�dS)Nrrr5rrrr))r(rr!rr6r)rr&r-r.r/r'rrr�test_writing_in_place�s�zTestTool.test_writing_in_placecCsFtjdddf}tj||jdddd�}|�|j|j�|�|jd�dS)Nrrz--json-linesTrr)	rr
rr�
jsonlines_rawrr�jsonlines_expectrrrrr�test_jsonlines�szTestTool.test_jsonlinescCs>tddd�\}}}|�|d�|�|�d��|�|d�dS)Nrrz-hrsusage: r))rrZ
assertTrue�
startswith)rr-r.r/rrr�test_help_flag�szTestTool.test_help_flagcCsR|��}tddd|�\}}}|�|d�|�|��|j�����|�|d�dS)Nrrz--sort-keysrr))r(rrr*�expect_without_sort_keysr+r,rrr�test_sort_keys_flag�s
�zTestTool.test_sort_keys_flagcCsRd}t�d�}tjddddf}tj||dddd�}|�|j|�|�|jd	�dS)
N�[1, 2]z5        [
          1,
          2
        ]
        rrz--indent�2Trr)	r1r2rr
rrrrr�rZinput_rrrrrr�test_indent�s
zTestTool.test_indentcC�Jd}d}tjdddf}tj||dddd�}|�|j|�|�|jd�dS)	Nz[1,
2]z[1, 2]
rrz--no-indentTrr�rr
rrrrrrCrrr�test_no_indent��zTestTool.test_no_indentcCrE)	NrAz[
	1,
	2
]
rrz--tabTrrrFrCrrr�test_tab�rHzTestTool.test_tabcCrE)	Nz	[ 1 ,
 2]z[1,2]
rrz	--compactTrrrFrCrrr�test_compact�rHzTestTool.test_compactcCs�|�d�}tjd}|�tj|�tddd||�t|d��}|���	�}Wd�n1s/wYgd�}|�
||�dS)N�{"key":"💩"}r4rrz--no-ensure-ascii�rb)�{s    "key": "💩"�}�r(rr r"r#r$rr!r6r*r�rr&r7�f�linesZexpectedrrr�test_no_ensure_ascii_flag�s

�z"TestTool.test_no_ensure_ascii_flagcCs~|�d�}tjd}|�tj|�tdd||�t|d��}|���	�}Wd�n1s.wYgd�}|�
||�dS)NrKr4rrrL)rMs    "key": "\ud83d\udca9"rNrOrPrrr�test_ensure_ascii_default�s

�z"TestTool.test_ensure_ascii_defaultZwin32z-The test is failed with ValueError on WindowscCsHtjddg}tj|tjtjd�}|j��|�d�|�|j	t
j�dS)Nrr)r�stdins"{}")rr
r�Popen�PIPEr�closeZcommunicater�
returncode�errnoZEPIPE)r�cmd�procrrr�test_broken_pipe_error�s�

zTestTool.test_broken_pipe_error)N)�__name__�
__module__�__qualname__rr1r2r?rr:r;rr(r0r3r8r9r<r>r@rDrGrIrJrSrT�unittestZskipIfr�platformr]rrrrr
s.




	
r)rZr#rr1rar�testrZtest.supportrZtest.support.script_helperrZTestCaserrrrr�<module>s