
    daf*                        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mZmZmZ ej"                  d        Z G d dej&                  ej(                  ej*                  ej,                  ej.                  ej0                  ej2                  ej4                  
      Z G d d	ej8                  ej4                        Z G d
 dej<                  ej4                        Z G d dej4                        Z y)    N   )fixtures)DistributionPackageNotFoundErrordistributionentry_pointsfilesmetadatarequiresversionc               #      K   t        j                  d      5 } t        j                  dt               |  d d d        y # 1 sw Y   y xY ww)NT)recorddefault)category)warningscatch_warningssimplefilterDeprecationWarning)ctxs    @/root/Python-3.12.4/Lib/test/test_importlib/test_metadata_api.pysuppress_known_deprecationr      s@     		 	 	- i2DE	  s   A A	AAA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e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 )!APITestsz\d+\.\d+(\.\d)?c                     t        d      }t        |t              sJ t        j                  | j
                  |      sJ y )Negginfo-pkgr   
isinstancestrrematchversion_patternselfpkg_versions     r   test_retrieves_version_of_selfz'APITests.test_retrieves_version_of_self(   s6    m,+s+++xx,,k:::    c                     t        d      }t        |t              sJ t        j                  | j
                  |      sJ y Ndistinfo-pkgr   r"   s     r   &test_retrieves_version_of_distinfo_pkgz/APITests.test_retrieves_version_of_distinfo_pkg-   s6    n-+s+++xx,,k:::r&   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ndoes-not-exist)assertRaisesr   r   r#   s    r   test_for_name_does_not_existz%APITests.test_for_name_does_not_exist2   s/    34 	+)*	+ 	+ 	+s   +4c                     d}|D ]:  }| j                  |      5  t        |      j                  d   dk(  sJ 	 d d d        < y # 1 sw Y   GxY wN)pkg.dotpkg_dotzpkg-dotzpkg..dotzPkg.DotNamer2   subTestr   r
   r#   namesnames      r   test_name_normalizationz APITests.test_name_normalization6   a    F 	HDd# H#D)226:iGGGH H	HH H   AA	c                     d}|D ]E  }| j                  |      5  | j                  t              5  t        |       d d d        d d d        G y # 1 sw Y   xY w# 1 sw Y   ^xY w)N)ppkgzpkg.)r6   r-   r   r   )r#   prefixesprefixs      r   test_prefix_not_matchedz APITests.test_prefix_not_matched<   sh    % 	)Ff% )&&';< ) ()) )	)) )) )s!   AAAAAA#	c                     ddg}|D ]W  \  }}| j                  |      5  | j                  t        |      j                  d      j	                         |       d d d        Y y # 1 sw Y   dxY w)N)r   mod)egg_with_no_modules-pkg top_level.txt)r6   assertEqualr   	read_textstrip)r#   testspkg_nameexpect_contents       r   test_for_top_levelzAPITests.test_for_top_levelC   sx    "+
 ). 	$Hnh'    *44_EKKM" 	 s   9A""A+	c                    ddg}|D ]k  \  }}| j                  |      5  t        |      D cg c]  }|j                  dk(  s| c}d   }| j                  |j	                         |       d d d        m y c c}w # 1 sw Y   }xY w)N)r   zmod
)rE   
rG   r   )r6   r	   r9   rH   rI   )r#   rK   rL   rM   path	top_levels         r   test_read_textzAPITests.test_read_textO   s    $-
 ). 	H$Hnh' H%*8_!		_8TD	   !4!4!6G	H H	HH Hs"   A;A6A6&A;6A;;B	c                     t               }d|j                  v sJ |j                  d      }d|j                  v sJ |d   }| j	                  |j
                  d       | j	                  |j                  g        y )Nentriesgroupmainzmod:main)r   groupsselectr8   rH   valueextras)r#   epsrU   eps       r   test_entry_pointszAPITests.test_entry_points[   sn    nCJJ&&&**9*-&&&V_:.B'r&   c                     t        d      }dD ]S  }||   }| j                  |j                  j                  d       | j	                  |j                  j
                  d       U y )NrU   rV   )rX   ns:sub)r)   r   1.0.0)r   assertIndistr9   rH   r   )r#   rU   entryr^   s       r   test_entry_points_distributionz'APITests.test_entry_points_distributiond   sS    Y/' 	7EBMM"'',,(GHRWW__g6	7r&   c                 L   | j                   j                  t        j                               }| j                   j                  | j                  |             ddddi}t        j                  ||       t        d      }t        d |D              rJ d|j                  vsJ y	)
