
    daf8                         d dl Zd dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z	 e
e	      Z G d d      Z G d d      Z G d	 d
ej                        Zedk(  r ej"                          yy)    N)
gc_collect)import_helper)assert_python_okc                       e Zd Zy)
FullLoaderN__name__
__module____qualname__     4/root/Python-3.12.4/Lib/test/test_module/__init__.pyr   r          r   r   c                       e Zd Zy)
BareLoaderNr   r   r   r   r   r      r   r   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)y())ModuleTestsc                    t         j                  t               }| j                  t        |j                  t
                     | j                  t        |      g        	 |j                  }| j                  dt        |      z         | j                  |j                  t         j                  xs d       y # t        $ r Y :w xY w)Nz__name__ = %s )
ModuleType__new__
assertTrue
isinstance__dict__dictassertEqualdirr	   failreprAttributeError__doc__)selffooss      r   test_uninitializedzModuleTests.test_uninitialized   s       ,
3<<67S2&	AIIoQ/0 	j&8&8&>B?  		s   )B7 7	CCc                 p    t         j                  t               }| j                  t        dt        |d       y )Nz"module has no attribute 'not_here'not_here)r   r   assertRaisesRegexr    getattrr"   r#   s     r   "test_uninitialized_missing_getattrz.ModuleTests.test_uninitialized_missing_getattr#   s/       , Dj	*r   c                 T    t        d      }| j                  t        dt        |d       y )Nr#   z(module 'foo' has no attribute 'not_here'r'   )r   r(   r    r)   r*   s     r   test_missing_getattrz ModuleTests.test_missing_getattr+   s)      Jj	*r   c           	      v   t        d      }| j                  |j                  d       | j                  |j                  d        | j	                  |j
                  d        | j	                  |j                  d        | j	                  |j                  d        | j                  |j                  dd d d d d       y )Nr#   r	   r!   
__loader____package____spec__)	r   r   r	   r!   assertIsr0   r1   r2   r   r*   s     r   test_no_docstringzModuleTests.test_no_docstring3   s    u-d+cnnd+coot,cllD)Ed6:448(: 	;r   c           	          t        dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  ddd d d d       y )Nr#   foodocr/   r   r   r	   r!   r   r*   s     r   test_ascii_docstringz ModuleTests.test_ascii_docstring?   s\    )u-h/&+(,T&*,	-r   c           	          t        dd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  ddd d d d       y )Nr#   	   foodocሴr/   r7   r*   s     r   test_unicode_docstringz"ModuleTests.test_unicode_docstringI   s\    /u-n5&+(,T&*,	-r   c           
         t        dd      }d|_        |j                  }|j                  dd       | j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  dddd d d d       | j                  |j                  |u        y )Nr#   r:   *   r6   )r	   r!   barr0   r1   r2   )r   r>   r   __init__r   r	   r!   r   )r"   r#   ds      r   test_reinitzModuleTests.test_reinitS   s    /LLUH%u-h/"% Xb!$DJ	K 	)*r   c                 f    d }t                | j                   |       j                  d   d       y )Nc                  *    t        d      } d| _        | S )Nr#      )r   r>   )r#   s    r   fz+ModuleTests.test_dont_clear_dict.<locals>.fc   s    U#CCGJr   r>   rD   )r   r   r   )r"   rE   s     r   test_dont_clear_dictz ModuleTests.test_dont_clear_dicta   s)    	 	e,a0r   c                     g }t        d      }||_        d}t        ||j                         ~t	                | j                  |dg       y )Nr#   zwclass A:
    def __init__(self, l):
        self.l = l
    def __del__(self):
        self.l.append(1)
a = A(destroyed)   )r   	destroyedexecr   r   r   )r"   rI   mr$   s       r   test_clear_dict_in_ref_cyclez(ModuleTests.test_clear_dict_in_ref_cyclej   sI    	u 	Q

