U
    /e2                     @   s  d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
mZ dd Zdad	d
 Zdd Ze jddddd ZdddddZd&ddZdd Zdd ZdZdadZe jedd d! Zd d"lmZmZmZ e jd#d$ Zeserd%d! ZdS )'    N)	IS_JYTHONIS_IRONPYTHON)TEST_CYTHON)PYDEVD_TEST_VM)	pydev_logc                 C   s  t dtf  t dtf  zdd l}W n tk
r<   Y nX t d| f  t d t dtjf  t dtjf  t	tdrt d	tj
f  t	td
rt dtjf  t	tdrt dt f  t	tdrt dt f  tjD ].}tj|rtj|dkrt d|f  qd S )NzPYDEVD_USE_CYTHON: %szPYDEVD_TEST_VM: %sr   zNumber of processors: %szRelevant system paths:zsys.executable: %szsys.prefix: %sbase_prefixzsys.base_prefix: %sreal_prefixzsys.real_prefix: %sgetusersitepackageszsite.getusersitepackages(): %sgetsitepackageszsite.getsitepackages(): %szsite-packagesz+Folder with "site-packages" in sys.path: %s)printr   r   multiprocessingImportError	cpu_countsys
executableprefixhasattrr   r   siter	   r
   pathosexistsbasename)configr   r    r   E/tmp/pip-unpacked-wheel-dg3irmqq/debugpy/_vendored/pydevd/conftest.pypytest_report_header   s*    




r   Fc                     sj   t rd S da dd l ttdrft drfdd ldd lG  fddd j} |  }d|_|  d S )NTr   _current_frames	enumeratec                       s   e Zd Z fddZdS )z._start_monitoring_threads.<locals>.DumpThreadsc                    s&   d i }z(  D ]}d|j|jf ||j< qW n   Y nX dddg}t  D ]\}}|d |d|	||  |d d	|j
krtjt|j
d	 d
  |D ]6\}}}}	|d|||f  |	r|d|	   qqZ|d tjd
| dd l}
|
d d S )N   z%s  (daemon: %s)zO===============================================================================zEpydev pyunit runner: Threads still found running after tests finishedzO================================= Thread Dump =================================zP
-------------------------------------------------------------------------------z
 Thread %s self
z File "%s", line %d, in %sz   %szP
=============================== END Thread Dump ===============================r   {   )sleepr   namedaemonidentr   r   itemsappendgetf_localsstderrwritestrextract_stackstripjoinr   _exit)r    Zthread_id_to_nametZstack_traceZ	thread_idstackfilenamelinenor$   liner   	threadingtime	tracebackr   r   run<   s2    




z2_start_monitoring_threads.<locals>.DumpThreads.runN)__name__
__module____qualname__r;   r   r7   r   r   DumpThreads:   s   r?   )	_started_monitoring_threadsr8   r   r   r9   r:   Threadr%   start)r?   Zdump_current_frames_threadr   r7   r   _start_monitoring_threads-   s    $rC   c                   C   s
   t   d S NrC   r   r   r   r   pytest_unconfigurec   s    rF   sessionT)Zscopeautousec                   c   s   d V  t   d S rD   rE   r   r   r   r   check_no_threadsg   s    rI   )	BKMGTPEZY)	byteZkiloZmegaZgigaZteraZpetaZexaZzettaZiotta)	ZBiZKiZMiZGiZTiPiZEiZZiZYi)	rS   ZkibiZmebiZgibiZtebiZpebiZexbiZzebiZyobi)	customaryZcustomary_extZiecZiec_ext%(value).1f %(symbol)srU   c                 C   s   t | } | dk rtdt| }i }t|dd D ]\}}d|d d > ||< q4t|dd D ].}| || krbt| ||  }|t    S qb|t|d | d S )z
    Bytes-to-human / human-to-bytes converter.
    Based on: http://goo.gl/kTQMs
    Working with Python 2.x and 3.x.

    Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    License: MIT
    r   zn < 0   N
   )symbolvalue)int
ValueErrorSYMBOLSr   reversedfloatlocalsdict)nformatsymbolsr   isrY   rZ   r   r   r   bytes2humanx   s    .rg   c                 C   s"   dt | jt | j| jt|f S )Nz7Total: %s, Available: %s, Used: %s %%, Curr process: %s)rg   total	availablepercentformat_process_memory_info)memory_infoZcurr_proc_memory_infor   r   r   format_memory_info   s       rm   c                 C   s
   t | jS rD   )rg   rss)Zproc_memory_infor   r   r   rk      s    rk   )rH   c              
   c   s  zdd l }W n tk
