
    <e|                         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 d dlm	Z	 d dl
mZ  ej                     G d dej                              ZdS )    N)support)	os_helper)assert_python_okc                   4   e Zd ZdZ ej        d          Z ej        d          Z ej        d          Z ej        d          Z	d Z
d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 ej        ej        dk    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"
        }
    ]
    zr    {"ingredients":["frog", "water", "chocolate", "glucose"]}
    {"ingredients":["chocolate","steel bolts"]}
    z    {
        "ingredients": [
            "frog",
            "water",
            "chocolate",
            "glucose"
        ]
    }
    {
        "ingredients": [
            "chocolate",
            "steel bolts"
        ]
    }
    c                     t           j        ddf}t          j        || j        ddd          }|                     |j        | j                   |                     |j        d           d S )N-m	json.toolTinputcapture_outputtextcheck )	sys
executable
subprocessrundataassertEqualstdoutexpectstderrselfargsprocesss      //usr/lib/python3.11/test/test_json/test_tool.pytest_stdin_stdoutzTestTool.test_stdin_stdoutY   sf    ~t[0.TYtRV^bccc555,,,,,    Nc                     t           j        }t          |dd          5 }|                     t          j        |           |                    |p| j                   d d d            n# 1 swxY w Y   |S )Nwutf-8encoding)r   TESTFNopen
addCleanuposremovewriter   )r   r   infilefps       r   _create_infilezTestTool._create_infile_   s    !&#000 	(BOOBIv...HHT&TY'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( s   =A((A,/A,c                 R   |                                  }t          dd|          \  }}}|                     |d           |                     |                                | j                                                                                   |                     |d           d S )Nr	   r
   r   r    )r.   r   r   
splitlinesr   encoder   r,   rcouterrs        r   test_infile_stdoutzTestTool.test_infile_stdoutf   s    $$&&'k6BBCQ))4;+=+=+?+?+J+J+L+LMMMc"""""r    c                 v   d}t          j        d                                          }|                     |          }t	          dd|          \  }}}|                     |d           |                     |                                |                                           |                     |d           d S )Nu   {"msg": "こんにちは"}zP        {
            "msg": "\u3053\u3093\u306b\u3061\u306f"
        }
        r	   r
   r   r    )textwrapdedentr1   r.   r   r   r0   )r   r   r   r,   r3   r4   r5   s          r   test_non_ascii_infilezTestTool.test_non_ascii_infilem   s    : "   VXX	 	 $$T**'k6BBCQ))6+<+<+>+>???c"""""r    c                    |                                  }t          j        dz   }t          dd||          \  }}}|                     t
          j        |           t          |dd          5 }|                     |	                                | j
                   d d d            n# 1 swxY w Y   |                     |d           |                     |d           |                     |d           d S )	N.outr	   r
   rr#   r$   r   r    )r.   r   r&   r   r(   r)   r*   r'   r   readr   )r   r,   outfiler3   r4   r5   r-   s          r   test_infile_outfilezTestTool.test_infile_outfile|   s   $$&&"V+'k67KKC	7+++'3111 	5RRWWYY444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5Qc"""c"""""s   ,.B&&B*-B*c                    |                                  }t          dd||          \  }}}t          |dd          5 }|                     |                                | j                   d d d            n# 1 swxY w Y   |                     |d           |                     |d           |                     |d           d S )Nr	   r
   r=   r#   r$   r   r    )r.   r   r'   r   r>   r   )r   r,   r3   r4   r5   r-   s         r   test_writing_in_placezTestTool.test_writing_in_place   s    $$&&'k66JJC&#000 	5BRWWYY444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5Qc"""c"""""s   .A77A;>A;c                     t           j        dddf}t          j        || j        ddd          }|                     |j        | j                   |                     |j        d           d S )Nr	   r
   z--json-linesTr   r   )	r   r   r   r   jsonlines_rawr   r   jsonlines_expectr   r   s      r   test_jsonlineszTestTool.test_jsonlines   sk    ~t[.@.T-?PT[_gklll)>???,,,,,r    c                     t          ddd          \  }}}|                     |d           |                     |                    d                     |                     |d           d S )Nr	   r
   z-hr   s   usage: r    )r   r   
assertTrue
startswith)r   r3   r4   r5   s       r   test_help_flagzTestTool.test_help_flag   si    'k4@@CQz22333c"""""r    c                 T   |                                  }t          ddd|          \  }}}|                     |d           |                     |                                | j                                                                                   |                     |d           d S )Nr	   r
   z--sort-keysr   r    )r.   r   r   r0   expect_without_sort_keysr1   r2   s        r   test_sort_keys_flagzTestTool.test_sort_keys_flag   s    $$&&'k=&QQCQ))6==??JJLL	N 	N 	Nc"""""r    c                     d}t          j        d          }t          j        ddddf}t	          j        ||ddd          }|                     |j        |           |                     |j        d	           d S )