QC(r   c                     t        d      }t        j                  |      }| j                   |       |       ~t	                | j                   |       d        y Nr#   )r   weakrefrefr3   r   )r"   rK   wrs      r   test_weakrefzModuleTests.test_weakrefy   sA    u[[^bdAbdD!r   c                 ~   dd l mc m} ddl m} | j	                  |d       | j	                  |j
                  d       | j	                  |j                  d       | j                  t        d      5  |j                   d d d        | j	                  |j                  d       t        j                  d= y # 1 sw Y   7xY w)	Nr   )testzThere is testrH      z Deprecated, use whatever insteadzThere is whatevertest.test_module.good_getattr)test.test_module.good_getattrtest_modulegood_getattrrT   r   xyr(   r    yolowhateversysmodules)r"   ggarT   s      r   test_module_getattrzModuleTests.test_module_getattr   s    336/""##N$FH 	HH	 	':;KK78		 	s   0B33B<c                    dd l mc m} ddlm} | j                  |j                  d       | j                  |j                  d       | j                  t              5  |j                   d d d        | j                  t              5  |j                   d d d        t        j                  d= dt        j                  v rt        j                  d= y y # 1 sw Y   ixY w# 1 sw Y   KxY w)Nr   bad_getattr2rH   test.test_module.bad_getattrtest.test_module.bad_getattr2)test.test_module.bad_getattrrX   bad_getattrtest.test_modulerd   r   rZ   assertRaises	TypeErrornoper^   r_   r"   bgard   s      r   test_module_getattr_errorsz&ModuleTests.test_module_getattr_errors   s    221"+y) 	HH	y) 		KK67*ckk9;< :	 		 	s   CCCC'c                 r    dd l mc m} | j                  t	        |      g d       t
        j                  d= y )Nr   )abcrV   )rW   rX   rY   r   r   r^   r_   )r"   r`   s     r   test_module_dirzModuleTests.test_module_dir   s)    33S?3KK78r   c                 `   dd l mc m} ddlm} | j                  t              5  t        |       d d d        | j                  t              5  t        |       d d d        t        j                  d= dt        j                  v rt        j                  d= y y # 1 sw Y   hxY w# 1 sw Y   KxY w)Nr   rc   re   rf   )
rg   rX   rh   ri   rd   rj   rk   r   r^   r_   rm   s      r   test_module_dir_errorsz"ModuleTests.test_module_dir_errors   s    221y) 	H	y) 		KK67*ckk9;< :	 		 	s   BB$B!$B-c                 0   ddl m} | j                  t              5  |j                   d d d        | j                  t              5  |j
                   d d d        dt        j                  v rt        j                  d= y y # 1 sw Y   XxY w# 1 sw Y   :xY w)Nr   )bad_getattr3ztest.test_module.bad_getattr3)ri   rx   rj   r    one
delgetattrr^   r_   )r"   rx   s     r   test_module_getattr_trickyz&ModuleTests.test_module_getattr_tricky   s{    1~. 		~. 	$##	$*ckk9;< :		 		$ 	$s   B B B	Bc                 T    t        d      }|`| j                  t        |      d       y )Nr#   z<module '?'>)r   r	   r   r   r"   rK   s     r   test_module_repr_minimalz$ModuleTests.test_module_repr_minimal   s%    uJa.1r   c                 P    t        d      }| j                  t        |      d       y Nr#   z<module 'foo'>)r   r   r   r}   s     r   test_module_repr_with_namez&ModuleTests.test_module_repr_with_name   s!    ua"23r   c                 ^    t        d      }d|_        | j                  t        |      d       y Nr#   /tmp/foo.pyz!<module 'foo' from '/tmp/foo.py'>)r   __file__r   r   r}   s     r   'test_module_repr_with_name_and_filenamez3ModuleTests.test_module_repr_with_name_and_filename   s(    u"
a"EFr   c                 b    t        d      }|`d|_        | j                  t	        |      d       y )Nr#   r   z<module '?' from '/tmp/foo.py'>)r   r	   r   r   r   r}   s     r   #test_module_repr_with_filename_onlyz/ModuleTests.test_module_repr_with_filename_only   s-    uJ"
a"CDr   c                 l    t        d      }|j                  J | j                  t        |      d       y r   )r   r0   r   r   r}   s     r   $test_module_repr_with_loader_as_Nonez0ModuleTests.test_module_repr_with_loader_as_None   s1    u||###a"23r   c                     t        d      }|`t        |_        t	        t              }| j                  t	        |      dj                  |             y Nr#   z<module '?' ({})>)r   r	   r   r0   r   r   formatr"   rK   loader_reprs      r   -test_module_repr_with_bare_loader_but_no_namez9ModuleTests.test_module_repr_with_bare_loader_but_no_name   sE    uJ!:&G(//<	>r   c                     t        d      }|`t        |_        t	        t              }| j                  t	        |      dj                  |             y r   )r   r	   r   r0   r   r   r   r   s      r   -test_module_repr_with_full_loader_but_no_namez9ModuleTests.test_module_repr_with_full_loader_but_no_name   sG     uJ!:&G(//<	>r   c                     t        d      }t        |_        t        t              }| j	                  t        |      dj                  |             y )Nr#   z<module 'foo' ({})>)r   r   r0   r   r   r   )r"   rK   module_reprs      r   !test_module_repr_with_bare_loaderz-ModuleTests.test_module_repr_with_bare_loader   sA    u!:&G*11+>	@r   c                 v    t        d      }t        |_        | j                  t	        |      dt
         d       y )Nr#   z<module 'foo' (<class 'z.FullLoader'>)>)r   r   r0   r   r   r	   r}   s     r   !test_module_repr_with_full_loaderz-ModuleTests.test_module_repr_with_full_loader   s5    u!G.xjH	Jr   c                 t    t        d      }t        |_        d|_        | j	                  t        |      d       y r   )r   r   r0   r   r   r   r}   s     r   .test_module_repr_with_bare_loader_and_filenamez:ModuleTests.test_module_repr_with_bare_loader_and_filename   /    u!"
