o
    g)                     @   s   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
Z
d dlZd dl mZ d dlmZmZmZmZmZ ejjZd dlmZmZmZmZ dd ZG dd dejZd	d
 Zedkrke  dS dS )    N)	os_helper)spawn_pythonkill_pythonassert_python_okmake_scriptmake_zip_script)test_doctestsample_doctestsample_doctest_no_doctestssample_doctest_no_docstringsc                 C   s   t jtdd}t jtd}z
d| j| jf }W n ty#   |j}Y nw || ||D ]}|	| q+|j
|j}}|rFtjd||f trQtd|j|f  ||fS )NF)verboseZrecurse)r   z%s.%sz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)doctestZDocTestFinderr   ZDocTestRunner
__module____qualname__AttributeError__name__findrunZfailuresZtriestestsupportZ
TestFailedprint)objmodulefinderZrunnernameZexampleft r   Q/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_zipimport_support.py_run_object_doctest$   s   
r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ZipSupportTestsc                 C   sP   t   tj  tjd d  | _tjd d  | _tjd d  | _tj	  d S N)
	linecache
clearcache	zipimport_zip_directory_cacheclearsyspath	meta_path
path_hookspath_importer_cacheselfr   r   r   setUpA   s   
zZipSupportTests.setUpc                 C   s>   | j tj d d < | jtjd d < | jtjd d < tj  d S r!   )r(   r'   r)   r*   r+   r&   r,   r   r   r   tearDownI   s   zZipSupportTests.tearDownc              	   C   s   d}t  I}t|d|}tjdtj|}t|d||\}}t| t	j
d| dd l}z| t|j| W t	jd= nt	jd= w W d    d S 1 sRw   Y  d S )Nzdef foo(): pass
__init__zip_pkgtest_zipr   )r   temp_dirr   osr(   joinbasenamer   remover'   insertr1   ZassertEqualinspect	getsourceZfoomodules)r-   test_srcdZ	init_nameZname_in_zipzip_namerun_namer1   r   r   r    test_inspect_getsource_issue4223O   s    


"z0ZipSupportTests.test_inspect_getsource_issue4223c                 C   sH  t t}|dd}|dd}|dd}i }tttfD ]}t |}|dd}|jdd }|d	d
}|||< qt	
 }t|d|}t|d|\}}	t|d}
| D ]\}}|
|d | q\W d    n1 ssw   Y  trt|d}td|  |  W d    n1 sw   Y  t| tjd| dd l}za|j|jj|jjj|jj|jj|jj|jj|jj |jj!|j"|j"j|j"j |j"j!|j#|j$|j%|j&j'|j&j(|j&j)|j&j*|j&j+|j,|j-|j.|j/|j0|j1g}|j2|j3|j4g}|D ]}t5|| qW tj6d= ntj6d= w W d    d S 1 sw   Y  d S )Nzfrom test import test_doctestz*import test_zipped_doctest as test_doctestztest.test_doctesttest_zipped_doctestztest.sample_doctestZsample_zipped_doctest.Zsample_Zsample_zipped_r2   az.pyrzContents of %r:r   )7r9   r:   r   replacer	   r
   r   r   splitr   r3   r   r   zipfileZipFileitemsZwritestrr   r   Zprintdirr4   r7   r'   r(   r8   rA   ZSampleClassZNestedClassr0   Za_classmethodZ
a_propertyZa_staticmethodZdoublegetZSampleNewStyleClassZsample_funcZtest_DocTestZtest_DocTestParserZtest_DocTestRunnerZbasics
exceptionsZoption_directivesZoptionflagsZverbose_flagZtest_ExampleZ
test_debugZtest_testsourceZtest_trailing_space_in_testZtest_DocTestSuiteZtest_DocTestFinderZtest_DocFileSuiteZtest_testfileZtest_unittest_reportflagsr   r;   )r-   r<   Zsample_sourcesmodsrcmod_namer=   script_namer>   r?   zZzip_filerA   Zknown_good_testsZfail_due_to_missing_data_filesr   r   r   r   test_doctest_issue4197_   s   





	 $z&ZipSupportTests.test_doctest_issue4197c                 C   s   t d}d}t f}t|d|}t|\}}}||df }tr0td| td tt| | 	|
d| t|d|d	\}	}
t|	\}}}||
df }tr`td| td tt| | 	|
d| W d    d S 1 stw   Y  d S )
Nz                    class Test:
                        ">>> 'line 2'"
                        pass

                    import doctest
                    doctest.testmod()
                    zFile "%s", line 2, in %sscriptz__main__.TestzExpected linezGot stdout:utf-8r2   __main__.py)textwrapdedentr   r3   r   r   r   r   asciiassertInencoder   )r-   r<   patternr=   rP   rcouterrZexpectedr>   r?   r   r   r   test_doctest_main_issue4197   s,   



"z+ZipSupportTests.test_doctest_main_issue4197c                 C   s   t d}t N}t|d|}t|}|jd t|}| 	t
j|d| t|d|d\}}t|}|jd t|}| 	t
j|d| W d    d S 1 sZw   Y  d S )Nz                    def f():
                        pass

                    import pdb
                    pdb.Pdb(nosigint=True).runcall(f)
                    rS   s   l
rT   r2   rU   )rV   rW   r   r3   r   r   stdinwriter   rY   r4   r(   normcaserZ   r   )r-   r<   r=   rP   pdatar>   r?   r   r   r   test_pdb_issue4201   s   

"z"ZipSupportTests.test_pdb_issue4201N)	r   r   r   r.   r/   r@   rR   r_   re   r   r   r   r   r    8   s    	[r    c                   C   s   t j  d S r!   )r   r   reap_childrenr   r   r   r   tearDownModule   s   rg   __main__)Ztest.supportr   r4   Zos.pathr'   rV   rH   r$   r   r9   r"   Zunittestr   Ztest.support.script_helperr   r   r   r   r   r   r   r   r	   r
   r   r   ZTestCaser    rg   r   mainr   r   r   r   <module>   s,    8