
    ;e                    h   	 d dl mZ d dlmZ d dlm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Zd dlZej        s ej        d          d Z G d d          Z G d	 d
e          Z G d d          Zd Zd Z G d d          Z G d dej                  Zd Z G d d          Zd Zd Z  e!ed          r ej"                    sd Z#d Z$d Z%d Z&d Z' G d d          Z(e(d              Z)d! Z*d" Z+ G d# d$e	j,        j-        e	j,        j.                  Z/ G d% d&          Z0ej1        d'             Z2d( Z3d) Z4	  ej5        d*           d+Z6n# e7$ r d,Z6Y nw xY we6rd- Z8d. Z9d/ Z:d0 Z;d1 Z<d2 Z=e>d3k    r'd4ej?        v r e=d5           dS  ej@                     dS dS )6    )support)import_helper)	os_helperNz%test_CLI requires subprocess support.c                     	 | | z   S N vs    (/usr/lib/python3.11/test/test_doctest.pysample_funcr   "   s     Q3J    c                       e Zd Z	 d Zd Zd Zd Z ee          Zd Z e	e          Z e
ed          ZdZe	e
d	                         Z G d
 d          ZdS )SampleClassc                     	 || _         d S r   valselfr   s     r   __init__zSampleClass.__init__=       	 r   c                 <    	 t          | j        | j        z             S r   )r   r   r   s    r   doublezSampleClass.doubleD   s     	 48dh.///r   c                     	 | j         S r   r   r   s    r   getzSampleClass.getK       	 xr   c                     	 | dz   S )N   r   r	   s    r   a_staticmethodzSampleClass.a_staticmethodR   s    	 s
r   c                     	 |dz   S )N   r   )clsr
   s     r   a_classmethodzSampleClass.a_classmethodZ   s    	 s
r   zB
        >>> print(SampleClass(22).a_property)
        22
        )doc*   c                     	 | j         S r   )a_class_attribute)r"   s    r   a_classmethod_propertyz"SampleClass.a_classmethod_propertyk   s    	 $$r   c                   $    e Zd Z	 ddZd Zd ZdS )SampleClass.NestedClassr   c                     	 || _         d S r   r   r   s     r   r   z SampleClass.NestedClass.__init__{   s     DHHHr   c                 P    t                               | j        | j        z            S r   )r   NestedClassr   r   s    r   squarezSampleClass.NestedClass.square   s    **48DH+<===r   c                     | j         S r   r   r   s    r   r   zSampleClass.NestedClass.get   s	    8Or   N)r   )__name__
__module____qualname__r   r.   r   r   r   r   r-   r*   t   sK        		 	 	 		> 	> 	>	 	 	 	 	r   r-   N)r0   r1   r2   r   r   r   r   staticmethodr#   classmethodproperty
a_propertyr'   r(   r-   r   r   r   r   r   -   s          0 0 0     "\.11N    K..M# $   J
 % % X [%         r   r   c                   "    e Zd Z	 d Zd Zd ZdS )SampleNewStyleClassc                     	 || _         d S r   r   r   s     r   r   zSampleNewStyleClass.__init__   r   r   c                 <    	 t          | j        | j        z             S r   )r8   r   r   s    r   r   zSampleNewStyleClass.double   s     	 #48dh#6777r   c                     	 | j         S r   r   r   s    r   r   zSampleNewStyleClass.get   r   r   N)r0   r1   r2   r   r   r   r   r   r   r8   r8      sF          8 8 8    r   r8   c                       e Zd Z	 d Zd ZdS )
_FakeInputc                     || _         d S r   )lines)r   r?   s     r   r   z_FakeInput.__init__   s    


