a
    ze                     @   s   d 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m	Z	 ddl
mZ ejejdddZG d	d
 d
ejZedkre  dS )z!Test the interactive interpreter.    N)dedent)cpython_onlySuppressCrashReport)kill_python)stdoutstderrc                 O   sh   t jt jtjd}|ddg}|| |dtt j	}d|d< t
j|ftjdt
j| |d|S )	zRun the Python REPL with the given arguments.

    kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
    object.
    z<stdin>z-Ez-ienvZvt100ZTERMT)
executabletextstdinr   r   )ospathjoindirnamesysr	   extend
setdefaultdictenviron
subprocessPopenPIPE)r   r   argskwZstdin_fnameZcmd_liner    r   $/usr/lib/python3.9/test/test_repl.py
spawn_repl   s    

r   c                   @   s,   e Zd Zedd Zedd Zdd ZdS )TestInteractiveInterpreterc                 C   sj   d}t |}t }t  |j| W d    n1 s:0    Y  t|}| d| | |jd d S )Nz
            import sys, _testcapi
            1/0
            print('After the exception.')
            _testcapi.set_nomemory(0)
            sys.exit(0)
        zAfter the exception.)   x   )r   r   r   r   writer   assertIn
returncodeself
user_inputpoutputr   r   r   test_no_memory)   s    *z)TestInteractiveInterpreter.test_no_memoryc                 C   s8   d}t |}t }|j| t|}| |jd d S )Na          x = """<?xml version="1.0" encoding="iso-8859-1"?>
        <test>
            <Users>
                <fun25>
                    <limits>
                        <total>0KiB</total>
                        <kbps>0</kbps>
                        <rps>1.3</rps>
                        <connections>0</connections>
                    </limits>
                    <usages>
                        <total>16738211KiB</total>
                        <kbps>237.15</kbps>
                        <rps>1.3</rps>
                        <connections>0</connections>
                    </usages>
                    <time_to_refresh>never</time_to_refresh>
                    <limit_exceeded_URL>none</limit_exceeded_URL>
                </fun25>
            </Users>
        </test>"""
        r   )r   r   r   r    r   assertEqualr"   r#   r   r   r   test_multiline_string_parsing>   s    z8TestInteractiveInterpreter.test_multiline_string_parsingc                 C   sF   t d}t d}td|}||d }| |jd | d| d S )NzY
            import os
            print("before close")
            os.close(0)
        zl
            from test.support import suppress_msvcrt_asserts
            suppress_msvcrt_asserts()
        z-cr   zbefore close)r   r   communicater)   r"   r!   )r$   r%   Zprepare_replprocessr'   r   r   r   test_close_stdin_   s    
z+TestInteractiveInterpreter.test_close_stdinN)__name__
__module____qualname__r   r(   r*   r-   r   r   r   r   r   '   s
   

 r   __main__)__doc__r   r   Zunittestr   textwrapr   Ztest.supportr   r   Ztest.support.script_helperr   r   STDOUTr   ZTestCaser   r.   mainr   r   r   r   <module>   s   H