a"EFr   c                 t    t        d      }t        |_        d|_        | j	                  t        |      d       y r   )r   r   r0   r   r   r   r}   s     r   .test_module_repr_with_full_loader_and_filenamez:ModuleTests.test_module_repr_with_full_loader_and_filename   r   r   c                 B    | j                  t        t              d       y )Nz<module 'sys' (built-in)>)r   r   r^   )r"   s    r   test_module_repr_builtinz$ModuleTests.test_module_repr_builtin   s    c$?@r   c                     t        t              }d}d}| j                  |d t        |       |dj	                  ||             | j                  |t        |       d  |dj	                  ||             y )Nz<module 'unittest' from 'z__init__.py'>z{!r} does not start with {!r}z{!r} does not end with {!r})r   unittestr   lenr   )r"   rstarts_with	ends_withs       r   test_module_repr_sourcez#ModuleTests.test_module_repr_source  sv    N1#	,C,-{8??;O	QC	N?+,i6==aK	Mr   c                     t        d      }t        j                  j                  ddgd      }t        j                  j	                  d|      }||_        ||_        | j                  t        |      d       y )Nr#   r>   bazz'<module 'foo' (namespace) from ['bar']>)	r   	importlib	machineryNamespaceLoader
ModuleSpecr0   r2   r   r   )r"   rK   loaderspecs       r   'test_module_repr_with_namespace_packagez3ModuleTests.test_module_repr_with_namespace_package  sc    u$$44UUGUK""--eV<
a"KLr   c                     t        d      }t               }t        j                  j	                  d|      }||_        ||_        d}| j                  t        |      |       | j                  dt        |             y )Nr#   0<module 'foo' \(<.*\.BareLoader object at .+>\)>from)
r   r   r   r   r   r0   r2   assertRegexr   assertNotInr"   rK   r   r   expected_repr_patterns        r   9test_module_repr_with_namespace_package_and_custom_loaderzEModuleTests.test_module_repr_with_namespace_package_and_custom_loader  sh    u""--eV<
 Sa"78a)r   c                 
   t        d      }t               }dg|_        t        j                  j                  d|      }||_        ||_        d}| j                  t        |      |       | j                  dt        |             y )Nr#   spamr   r   )r   r   _pathr   r   r   r0   r2   r   r   r   r   s        r   ,test_module_repr_with_fake_namespace_packagez8ModuleTests.test_module_repr_with_fake_namespace_package  sq    ux""--eV<
 Sa"78a)r   c                     t        dd      \  }}}| j                  |       |j                         }| j                  t	        |      h d       y )Nz-cz$from test.test_module import final_a>      x = a   x = b	   len = len   final_a.x = a   final_b.x = b   shutil.rmtree = rmtree)r   assertFalse