r   c                 ^    | j                             d          }t          |           |dz   S )Nr   
)r?   popprint)r   lines     r   readlinez_FakeInput.readline   s*    z~~a  dDyr   N)r0   r1   r2   r   rE   r   r   r   r=   r=      s7              r   r=   c                      d S r   r   r   r   r   test_ExamplerG            r   c                      d S r   r   r   r   r   test_DocTestrJ   2  rH   r   c                   ,    e Zd Zd Zej        rd ZdS dS )test_DocTestFinderc                      d S r   r   r   r   r   basicsztest_DocTestFinder.basics  rH   r   c                      d S r   r   r   r   r   non_Python_modulesz%test_DocTestFinder.non_Python_modules  rH   r   N)r0   r1   r2   rN   int__doc__rP   r   r   r   rL   rL     sL        C C CJ { %$	 $	 $	 $	 $	% %r   rL   c                       e Zd Zd Zd ZdS )TestDocTestFinderc                     ddl m} t          j        d          }||j        d<   	 t          j        |d           d S # t          $ r}t          j        d          |d }~ww xY w)Nr   )calldummyinject_callT)	verbosityzDoctest unwrap failed)	unittest.mockrV   types
ModuleType__dict__r   run_doctest
ValueError
TestFailed)r   rV   dummy_modulees       r   test_issue35753z!TestDocTestFinder.test_issue35753  s     	'&&&&&'00/3m,	E====== 	E 	E 	E$%<==1D	Es   > 
A"AA"c                 2   d}t          j                    5 }t          j                            ||          }t          j        |           t          j                            |           	 t          j	        |          }t          j        |           t          j                                         n7# t          j        |           t          j                                         w xY wt          j        d          }t          j        d          }|                     t!          |                    |                    d           |                     t!          |                    |                    d           d d d            d S # 1 swxY w Y   d S )Ndoctest_empty_pkgF)exclude_emptyTr   r   )tempfileTemporaryDirectoryospathjoinmkdirsysappend	importlibimport_moduler   forgetrB   doctestDocTestFinderassertEquallenfind)r   pkg_name
parent_dirpkg_dirmodinclude_empty_finderexclude_empty_finders          r   test_empty_namespace_packagez.TestDocTestFinder.test_empty_namespace_package  s   &(** 	Ejgll:x88GHWHOOJ'''-h77$X... $X...#*#8u#M#M#M #*#8t#L#L#L S!5!:!:3!?!?@@!DDDS!5!:!:3!?!?@@!DDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es+   AF+B2?3F24C&&BFFFN)r0   r1   r2   rc   r}   r   r   r   rT   rT     s:        
E 
E 
EE E E E Er   rT   c                      d S r   r   r   r   r   test_DocTestParserr     rH   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )test_DocTestRunnerc                      d S r   r   r   r   r   rN   ztest_DocTestRunner.basics=  rH   r   c                      d S r   r   r   r   r   verbose_flagztest_DocTestRunner.verbose_flagz  rH   r   c                      d S r   r   r   r   r   
exceptionsztest_DocTestRunner.exceptions  rH   r   c                      d S r   r   r   r   r   displayhookztest_DocTestRunner.displayhook  rH   r   c                      d S r   r   r   r   r   optionflagsztest_DocTestRunner.optionflags  rH   r   c                      d S r   r   r   r   r   option_directivesz$test_DocTestRunner.option_directivesy  rH   r   N)	r0   r1   r2   rN   r   r   r   r   r   r   r   r   r   r   <  s        < < <zB B BFm m m\  :o o obV V V V Vr   r   c                      d S r   r   r   r   r   test_testsourcer   Q  rH   r   c                      d S r   r   r   r   r   
test_debugr   y  rH   r   gettracec                      d S r   r   r   r   r   test_pdb_set_tracer     s    C	 C	r   c                      d S r   r   r   r   r   test_pdb_set_trace_nestedr     s    S	 S	r   c                      d S r   r   r   r   r   test_DocTestSuiter   t  s    r rr   c                      d S r   r   r   r   r   test_DocFileSuiter     s    c cr   c                      d S r   r   r   r   r   test_trailing_space_in_testr   	  s     r   c                       e Zd Zd Zd ZdS )Wrapperc                 >    || _         t          j        | |           d S r   )func	functoolsupdate_wrapper)r   r   s     r   r   zWrapper.__init__	  s"    	 t,,,,,r   c                       | j         |i | d S r   )r   )r   argskwargss      r   __call__zWrapper.__call__	  s    	4"6"""""r   N)r0   r1   r2   r   r   r   r   r   r   r   	  s2        - - -# # # # #r   r   c                      d S r   r   r   r   r   test_look_in_unwrappedr   	  s     r   c                      d S r   r   r   r   r   test_unittest_reportflagsr   	  s    L Lr   c                      d S r   r   r   r   r   test_testfiler   	  rH   r   c                       e Zd ZddZd ZdS )TestImporterNc                 F    t           j                            |||           S )N)loader)ro   utilspec_from_file_location)r   fullnamerj   targets       r   	find_speczTestImporter.find_spec
  s    ~55hT5RRRr   c                     t          |d          5 }|                                cd d d            S # 1 swxY w Y   d S )Nrb)mode)openread)r   rj   fs      r   get_datazTestImporter.get_data
  s    $T""" 	a6688	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   377r   )r0   r1   r2   r   r   r   r   r   r   r   
  s;        S S S S    r   r   c                       e Zd Zd Zd ZdS )TestHookc                    t           j        d d          | _        t           j        d d          | _        t           j        d d          | _        t           j                            |           t           j                                         t           j        	                                | _
        t                      | _        t           j                            | j                   d S r   )rm   rj   sys_path	meta_path
path_hooksrn   path_importer_cacheclearmodulescopymodules_beforer   importer)r   pathdirs     r   r   zTestHook.__init__
  s    qqq).+   %%'''!k..00$T]+++++r   c                 J   | j         t          j        d d <   | j        t          j        d d <   | j        t          j        d d <   t          j                                         t          j                                         t          j                            | j	                   d S r   )
