
    daf|                         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y)    N)support)	os_helper)assert_python_okc                   H   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j4                  ej8                  dk(  d      d        Zy)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                         | j                  |j                  d       y )N-m	json.toolTinputcapture_outputtextcheck )	sys
executable
subprocessrundataassertEqualstdoutexpectstderrselfargsprocesss      3/root/Python-3.12.4/Lib/test/test_json/test_tool.pytest_stdin_stdoutzTestTool.test_stdin_stdoutY   sZ    ~~t[0..TYYtRV^bc5,    Nc                     t         j                  }t        |dd      5 }| j                  t        j
                  |       |j                  |xs | j                         d d d        |S # 1 sw Y   |S xY w)Nwutf-8encoding)r   TESTFNopen
addCleanuposremovewriter   )r   r   infilefps       r   _create_infilezTestTool._create_infile_   s`    !!&#0 	(BOOBIIv.HHT&TYY'	( 	( s   A A))A3c                    | j                         }t        dd|      \  }}}| j                  |d       | j                  |j                         | j                  j                         j                                | j                  |d       y )Nr	   r
   r   r    )r.   r   r   
splitlinesr   encoder   r,   rcouterrs        r   test_infile_stdoutzTestTool.test_infile_stdoutf   sq    $$&'k6BCQ)4;;+=+=+?+J+J+LMc"r    c                 6   d}t        j                  d      j                         }| j                  |      }t	        dd|      \  }}}| j                  |d       | j                  |j                         |j                                | j                  |d       y )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    : "  VX	 	 $$T*'k6BCQ)6+<+<+>?c"r    c                    | j                         }t        j                  dz   }t        dd||      \  }}}| j	                  t
        j                  |       t        |dd      5 }| j                  |j                         | j                         d d d        | j                  |d       | j                  |d       | j                  |d       y # 1 sw Y   @xY w)	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C		7+'31 	5RRWWY4	5Qc"c"		5 	5s   $+CCc                 N   | j                         }t        dd||      \  }}}t        |dd      5 }| j                  |j	                         | j
                         d d d        | j                  |d       | j                  |d       | j                  |d       y # 1 sw Y   @xY w)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C&#0 	5BRWWY4	5Qc"c"		5 	5s   +BB$c                     t         j                  dddf}t        j                  || j                  ddd      }| j                  |j                  | j                         | j                  |j                  d       y )Nr	   r
   z--json-linesTr   r   )	r   r   r   r   jsonlines_rawr   r   jsonlines_expectr   r   s      r   test_jsonlineszTestTool.test_jsonlines   sa    ~~t[.@..T-?-?PT[_gkl)>)>?,r    c                     t        ddd      \  }}}| j                  |d       | j                  |j                  d             | j                  |d       y )Nr	   r
   z-hr   s   usage: r    )r   r   
assertTrue
startswith)r   r3   r4   r5   s       r   test_help_flagzTestTool.test_help_flag   sK    'k4@CQz23c"r    c                    | j                         }t        ddd|      \  }}}| j                  |d       | j                  |j                         | j                  j                         j                                | j                  |d       y )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   sy    $$&'k=&QCQ)66==?JJL	Nc"r    c                     d}t        j                  d      }t        j                  ddddf}t	        j
                  ||ddd      }| j                  |j                  |       | j                  |j                  d	       y )
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   so     "  ~~t[*cA..VDt[_`0,r    c                     d}d}t         j                  dddf}t        j                  ||ddd      }| j	                  |j
                  |       | j	                  |j                  d       y )	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   s]    ~~t[-?..VDt[_`0,r    c                     d}d}t         j                  dddf}t        j                  ||ddd      }| j	                  |j
                  |       | j	                  |j                  d       y )	NrO   z[
	1,
	2
]
r	   r
   z--tabTr   r   rU   rQ   s        r   test_tabzTestTool.test_tab   s]    $~~t['9..VDt[_`0,r    c                     d}d}t         j                  dddf}t        j                  ||ddd      }| j	                  |j
                  |       | j	                  |j                  d       y )	Nz	[ 1 ,
 2]z[1,2]
r	   r
   z	--compactTr   r   rU   rQ   s        r   test_compactzTestTool.test_compact   s]    ~~t[+=..VDt[_`0,r    c                 T   | j                  d      }t        j                  dz   }| j                  t        j
                  |       t        ddd||       t        |d      5 }|j                         j                         }d d d        g d}| j                  |       y # 1 sw Y    xY w)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""V+		7+{,?Q'4  	*AFFH'')E	* B)		* 	*s    BB'c                 R   | j                  d      }t        j                  dz   }| j                  t        j
                  |       t        dd||       t        |d      5 }|j                         j                         }d d d        g d}| j                  |       y # 1 sw Y    xY w)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""V+		7+{FG<'4  	*AFFH'')E	* ?)		* 	*s   BB&win32z-The test is failed with ValueError on Windowsc                 <   t         j                  ddg}t        j                  |t        j                  t        j                        }|j
                  j                          |j                  d       | j                  |j                  t        j                         y )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   sj    ~~t[1'1&0oo7 	!%++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, $HOO % 	M
 'x ( 	"-##	##-##----	*	* X__S\\G+-\]7 ^7r    r   )rp   r)   r   r8   rx   r   testr   test.supportr   test.support.script_helperr   requires_subprocessTestCaser   r{   r    r   <module>r      sO     	 
     " 7 Z7x   Z7 Z7r    