a
    3j)                     @   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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re  dS )    N)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yF   |j}Y n0 || ||D ]}|	| qV|j
|j }}|rtjd||f trt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   W/www/server/python_manager/versions/3.9.10/lib/python3.9/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   setUp@   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   tearDownH   s    zZipSupportTests.tearDownc              	   C   s   d}t j }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= 0 W d    n1 s0    Y  d S )Nzdef foo(): pass
__init__zip_pkgtest_zipr   )r   r   temp_dirr   osr'   joinbasenamer   remover&   insertr0   ZassertEqualinspect	getsourceZfoomodules)r,   test_srcdZ	init_nameZname_in_zipzip_namerun_namer0   r   r   r    test_inspect_getsource_issue4223N   s    

z0ZipSupportTests.test_inspect_getsource_issue4223c                 C   sP  t t}|dd}|dd}|dd}i }tttfD ]>}t |}|dd}|jdd }|d	d
}|||< q<t	j
 }t|d|}t|d|\}}	t|d2}
| D ]\}}|
|d | qW d    n1 s0    Y  tr<t|d$}td|  |  W d    n1 s20    Y  t| tjd| dd l}z|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|j1|j2g}|j3|j4|j5g}|D ]}t6|| qW tj7d= n
tj7d= 0 W d    n1 sB0    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_r1   az.pyrzContents of %r:r   )8r8   r9   r   replacer   r	   r
   r   splitr   r   r2   r   r   zipfileZipFileitemsZwritestrr   r   Zprintdirr3   r6   r&   r'   r7   r@   ZSampleClassZNestedClassr/   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srcZmod_namer<   script_namer=   r>   zZzip_filer@   Zknown_good_testsZfail_due_to_missing_data_filesr   r   r   r   test_doctest_issue4197^   s    


0(
	 z&ZipSupportTests.test_doctest_issue4197c                 C   s   t d}d}tj }t|d|}t|\}}}||df }trbtd| td tt	| | 
|d| t|d|d	\}	}
t|	\}}}||
df }trtd| td tt	| | 
|d| W d    n1 s0    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-8r1   __main__.py)textwrapdedentr   r   r2   r   r   r   r   asciiassertInencoder   )r,   r;   patternr<   rN   rcouterrZexpectedr=   r>   r   r   r   test_doctest_main_issue4197   s*    


z+ZipSupportTests.test_doctest_main_issue4197c                 C   s   t d}tj }t|d|}t|}|jd t	|}| 
tj|d| t|d|d\}}t|}|jd t	|}| 
tj|d| W d    n1 s0    Y  d S )Nz                    def f():
                        pass

                    import pdb
                    pdb.Pdb(nosigint=True).runcall(f)
                    rQ   s   l
rR   r1   rS   )rT   rU   r   r   r2   r   r   stdinwriter   rW   r3   r'   normcaserX   r   )r,   r;   r<   rN   pdatar=   r>   r   r   r   test_pdb_issue4201   s    
z"ZipSupportTests.test_pdb_issue4201N)	r   r   r   r-   r.   r?   rP   r]   rc   r   r   r   r   r   7   s   	[r   c                   C   s   t j  d S r    )r   r   reap_childrenr   r   r   r   tearDownModule   s    re   __main__)Ztest.supportr   r3   Zos.pathr&   rT   rG   r#   r   r8   r!   ZunittestZtest.support.script_helperr   r   r   r   r   r   r   r   r   r	   r
   r   ZTestCaser   re   r   mainr   r   r   r   <module>   s&    8