z
        Entry points should only be exposed for the first package
        on sys.path with a given name (even when normalized).
        zDistInfo_pkg-1.1.0.dist-infozS
                Name: distinfo-pkg
                Version: 1.1.0
                zJ
                [entries]
                main = mod:altmain
            )METADATAzentry_points.txtrU   rV   c              3      K   | ]8  }|j                   j                  d k(  xr |j                   j                  dk(   : yw)r)   rb   N)rd   r9   r   ).0r^   s     r   	<genexpr>zHAPITests.test_entry_points_unique_packages_normalized.<locals>.<genexpr>   s:      
 GGLLN*Irww'/II
s   >A ra   N)r   enter_contexttempdiradd_sys_pathbuild_filesr   anyr8   )r#   alt_site_diralt_pkgrU   s       r   ,test_entry_points_unique_packages_normalizedz5APITests.test_entry_points_unique_packages_normalizedk   s    
 }}2283C3C3EF##D$5$5l$CD*%	-
 	Wl3Y/ 

 
 	
 

 w}},,,r&   c                 v    | j                  t              5  t        d      d    d d d        y # 1 sw Y   y xY w)NrU   rV   missing)r-   KeyErrorr   r.   s    r   test_entry_points_missing_namez'APITests.test_entry_points_missing_name   s2    x( 	5y))4	5 	5 	5s   /8c                 &    t        d      dk(  sJ y )Nru   rV    )r   r.   s    r   test_entry_points_missing_groupz(APITests.test_entry_points_missing_group   s    ),222r&   c                     t               j                  dd      }| j                  t              5  d|_        d d d        y # 1 sw Y   y xY w)NrU   rX   )rW   r9      )r   rZ   r-   AttributeErrorfoo)r#   r^   s     r   &test_entry_points_allows_no_attributesz/APITests.test_entry_points_allows_no_attributes   sC    ^"""@~. 	BF	 	 	s   AAc                     t        d      }|d   dk(  sJ |d   dk(  sJ |d   dk(  sJ |j                  d      }d|v sJ y )	Nr   authorz	Steven MaLICENSEUnknownr4   
