a  ze@sddlmZddlZddlZddlmZddlZddlZGdddZ ej e ej d\Z Z Gdd d ZGd d d eZej eej d\ZZGd d d eZej eej d\ZZedkredS))utilN) MethodTypec@s(eZdZdZddZddZddZdS) CallingOrderzCalls to the importers on sys.meta_path happen in order that they are specified in the sequence, starting with the first importer [first called], and then continuing on down until one is found that doesn't return None [continuing].c Csd}t|}t|X}tj||gd(||||j|Wdn1sZ0YWdn1sx0YWdn1s0YdS)N top_level meta_path)r mock_spec import_stateassertIs __import__modules)selfmodfirstsecondr^/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/import_/test_meta_path.pytest_first_calledszCallingOrder.test_first_calledc Csd}td}t|d}ddd|_tj||gd(||||j|Wdn1sf0YWdn1s0YWdn1s0YdS)NZfor_realZ nonexistentcSsdSNr)rfullnamepathparentrrrz.CallingOrder.test_continuing..r)NN)rr find_specr r r r )rmod_namerrrrrtest_continuings  zCallingOrder.test_continuingc Csd}z tj|=Wnty"Yn0tjgdtjddT}td|t j dd| t |d|t|djtWdn1s0YWdn1s0YdS)NZnothingrT)recordalways)sysr KeyErrorrr warningscatch_warnings simplefilter assertIsNone importlib _bootstrap _find_spec assertEquallenZ assertTrue issubclasscategory ImportWarning)r module_namewrrr test_empty!s    zCallingOrder.test_emptyN)__name__ __module__ __qualname____doc__rrr2rrrrr s r)r c@s(eZdZdZddZddZddZdS) CallSignaturezIf there is no __path__ entry on the parent module, then 'path' is None [no path]. Otherwise, the value for __path__ is passed in for the 'path' argument [path set].cs&t||jgfdd}|fS)Ncs||g|i|Sr)append)rargskwargsfxnlogrrwrapper?sz)CallSignature.log_finder..wrapper)getattr finder_name)rimporterr>rr;r log_finder<s zCallSignature.log_finderc Csd}d|vsJ||}||\}}t||jt||tj|gdT||t|dkshJ|dd}| |d|| |dWdn1s0YWdn1s0YdS)Nr.rr r) mock_modulesrBsetattrr@rrr r r,r+r')rrrAr= wrapped_callr9rrr test_no_pathDs    zCallSignature.test_no_pathc Cs d}|d}dg}d|vsJ||d|}||j|_||\}}t||jt||tj|gdl| |t |dksJ|dd }|dd}| || |d || |d|Wdn1s0YWdn1s0YdS) NZpkgz.module*rCz .__init__rrr r)rDr __path__rBrEr@rrr r r,Z assertFalser+r ) rZpkg_namerrrAr=rFr9r:rrrtest_with_pathSs       zCallSignature.test_with_pathN)r3r4r5r6rBrGrJrrrrr76sr7c@seZdZejZdZdS)CallSignaturePEP302 find_moduleN)r3r4r5rrDr@rrrrrKhsrKc@seZdZejZdZdS)CallSignaturePEP451rN)r3r4r5rr rDr@rrrrrMrsrM__main__)rZimportlib._bootstrapr(r"typesrZunittestr$rZ test_bothr ZFrozen_CallingOrderZSource_CallingOrderr7rKZFrozen_CallSignaturePEP302ZSource_CallSignaturePEP302rMZFrozen_CallSignaturePEP451ZSource_CallSignaturePEP451r3mainrrrrs(  *2