r   rm   rj   r   r   r   r   r   updater   r   s    r   removezTestHook.remove
  s    m>aaa Oqqq%%'''4./////r   N)r0   r1   r2   r   r   r   r   r   r   r   
  s2        , , ,0 0 0 0 0r   r   c              #      K   t          |           }	 |V  |                                 d S # |                                 w xY wr   )r   r   )r   hooks     r   	test_hookr   
  sD      GD


s	   - Ac                      d S r   r   r   r   r   test_lineendingsr   
  rH   r   c                      d S r   r   r   r   r   test_testmodr     rH   r   u   foo-bär@baz.pyTFc                      d S r   r   r   r   r   test_unicoder   *  rH   r   c                      d S r   r   r   r   r   test_CLIr   E  rH   r   c                      	 d S r   r   r   r   r   %test_no_trailing_whitespace_strippingr   +  s    " r   c                      d S r   r   r   r   r   $test_run_doctestsuite_multiple_timesr   U  s     r   c                     |                     t          j        t                               |                     t          j                               |S r   )addTestrr   DocTestSuite)r   testspatterns      r   
load_testsr   e  s?    	MM'&w//000	MM'&(()))Lr   c                 *   t          j        d          }|                    t          j        t          j        gdd          }|                    d           |                                }t          d           |	                    dd|            d S )	Ntracer   r   )
ignoredirsr   countztest_main()zWriting coverage results...T)show_missingsummarycoverdir)
r   rp   Tracerm   base_prefixbase_exec_prefixrunresultsrC   write_results)r   r   tracerrs       r   test_coverager   k  s    '00E[[S_c6J$L   + +F
JJ}A	
'(((OOt%  ' ' ' ' 'r   __main__z-cz/tmp/doctest.cover)Atestr   test.supportr   r   rr   r   ri   rm   ro   importlib.abcimportlib.utilunittestrg   shutilr[   
contextlibhas_subprocess_supportSkipTestr   r   objectr8   r=   rG   rJ   rL   TestCaserT   r   r   r   r   hasattrr   r   r   r   r   r   r   r   r   r   abcMetaPathFinderResourceLoaderr   r   contextmanagerr   r   r   fsencodesupports_unicodeUnicodeEncodeErrorr   r   r   r   r   r   r0   argvmainr   r   r   <module>r     s         & & & & & & " " " " " "      				 



                     % E
(
C
D
DD	 	 	W W W W W W W Wr    &   @       &w w wrC C CJk k k k k k k k\	E E E E E) E E E@5 5 5nS S S S S S S Sj & & &P  < wsJ [|s|~~ [D D DLT T Tls s sjd d dL  # # # # # # # # 	  	M M M^n n n`    9=/1M   0 0 0 0 0 0 0 0*   F F FP	 	 	BK!"""       6d d dL' ' 'T     ' ' ' zsx*+++++	 s   E$ $E.-E.