U
    4Je                     @   s   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zd dlm	Z	 W nJ e
k
r   zd dlm	Z	 W n$ e
k
r   d dlZdd Z	Y nX Y nX dd ZG dd	 d	ejZdS )
    )with_statementN)strip_python_stderrc                 C   s   t d d |  S )Nz\[\d+ refs\]\r?\n?$ )resubencodestrip)stderr r
   >/tmp/pip-unpacked-wheel-52sb2ggr/simplejson/tests/test_tool.pyr      s
    r   c                  C   s>   t jdkrtjdd} | j}nt \}}t|d} | |fS )N)      F)deletezw+b)sysversion_infotempfileNamedTemporaryFilenamemkstemposfdopen)filefilenamefdr
   r
   r   open_temp_file   s    
r   c                   @   s<   e Zd ZdZedZd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
        }
    ]
    Nc                 C   sp   t jddg}|r|| tj|tjtjtjd}||\}}| t|d	  | |j
d |d S )Nz-mzsimplejson.tool)stdinr	   stdoutr   r   utf8)r   
executableextend
subprocessPopenPIPEcommunicateassertEqualr   r   
returncodedecode
splitlines)selfargsdataargvprocouterrr
   r
   r   runTool@   s    
zTestTool.runToolc                 C   s$   |  | j| j d| j  d S )N)r+   )r%   r0   r+   r   expectr(   )r)   r
   r
   r   test_stdin_stdoutM   s    zTestTool.test_stdin_stdoutc              	   C   sT   t  \}}z8|| j  |  | | j|gd| j	
  W 5 t| X d S )Nr*   )r   r   unlinkwriter+   r   closer%   r0   r1   r(   )r)   infileinfile_namer
   r
   r   test_infile_stdoutR   s    
zTestTool.test_infile_stdoutc              	   C   s   t  \}}z|| j  |  t  \}}zZ|  | | j||gdg  t	|d&}| |
 d | j  W 5 Q R X W 5 t| X W 5 t| X d S )Nr3   rbr   )r   r   r4   r5   r+   r   r6   r%   r0   openreadr'   r(   r1   )r)   r7   r8   outfileZoutfile_namefr
   r
   r   test_infile_outfile]   s$    

zTestTool.test_infile_outfile)NN)__name__
__module____qualname__r+   textwrapdedentr1   r0   r2   r9   r?   r
   r
   r
   r   r   !   s   

r   )
__future__r   r   r   rC   Zunittestr!   r   Ztest.supportr   ImportErrorZtest.test_supportr   r   ZTestCaser   r
   r
   r
   r   <module>   s    	