o
    wi                      @   sD  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Zd dlZd dlZd dl	m
Z
 d dlZd dlZd dlm  mZ d dlmZ e je jeZe jedZe jedZeeZdd eedD Z W d   n1 srw   Y  da!d	d
 Z"G dd dej#Z$G dd de$Z%G dd de%Z&e'dkre(  dS dS )    N)	ccompiler)Cygdbcodefilecfuncs.cc                 C   s   i | ]	\}}|  |qS  )strip).0iliner   r   `/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/Cython/Debugger/Tests/TestLibCython.py
<dictcomp>   s    r      c               	   C   sF  t d urt S da ztjg dtjd} W n ty   d }Y nw |  \}}d}t||dd}|rt	t
t| }|ddgkrd	a tjd
dG}|d |  tjddd|jgtjd} |  \}}zt	t
t|dd }|ddgk r~da W n ty   da Y nw W d    n1 sw   Y  t std t S )NF)gdbz-nxz	--version)stdoutzGNU gdb [^\d]*(\d+)\.(\d+)asciiignore      Tzw+)modez8python import sys; print("%s %s" % sys.version_info[:2])r   -batch-xz6Skipping gdb tests, need gdb >= 7.2 with Python >= 2.7)have_gdb
subprocessPopenPIPEOSErrorcommunicaterematchdecodelistmapintgroupstempfileNamedTemporaryFilewriteflushnamesplit
ValueErrorwarningswarn)pgdb_versionr   _regexgdb_version_numberpython_version_scriptinternal_python_versionr   r   r   test_gdb   sJ   
r4   c                   @   s   e Zd Zdd Zdd ZdS )DebuggerTestCasec                 C   s  t  sdS t | _tj| jd| _tj| jdd| _tj| jd| _	t
 | _zt| j tt| j tt| j	d  ttdd| j	d  t }|jdgd	d
gd t| jd| jd}t }tjd| jdttd|}ttjd}tj}|t_|  z4|j d| jddd	| jdd| |j!|d |d |d dddgid W |"  |t_|#  W dS |"  |t_|#  w    t| j  )z
        Run gdb and have cygdb import the debug information from the code
        defined in TestParseTreeTransforms's setUp method
        Nzcodefile.pyxcython_debugcython_debug_info_codefilecfuncsz.cz.hr   Tz-fPIC)debugextra_postargsr   )test_directorymodulemodule_pathF)workdircleanup_workdirtagsw)	gdb_debug
output_dir)	targetdirincdirannotateextra_compile_optionsr;   r<   extra_objectszcfuncs.o)r;   r<   r>   rE   extra_extension_argsr   )$r4   r$   mkdtemptempdirospathjoindestfile
debug_destcfuncs_destfilegetcwdcwdchdirshutilcopyr   cfuncs_filereplacer   new_compilercompiledict	build_extOptimizationruntestsCythonCompileTestCase
parse_tagsopendevnullsysstderrdisable_optimization
run_cythonrun_distutilsrestore_stateclose)selfcompileroptsoptimization_disablercython_compile_testcase
new_stderrrd   r   r   r   setUpG   s~   


	
zDebuggerTestCase.setUpc                 C   s&   t  sd S t| j t| j d S N)r4   rL   rT   rS   rU   rmtreerK   rj   r   r   r   tearDown   s   zDebuggerTestCase.tearDownN)__name__
__module____qualname__rp   rt   r   r   r   r   r5   E   s    Zr5   c                       s(   e Zd Z fddZ fddZ  ZS )GdbDebuggerTestCasec              	      s  t  sd S t   td}tdtjd d f }t| j	|| _
t| j
d}|| W d    n1 s:w   Y  ddd| j
dd	tjd
dg	}g }tjd}|r[|| |tjtjtjtj ttjtj|d}tj|tjtj|d| _d S )Na              python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                sys.stderr.flush()
                sys.stdout.flush()
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            z            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            r   ar   r   r   z-nz--argsz-czimport codefile
PYTHONPATH)rz   )r   rd   env)r4   superrp   textwrapdedentrc   version_infocygdbmake_command_filerK   gdb_command_filera   r&   
executablerL   environgetappendrM   dirnameabspathCython__file__r[   pathseprN   r   r   r   r-   )rj   prefix_codecodefargspathsrM   r{   	__class__r   r   rp      s<   

	
zGdbDebuggerTestCase.setUpc              	      s   t  sd S z9t   | jr6z| jj  W n   Y z| jj  W n   Y | j  W t	| j
 d S W t	| j
 d S t	| j
 w rq   )r4   r|   rt   r-   r   ri   rd   waitrL   remover   rs   r   r   r   rt      s   
zGdbDebuggerTestCase.tearDown)ru   rv   rw   rp   rt   __classcell__r   r   r   r   rx      s    <rx   c                   @   s   e Zd Zdd ZdS )TestAllc           	      C   s   t  sd S | j \}}|d}|d}| jj}|dkr,tj| tj| d S |dkrUd}d||f }d||f }d||f }d|||||f }tj| d S d S )	NzUTF-8r   r   z******************************z%s   v INSIDE GDB v   %sz%s   v STDERR v   %sz%s   ^ INSIDE GDB ^   %sz
%s
%s%s
%s%s)r4   r-   r   r   
returncoderc   rd   r&   )	rj   outerrexit_statusborderstartrd   enderrmsgr   r   r   test_all   s"   

zTestAll.test_allN)ru   rv   rw   r   r   r   r   r   r      s    r   __main__))rL   r   rc   rU   r+   r}   unittestr$   r   	distutilsr   r^   Cython.Distutils.extensionr   Cython.Distutils.old_build_ext	Distutilsold_build_extr\   Cython.Debuggerr   r   rM   r   r   r   rootrN   r   rW   ra   r   	enumeratesource_to_linenor   r4   TestCaser5   rx   r   ru   mainr   r   r   r   <module>   s8    
)cN