splitlinesr   set)r"   rcouterrliness        r   $test_module_finalization_at_shutdownz0ModuleTests.test_module_finalization_at_shutdown)  sH    '.TUC U &' 	(r   c                      G d d       G fddt               }| j                  t        t         |d      d       y )Nc                       e Zd Zd Zy);ModuleTests.test_descriptor_errors_propagate.<locals>.Descrc                     t         N)RuntimeError)r"   ots      r   __get__zCModuleTests.test_descriptor_errors_propagate.<locals>.Descr.__get__8  s    ""r   N)r	   r
   r   r   r   r   r   Descrr   7  s    #r   r   c                       e Zd Z W         Zy)7ModuleTests.test_descriptor_errors_propagate.<locals>.MN)r	   r
   r   melon)r   s   r   Mr   :  s
    GEr   r   mymodr   )r   rj   r   r)   )r"   r   r   s     @r    test_descriptor_errors_propagatez,ModuleTests.test_descriptor_errors_propagate6  s1    	# 	#	
 	,7WEr   c                 f   t        d      }t        d      D ]  }| j                  d|j                  v        |j                  }| j                  d|j                  v        | j                  |j                  |       | j                  |j                  d   |       |dz  r|`|j                  d=  y )Nr#   rD   __annotations__rU   )r   ranger   r   r   r   r   r"   r#   ir@   s       r   test_lazy_create_annotationsz(ModuleTests.test_lazy_create_annotations>  s     q 		4A.#,,>?##AOO-=>S00!4S\\*;<a@1u'LL!23		4r   c                 l   t        d      }t        d      D ]  }| j                  d|j                  v        dt        i}||_        | j                  d|j                  v        | j                  |j
                  |       | j                  |j                  d   |       |dz  r|`|j                  d=  y )Nr#   rD   r   rq   rU   )r   r   r   r   intr   r   r   r   s       r   test_setting_annotationsz$ModuleTests.test_setting_annotationsN  s    q 
	4A.#,,>?c
A"#COO-=>S00!4S\\*;<a@1u'LL!23
	4r   c                     t        d      }i |_        |`| j                  t              5  |`d d d        y # 1 sw Y   y xY wrN   )r   r   rj   r    r*   s     r   test_annotations_getset_raisesz*ModuleTests.test_annotations_getset_raises\  sC     ~. 	$#	$ 	$ 	$s   6?c                     t        j                  d      }| j                  d|j                  v        |`| j                  d|j                  v        y )Nztest.typinganndata.ann_module4r   )r   import_fresh_moduler   r   r   r   )r"   ann_module4s     r   &test_annotations_are_created_correctlyz2ModuleTests.test_annotations_are_created_correctlyd  sO    #77,
 	)[-A-AAB'*k.B.BBCr   c                     t        d      }|j                  }d}t        d      D ])  }d|_        ||j                  z  }|j	                  d       + | j                  |d       y )NrT   r   d   rH   attr)r   r   r   r   popr   )r"   rK   r@   count_s        r   test_repeated_attribute_popsz(ModuleTests.test_repeated_attribute_popsm  s`     vJJs 	AAFQVVOEEE&M	 	$r   c                     G d dt               } |d      }| j                  t              5  |j                   d d d        | j                  t              5  |j                   d d d        d\  |_        |_        | j                  |j                  d       | j                  |j                  d       y # 1 sw Y   {xY w# 1 sw Y   ]xY w)Nc                   "     e Zd ZdZ fdZ xZS )=ModuleTests.test_subclass_with_slots.<locals>.ModuleWithSlots)rq   rr   c                 $    t         |   |       y r   )superr?   )r"   name	__class__s     r   r?   zFModuleTests.test_subclass_with_slots.<locals>.ModuleWithSlots.__init__  s     &r   )r	   r
   r   	__slots__r?   __classcell__)r   s   @r   ModuleWithSlotsr   ~  s    "I' 'r   r   r   )rH   rU   rH   rU   )r   rj   r    rq   rr   r   )r"   r   rK   s      r   test_subclass_with_slotsz$ModuleTests.test_subclass_with_slots{  s    	'j 	' F#~. 	CC	~. 	CC	QSa a 	 		 	s   B4C 4B= C	N)*r	   r
   r   r%   r+   r-   r4   r8   r;   rA   rF   rL   rR   ra   ro   rt   rv   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    @**
;--+1)"
9=9
	==24G
E4
>
>@JGGAMM*	*(F4 4$D
%!r   r   __main__)importlib.machineryr   r   rO   test.supportr   r   test.support.script_helperr   r^   typer   r   r   TestCaser   r	   mainr   r   r   <module>r     sf       # & 7 
#Y
	 		 	v!(## v!t zHMMO r   