
    z%i3                         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__     M/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/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&y%)&ModuleTestsc                    t         j                  t               }| j                  t        |j                  t
                     | j                  t        |      g        	 |j                  }| j                  dt        |      z         | j                  |j                  t         j                         y # t        $ r Y 6w 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9  		s   )B3 3	B?>B?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    assertIsr/   r0   r1   r   r)   s     r   test_no_docstringzModuleTests.test_no_docstring2   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.   r6   r)   s     r   test_unicode_docstringz"ModuleTests.test_unicode_docstringH   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"   r9   *   r5   )r	   r    barr/   r0   r1   )r   r=   r   __init__r   r	   r    r   )r!   r"   ds      r   test_reinitzModuleTests.test_reinitR   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>.fb   s    U#CCGJr   r=   rC   )r   r   r   )r!   rD   s     r   test_dont_clear_dictz ModuleTests.test_dont_clear_dict`   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!   rH   mr#   s       r   test_clear_dict_in_ref_cyclez(ModuleTests.test_clear_dict_in_ref_cyclei   sI    	u 	Q

QC(r   c                     t        d      }t        j                  |      }| j                   |       |       ~t	                | j                   |       d        y Nr"   )r   weakrefrefr2   r   )r!   rJ   wrs      r   test_weakrefzModuleTests.test_weakrefx   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 testrG      z Deprecated, use whatever insteadzThere is whatevertest.test_module.good_getattr)test.test_module.good_getattrtest_modulegood_getattrrS   r   xyr'   r   yolowhateversysmodules)r!   ggarS   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_getattr2rG   test.test_module.bad_getattrtest.test_module.bad_getattr2)test.test_module.bad_getattrrW   bad_getattrtest.test_modulerc   r   rY   assertRaises	TypeErrornoper]   r^   r!   bgarc   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crU   )rV   rW   rX   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   rb   rd   re   )
rf   rW   rg   rh   rc   ri   rj   r   r]   r^   rl   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)rh   rw   ri   r   one
delgetattrr]   r^   )r!   rw   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!   rJ   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   r/   r   r   r|   s     r   $test_module_repr_with_loader_as_Nonez0ModuleTests.test_module_repr_with_loader_as_None   s.    u||##a"23r   c                     t        d      }|`t        |_        t	        t              }| j                  t	        |      dj                  |             y Nr"   z<module '?' ({})>)r   r	   r   r/   r   r   formatr!   rJ   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   r/   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   r/   r   r   r   )r!   rJ   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   r/   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   r/   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   r/   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d      \  }}}| j                  |       |j                         }| j                  t	        |      h d       y )Nz-czfrom test 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    '.HI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__  s    ""r   N)r	   r
   r   r   r   r   r   Descrr     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   ri   r   r(   )r!   r   r   s     @r    test_descriptor_errors_propagatez,ModuleTests.test_descriptor_errors_propagate  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"   rC   __annotations__rT   )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"   rC   r   rp   rT   )r   r   r   r   intr   r   r   r   s       r   test_setting_annotationsz$ModuleTests.test_setting_annotations0  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rM   )r   r   ri   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.ann_module4r   )r   import_fresh_moduler   r   r   r   )r!   ann_module4s     r   &test_annotations_are_created_correctlyz2ModuleTests.test_annotations_are_created_correctlyF  sK    #778JK)[-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 )NrS   r   d   rG   attr)r   r   r   r   popr   )r!   rJ   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)rp   rq   c                 $    t         |   |       y r   )superr>   )r!   name	__class__s     r   r>   zFModuleTests.test_subclass_with_slots.<locals>.ModuleWithSlots.__init__a  s     &r   )r	   r
   r   	__slots__r>   __classcell__)r   s   @r   ModuleWithSlotsr   ^  s    "I' 'r   r   r   )rG   rT   rG   rT   )r   ri   r   rp   rq   r   )r!   r   rJ   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,   r3   r7   r:   r@   rE   rK   rQ   r`   rn   rs   ru   rz   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(F4 4$D
%!r   r   __main__)r   rN   test.supportr   r   test.support.script_helperr   r]   typer   r   r   TestCaser   r	   mainr   r   r   <module>r      sc      # & 7 
#Y
	 		 	W!(## W!v
 zHMMO r   