r(   d V  Y d S X tdd | D }|  }trtrz"ddlm	}m
} || }W n   t  Y nX tjd| jt| |f  d V  g }| D ]t}|j|krzFz| }	W n   d}	Y nX |d| |j|	t| f  W q |j|jfk
r0   Y qX q|  }
trzz|
j|j dkrtr|| }|||}tjd	 tjd
 tjd	 || tjd	 dandaW n   t  Y nX tjd| jt| |
|sdndd| f  d S )Nr   c                 s   s   | ]}|j V  qd S rD   )pid).0procr   r   r   	<genexpr>   s     z-before_after_each_function.<locals>.<genexpr>)summarymuppyz
===============================================================================
Memory before: %s
%s
===============================================================================
z<unable to get>zNew Process: %s(%s - %s) - %si zP===============================================================================
zLeak info:
TFz
===============================================================================
Memory after: %s
%s%s
===============================================================================


r   z
Leaked processes:
r!   ) psutilr   setZprocess_iterProcessrl   _global_collect_infoDEBUG_MEMORY_INFOZpymplerrs   rt   Z	summarizeZget_objectsr   	exceptionr   stdoutr,   functionrm   Zvirtual_memoryro   cmdliner(   r$   rk   ZNoSuchProcessZAccessDeniedrn   Zget_diffprint_r0   )requestru   Zcurrent_pidsZbefore_curr_proc_memory_infors   rt   Zsum1Zprocesses_inforq   r}   Zafter_curr_proc_memory_infoZsum2Zdiffr   r   r   before_after_each_function   sz    



r   )data_regressiondatadiroriginal_datadirc                    s$   ddl ddl  fdd}|S )a5  
    Based on debugpy pyfile fixture (adapter for older versions of Python)

    A fixture providing a factory function that generates .py files.

    The returned factory takes a single function with an empty argument list,
    generates a temporary file that contains the code corresponding to the
    function body, and returns the full path to the generated file. Idiomatic
    use is as a decorator, e.g.:

        @pyfile
        def script_file():
            print('fizz')
            print('buzz')

    will produce a temporary file named script_file.py containing:

        print('fizz')
        print('buzz')

    and the variable script_file will contain the path to that file.

    In order for the factory to be able to extract the function body properly,
    function header ("def") must all be on a single line, with nothing after
    the colon but whitespace.

    Note that because the code is physically in a separate file when it runs,
    it cannot reuse top-level module imports - it must import all the modules
    that it uses locally. When linter complains, use #noqa.

    Returns a py.path.local instance that has the additional attribute "lines".
    After the source is writen to disk, tests.code.get_marked_line_numbers() is
    invoked on the resulting file to compute the value of that attribute.
    r   Nc              	      s  t | jst| j}| \} }d}| D ],}| }|drP|drP qb|d7 }q,td| |d d  } | szt| D ]}| r~ qq~t	|t	|
    fdd| D } d| } tjt|d	 }tj|rtd
|f t|d}||  W 5 Q R X |S )Nr   def:rW   z!Failed to locate function header.c                    s$   g | ]}|  r| d  ndqS )Nr!   )r/   )rp   lindentr   r   
<listcomp>_  s     z+pyfile.<locals>.factory.<locals>.<listcomp>r   z.pyz%s already exists.w)
isinstanceFunctionTypeAssertionErrorr<   getsourcelinesr/   
startswithendswithr\   lenlstripr0   r   r   r-   r   openr,   )sourcer$   _Z
def_linenor6   Ztmpfilestreaminspecttmpdirtypesr   r   factoryD  s.    

zpyfile.<locals>.factory)r   r   )r   r   r   r   r   r   pyfile  s    $&r   c                   C   s   d S rD   r   r   r   r   r   r   p  s    )rV   rU   )Zpytestr   Z_pydevd_bundle.pydevd_constantsr   r   Ztests_python.debug_constantsr   r   r   r   Z_pydev_bundler   r   r@   rC   rF   ZfixturerI   r]   rg   rm   rk   ry   rx   ZPRINT_MEMORY_BEFORE_AFTER_TESTr   Ztests_python.regression_checkr   r   r   r   r   r   r   r   <module>   s>   6


<

U
O
