B
    18™\z  ã               @   s^   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 d dl	m
Z
 G dd„ dejƒZdS )é    N)ÚPopenÚPIPE)Úsupport)Úassert_python_okc               @   sT   e Zd ZdZe d¡Ze d¡Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ ZdS )Ú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"
        }
    ]
    c          	   C   sf   t jddf}t|tttd}| | j ¡ ¡\}}W d Q R X |  | ¡ | j	 ¡  ¡ ¡ |  |d¡ d S )Nz-mz	json.tool)ÚstdinÚstdoutÚstderró    )
ÚsysÚ
executabler   r   ÚcommunicateÚdataÚencodeÚassertEqualÚ
splitlinesÚexpect)ÚselfÚargsÚprocÚoutÚerr© r   ú\/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_json/test_tool.pyÚtest_stdin_stdout?   s
    zTestTool.test_stdin_stdoutc          	   C   s:   t j}t|dƒ }|  tj|¡ | | j¡ W d Q R X |S )NÚw)r   ÚTESTFNÚopenÚ
addCleanupÚosÚremoveÚwriter   )r   ÚinfileÚfpr   r   r   Ú_create_infileF   s
    zTestTool._create_infilec             C   sP   |   ¡ }tdd|ƒ\}}}|  |d¡ |  | ¡ | j ¡  ¡ ¡ |  |d¡ d S )Nz-mz	json.toolr   r
   )r$   r   r   r   r   r   )r   r"   Úrcr   r   r   r   r   Útest_infile_stdoutM   s
    zTestTool.test_infile_stdoutc          	   C   s„   |   ¡ }tjd }tdd||ƒ\}}}|  tj|¡ t|dƒ}|  | 	¡ | j
¡ W d Q R X |  |d¡ |  |d¡ |  |d¡ d S )Nz.outz-mz	json.toolÚrr   r
   )r$   r   r   r   r   r   r    r   r   Úreadr   )r   r"   Zoutfiler%   r   r   r#   r   r   r   Útest_infile_outfileT   s    
zTestTool.test_infile_outfilec             C   s>   t dddƒ\}}}|  |d¡ |  | d¡¡ |  |d¡ d S )Nz-mz	json.toolz-hr   s   usage: r
   )r   r   Ú
assertTrueÚ
startswith)r   r%   r   r   r   r   r   Útest_help_flag_   s    zTestTool.test_help_flagc             C   sR   |   ¡ }tddd|ƒ\}}}|  |d¡ |  | ¡ | j ¡  ¡ ¡ |  |d¡ d S )Nz-mz	json.toolz--sort-keysr   r
   )r$   r   r   r   Úexpect_without_sort_keysr   )r   r"   r%   r   r   r   r   r   Útest_sort_keys_flage   s    
zTestTool.test_sort_keys_flagN)Ú__name__Ú
__module__Ú__qualname__r   ÚtextwrapÚdedentr-   r   r   r$   r&   r)   r,   r.   r   r   r   r   r   
   s   r   )r   r   r2   ÚunittestÚ
subprocessr   r   Útestr   Ztest.support.script_helperr   ÚTestCaser   r   r   r   r   Ú<module>   s   