Classifierz*Topic :: Software Development :: Libraries)r
   get_all)r#   mdclassifierss      r   test_metadata_for_this_packagez'APITests.test_metadata_for_this_package   s^    m$(|{***)}	)))&z]***jj.;{JJJr&   c                 h    t        d      }t               5  |d   J 	 ddd       y# 1 sw Y   yxY w)zL
        Requesting a missing key will still return None, but warn.
        r)   r,   N)r
   r   r#   r   s     r   test_missing_key_legacyz APITests.test_missing_key_legacy   s;     n%') 	0&'///	0 	0 	0s   (1c                 F    t        d      }|j                  d      dk(  sJ y)z-
        Getting a key gets the key.
        r   r4   Nr
   getr   s     r   test_get_keyzAPITests.test_get_key   s$     m$vvf~...r&   c                 @    t        d      }|j                  d      J y)z<
        Requesting a missing key will return None.
        r)   r,   Nr   r   s     r   test_get_missing_keyzAPITests.test_get_missing_key   s$     n%vv&'///r&   c                    | d   j                   }| D ]  }|j                   |k(  sJ |j                  r|j                  j                  sJ |j                  r|j                  j                  dk(  sJ |j                  r|j                  dk\  sJ |j                         j                         sJ t        |j                         t              sJ |j                  j                  d      s|j                           y )Nr   sha256z.py)roothashr[   modesizelocateexistsr   read_binarybytesr9   endswithrI   )r	   r   files      r   _test_fileszAPITests._test_files   s    Qx}} 	!D99$$$yyDIIOO33yyDIINNh$>>>yyDIIN22;;='')))d..0%888yy!!%( 	!r&   c                     t        d      D cg c]  }|j                  dk(  s| c}d   }| j                  t        |j                        d       y c c}w )Nr)   zmod.pyr   z!<FileHash mode: sha256 value: .*>)r	   r9   assertRegexreprr   )r#   r>   utils      r   test_file_hash_reprzAPITests.test_file_hash_repr   sF     0GaAFFh4FGJdii*MN Hs
   AAc                 8    | j                  t        d             y r(   r   r	   r.   s    r   test_files_dist_infozAPITests.test_files_dist_info   s    ~./r&   c                     | j                  t        d             | j                  t        d             | j                  t        d             | j                  t        d             y )Nr   zegg_with_module-pkgrE   zsources_fallback-pkgr   r.   s    r   test_files_egg_infozAPITests.test_files_egg_info   sQ    }-.45689:567r&   c                 :    | j                  t        d      d       y )Negginfo-filez0.1)rH   r   r.   s    r   test_version_egg_info_filez#APITests.test_version_egg_info_file   s    0%8r&   c                 <    t        d      }| j                  |       y )Nr   )r   assertIsNone)r#   requirementss     r   test_requires_egg_info_filez$APITests.test_requires_egg_info_file   s    /,'r&   c                 b    t        d      }t        |      dk(  sJ t        d |D              sJ y )Nr      c              3   &   K   | ]	  }|d k(    yw)z%wheel >= 1.0; python_version >= "2.7"Nry   )rj   deps     r   rk   z2APITests.test_requires_egg_info.<locals>.<genexpr>   s     Rc3AARs   )r   lenrp   r#   depss     r   test_requires_egg_infozAPITests.test_requires_egg_info   s0    &4yA~~RTRRRRr&   c                     t        j                  ddi| j                  j                  d             t	        d      }|g k(  sJ y )Nzrequires.txtrF   zegginfo_pkg.egg-infor   )r   ro   site_dirjoinpathr   r   s     r   test_requires_egg_info_emptyz%APITests.test_requires_egg_info_empty   sG     MM""#9:		
 &rzzr&   c                 l    t        d      }t        |      dk(  sJ t        |      sJ d|v sJ d|v sJ y )Nr)   r   zwheel >= 1.0zpytest; extra == 'test')r   r   allr   s     r   test_requires_dist_infoz APITests.test_requires_dist_info   sD    '4yA~~4yy%%%(D000r&   c                     t        j                  d      }t        t        j                  |            }g d}||k(  sJ y )Na  
            dep1
            dep2

            [:python_version < "3"]
            dep3

            [extra1]
            dep4
            dep6@ git+https://example.com/python/dep.git@v1.0.0

            [extra2:python_version < "3"]
            dep5
            )dep1dep2zdep3; python_version < "3"zdep4; extra == "extra1"z2dep5; (python_version < "3") and extra == "extra2"zGdep6@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1")textwrapdedentsortedr   _deps_from_requires_text)r#   r   r   expecteds       r   $test_more_complex_deps_requires_textz-APITests.test_more_complex_deps_requires_text   sC    ??
  l;;HEF
 xr&   c                     t        d      j                  }d|v sJ |d   ddgk(  sJ |d   }|j                  d      sJ t        |d         d	k(  sJ y )
Nr)   r9   keywordssamplepackagedescriptionOnce upon a time
There wasrequires_distr   r
   json
