
    dafE*                     ,   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 Z G d dej6                        Zd Zed	k(  r ej>                          yy)
    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                    t        j                  t        d      }t        j                  t              }	 | j                  d| j
                  }|j                  | ||      D ]  }|j                  |        |j                  |j                  }}|r$t        j                  j                  d||fz        t        rt        d|j                  |fz         ||fS # t        $ r |j                  }Y w xY w)NF)verboserecurse)r   .z%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)doctestDocTestFinderr   DocTestRunner
__module____qualname__AttributeError__name__findrunfailurestriestestsupport
TestFailedprint)objmodulefinderrunnernameexamplefts           6/root/Python-3.12.4/Lib/test/test_zipimport_support.py_run_object_doctestr)   %   s    ""7EBF""73F..#*:*:; ;;sD&1 

7??FLLqAll%%&@Aq6&IJJ=RS@TTUa4K  s   C C54C5c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ZipSupportTestsc                 4   t        j                          t        j                  j	                          t
        j                  d d  | _        t
        j                  d d  | _        t
        j                  d d  | _        t
        j                  j	                          y N)
	linecache
clearcache	zipimport_zip_directory_cacheclearsyspath	meta_path
path_hookspath_importer_cacheselfs    r(   setUpzZipSupportTests.setUpB   sa    &&,,.HHQK	q)..+%%'    c                     | j                   t        j                   d d  | j                  t        j                  d d  | j                  t        j                  d d  t        j                  j                          y r-   )r4   r3   r5   r6   r7   r2   r8   s    r(   tearDownzZipSupportTests.tearDownJ   sI    ii>>a OOq%%'r;   c                 2   d}t        j                         5 }t        |d|      }t        j                  j                  dt        j                  j                  |            }t        |d||      \  }}t        j                  |       t        j                  j                  d|       dd l}	 | j                  t        j                  |j                        |       t        j                   d= 	 d d d        y # t        j                   d= w xY w# 1 sw Y   y xY w)Nzdef foo(): pass
__init__zip_pkgtest_zipr   )r   temp_dirr   osr4   joinbasenamer   remover3   insertr@   assertEqualinspect	getsourcefoomodules)r9   test_srcd	init_namename_in_zipzip_namerun_namer@   s           r(    test_inspect_getsource_issue4223z0ZipSupportTests.test_inspect_getsource_issue4223P   s    &! 	+Q#Az8<I'',,y')ww'7'7	'BDK!0J09;"HHhIIi HHOOAx(+  !2!27;;!?JKK	*	+ 	+ KK	*	+ 	+s$   BD-/C7D7D

DDc                 F   t        j                  t              }|j                  dd      }|j                  dd      }|j                  dd      }i }t        t
        t        fD ]^  }t        j                  |      }|j                  dd      }|j                  j                  d      d   }|j                  d	d
      }|||<   ` t        j                         5 }t        |d|      }t        |d|      \  }}	t        j                  |d      5 }
|j                         D ]  \  }}|
j!                  |dz   |        	 d d d        t"        r=t        j                  |d      5 }t%        d|z         |j'                          d d d        t)        j*                  |       t,        j.                  j1                  d|       dd l}	 |j4                  |j4                  j6                  |j4                  j6                  j8                  |j4                  j8                  |j4                  j:                  |j4                  j<                  |j4                  j>                  |j4                  j@                  |j4                  jB                  |jD                  |jD                  j8                  |jD                  j@                  |jD                  jB                  |jF                  |jH                  |jJ                  |jL                  jN                  |jL                  jP                  |jL                  jR                  |jL                  jT                  |jL                  jV                  |jX                  |jZ                  |j\                  |j^                  |j`                  |jb                  g}|jd                  |jf                  |jh                  g}|D ]  }tk        ||        	 t,        jl                  d= 	 d d d        y # 1 sw Y   xY w# 1 sw Y   xxY w# t,        jl                  d= w xY w# 1 sw Y   y xY w)Nz*from test.test_doctest import test_doctestz*import test_zipped_doctest as test_doctestztest.test_doctest.test_doctesttest_zipped_doctestz test.test_doctest.sample_doctestsample_zipped_doctestr   sample_sample_zipped_rA   az.pyrzContents of %r:r   )7rI   rJ   r	   replacer
   r   r   r   splitr   rB   r   r   zipfileZipFileitemswritestrr   r   printdirrC   rF   r3   r4   rG   rU   SampleClassNestedClassr?   a_classmethod