N[1, 2]z5        [
          1,
          2
        ]
        r	   r
   z--indent2Tr   r   )	r8   r9   r   r   r   r   r   r   r   r   input_r   r   r   s        r   test_indentzTestTool.test_indent   s     "   ~t[*cA.VDt[_```000,,,,,r    c                     d}d}t           j        dddf}t          j        ||ddd          }|                     |j        |           |                     |j        d           d S )	Nz[1,
2]z[1, 2]
r	   r
   z--no-indentTr   r   r   r   r   r   r   r   r   rQ   s        r   test_no_indentzTestTool.test_no_indent   sm    ~t[-?.VDt[_```000,,,,,r    c                     d}d}t           j        dddf}t          j        ||ddd          }|                     |j        |           |                     |j        d           d S )	NrO   z[
	1,
	2
]
r	   r
   z--tabTr   r   rU   rQ   s        r   test_tabzTestTool.test_tab   sm    $~t['9.VDt[_```000,,,,,r    c                     d}d}t           j        dddf}t          j        ||ddd          }|                     |j        |           |                     |j        d           d S )	Nz	[ 1 ,
 2]z[1,2]
r	   r
   z	--compactTr   r   rU   rQ   s        r   test_compactzTestTool.test_compact   sm    ~t[+=.VDt[_```000,,,,,r    c                    |                      d          }t          j        dz   }|                     t          j        |           t          ddd||           t          |d          5 }|                                	                                }d d d            n# 1 swxY w Y   g d}| 
                    ||           d S )N   {"key":"💩"}r<   r	   r
   z--no-ensure-asciirb)   {s       "key": "💩"   }r.   r   r&   r(   r)   r*   r   r'   r>   r0   r   r   r,   r?   flinesexpecteds         r   test_no_ensure_ascii_flagz"TestTool.test_no_ensure_ascii_flag   s    $$%566"V+	7+++{,?QQQ'4   	*AFFHH''))E	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* BAA)))))s   ('BB"Bc                    |                      d          }t          j        dz   }|                     t          j        |           t          dd||           t          |d          5 }|                                	                                }d d d            n# 1 swxY w Y   g d}| 
                    ||           d S )Nr\   r<   r	   r
   r]   )r^   s       "key": "\ud83d\udca9"r_   r`   ra   s         r   test_ensure_ascii_defaultz"TestTool.test_ensure_ascii_default   s    $$%566"V+	7+++{FG<<<'4   	*AFFHH''))E	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* ?>>)))))s   ''BB!Bwin32z-The test is failed with ValueError on Windowsc                     t           j        ddg}t          j        |t          j        t          j                  }|j                                         |                    d           |                     |j	        t          j                   d S )Nr	   r
   )r   stdins   "{}")r   r   r   PopenPIPEr   closecommunicater   
returncodeerrnoEPIPE)r   cmdprocs      r   test_broken_pipe_errorzTestTool.test_broken_pipe_error   s}    ~t[1'1&0o7 7 7 	!!!%+66666r    )N)__name__
__module____qualname__r   r8   r9   rL   r   rD   rE   r   r.   r6   r:   r@   rB   rF   rJ   rM   rS   rV   rX   rZ   re   rg   unittestskipIfr   platformrt    r    r   r   r      s       D  /x 0  	  	, X_  	 	F, $HO % 	 	M
 'x ( 	 	"- - -   # # ## # #	# 	# 	## # #- - -# # ## # #- - -- - -- - -- - -	* 	* 	*	* 	* 	* X_S\G+-\]]7 7 ^]7 7 7r    r   )rp   r)   r   r8   rx   r   testr   test.supportr   test.support.script_helperr   requires_subprocessTestCaser   r{   r    r   <module>r      s     				 



             " " " " " " 7 7 7 7 7 7 Z7 Z7 Z7 Z7 Z7x  Z7 Z7 Z7 Z7 Z7r    