startswithr   r#   r   descs      r   test_as_jsonzAPITests.test_as_json  sj    n%**||*~(I!6666- <===2o&'1,,,r&   c                     t        d      j                  }d|v sJ |d   ddgk(  sJ |d   }|j                  d      sJ t        |d         d	k(  sJ y )
Nr   r9   r   r   r   r   r   
classifierr   r   r   s      r   test_as_json_egg_infozAPITests.test_as_json_egg_info  sj    m$))||*~(I!6666- <===2l#$)))r&   c                     | j                          t        d      j                  }d|v sJ t        |d         dk(  sJ |d   ddgk(  sJ y )Nr)   r9   r   r   r   SAMPLEPACKAGE)make_uppercaser
   r   r   r   s     r   test_as_json_odd_casezAPITests.test_as_json_odd_case  sY    n%**||2o&'1,,,*~(I!6666r&   N)#__name__
__module____qualname__r!   r%   r*   r/   r:   rB   rN   rS   r_   rf   rs   rw   rz   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   ry   r&   r   r   r      s     )O;
;
+H)

H(7-853
K0/0 
! 
!O089(S
1 @-*7r&   r   c                       e Zd Zd Zd Zy)
LegacyDotsc                     d}|D ]:  }| j                  |      5  t        |      j                  d   dk(  sJ 	 d d d        < y # 1 sw Y   GxY wr1   r5   r7   s      r   r:   z"LegacyDots.test_name_normalization!  r;   r<   c                     d}|D ]:  }| j                  |      5  t        |      j                  d   dk(  sJ 	 d d d        < y # 1 sw Y   GxY w)N)pkg.lotpkg_lotzpkg-lotzpkg..lotzPkg.Lotr4   r   r5   r7   s      r   ,test_name_normalization_versionless_egg_infoz7LegacyDots.test_name_normalization_versionless_egg_info'  r;   r<   N)r   r   r   r:   r   ry   r&   r   r   r      s    HHr&   r   c                       e Zd Zd Zd Zd Zy)OffSysPathTestsc                     t        j                  t        | j                        g      }t	        d |D              sJ y )N)rQ   c              3   @   K   | ]  }|j                   d    dk(    yw)r4   r)   N)r
   )rj   rd   s     r   rk   zIOffSysPathTests.test_find_distributions_specified_path.<locals>.<genexpr>1  s     Mt4==(N:Ms   )r   discoverr   r   rp   )r#   distss     r   &test_find_distributions_specified_pathz6OffSysPathTests.test_find_distributions_specified_path/  s2    %%C,>+?@MuMMMMr&   c                 n    | j                   dz  }t        j                  |      }|j                  dk(  sJ y)z9Demonstrate how to load metadata direct from a directory.distinfo_pkg-1.0.0.dist-inforb   N)r   r   atr   r#   dist_info_pathrd   s      r   test_distribution_at_pathlibz,OffSysPathTests.test_distribution_at_pathlib3  s1    )GG~.||w&&&r&   c                     | j                   dz  }t        j                  t        |            }|j                  dk(  sJ y )Nr   rb   )r   r   r   r   r   r   s      r   test_distribution_at_strz(OffSysPathTests.test_distribution_at_str9  s6    )GGs>23||w&&&r&   N)r   r   r   r   r   r   ry   r&   r   r   r   .  s    N''r&   r   c                       e Zd Zd Zy)InvalidateCachec                 ,    t        j                          y )N)	importlibinvalidate_cachesr.   s    r   test_invalidate_cachez%InvalidateCache.test_invalidate_cache@  s    ##%r&   N)r   r   r   r   ry   r&   r   r   r   ?  s    &r&   r   )!r   r   unittestr   r   
contextlibrF   r   importlib.metadatar   r   r   r   r	   r
   r   r   contextmanagerr   
EggInfoPkg EggInfoPkgPipInstalledNoToplevelEggInfoPkgPipInstalledNoModulesEggInfoPkgSourcesFallbackDistInfoPkgDistInfoPkgWithDotEggInfoFileTestCaser   DistInfoPkgWithDotLegacyr   DistInfoPkgOffPathr   r   ry   r&   r   <module>r     s    	      	 	 	  A7--,,&&A7HH22H4E4E H'h1183D3D '"&h'' &r&   