a_propertya_staticmethoddoublegetSampleNewStyleClasssample_functest_DocTesttest_DocTestParsertest_DocTestRunnerbasics
exceptionsoption_directivesoptionflagsverbose_flagtest_Example
test_debugtest_testsourcetest_trailing_space_in_testtest_DocTestSuitetest_DocTestFindertest_DocFileSuitetest_testfiletest_unittest_reportflagsr)   rL   )r9   rM   sample_sourcesmodsrcmod_namerN   script_namerQ   rR   zzip_filerU   known_good_testsfail_due_to_missing_data_filesr    s                   r(   test_doctest_issue4197z&ZipSupportTests.test_doctest_issue4197`   s    $$\2##EEG ##$D$9;##$F$;= "$>02 	+C##C(C++>@UVC ||))#.r2H''	3CDH'*N8$	+ ! ?	7Q%a)>,46K!0J0;"=Hh3/ 61%3%9%9%; 6MHcJJx%/566 __Xs3 (x,x78%%'( IIk"HHOOAx(&07 (33'33??'33??HH'33<<'33AA'33>>'33BB'33::'3377';;';;DD';;BB';;??'33'44'::'::AA'::EE'::LL'::FF'::GG'44'22'77'CC'99'::7$ @ (99'55'AA2. , BC'-@AB KK 56?	7 ?	7
6 6( (l KK 56?	7 ?	7sV   4P.O';$PO4>AP HPP'O1	,P4O>	9PPPP c                 `   t        j                  d      }d}t        j                         5 }t	        |d|      }t        |      \  }}}||dfz  }t        r+t        d|       t        d       t        t        |             | j                  |j                  d      |       t        |d|d	      \  }	}
t        |	      \  }}}||
dfz  }t        r+t        d|       t        d       t        t        |             | j                  |j                  d      |       d d d        y # 1 sw Y   y xY w)
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-8rA   __main__.py)textwrapdedentr   rB   r   r   r   r   asciiassertInencoder   )r9   rM   patternrN   r   rcouterrexpectedrQ   rR   s              r(   test_doctest_main_issue4197z+ZipSupportTests.test_doctest_main_issue4197   s   ?? $  -! 	9Q%a8<K+K8LBS+!??H1}%uSz"MM(//'2C8!0J0;]"LHh+H5LBS(O!<<H1}%uSz"MM(//'2C8#	9 	9 	9s   C/D$$D-c                 x   t        j                  d      }t        j                         5 }t	        |d|      }t        |      }|j                  j                  d       t        |      }| j                  t        j                  j                  |j                  d            |       t        |d|d      \  }}t        |      }|j                  j                  d       t        |      }| j                  t        j                  j                  |j                  d            |       d d d        y # 1 sw Y   y xY w)Nz                    def f():
                        pass

                    import pdb
                    pdb.Pdb(nosigint=True).runcall(f)
                    r   s   l
r   rA   r   )r   r   r   rB   r   r   stdinwriter   r   rC   r4   normcaser   r   )r9   rM   rN   r   pdatarQ   rR   s           r(   test_pdb_issue4201z"ZipSupportTests.test_pdb_issue4201   s    ?? $  ! 	LQ%a8<K[)AGGMM&!q>DMM"''**;+=+=g+FGN!0J0;]"LHhX&AGGMM&!q>DMM"''**8??7+CDdK	L 	L 	Ls   C=D00D9N)	r   r   r   r:   r=   rS   r   r   r    r;   r(   r+   r+   9   s#    ((+ Y7v9:Lr;   r+   c                  @    t         j                  j                          y r-   )r   r   reap_childrenr   r;   r(   tearDownModuler      s    LL r;   __main__) test.supportr   rC   os.pathr3   r   r^   r0   r   rI   r.   unittestr   test.support.script_helperr   r   r   r   r   r   r   test.test_doctestr	   r
   r   r   r)   TestCaser+   r   r   mainr   r;   r(   <module>r      s   
  	  
        "F F ,,

= =
(tLh'' tLn! zHMMO r;   