a ze0@sddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z e Z e ej ejgZdgddgdgdgZdgddgdgd gZdgd d dggd gZdgd d dggdgZdgdggdgZdgdggdgZdddgdggdgZdddgggdgZddgggdgZdgddggdgZdgddggdgZdddgggd gZdddgggd!gZd"d"dgggd#d$d%gZd&d'Z d(d)Z!Gd*d+d+ej"Z#e$d,kre%dS)-N)supporta.module)arsysbcz b.somethingza/__init__.py a/module.py from b import something from c import something b/__init__.py from sys import * )rrrr __future__aa/__init__.py a/module.py from b import something from c import something b/__init__.py from __future__ import absolute_import from sys import * )ra.bza.crZmymodulerZblahblahamymodule.py a/__init__.py import blahblah from a import b import c a/module.py import sys from a import b as x from a.c import sillyname a/b.py a/c.py from a.module import x import mymodule as sillyname from sys import version_info ) rrrzb.xzb.yzb.zrrgczajmymodule.py a/__init__.py a/module.py from __future__ import absolute_import import sys # sys import blahblah # fails import gc # gc import b.x # b.x from b import y # b.y from b.z import * # b.z.* a/gc.py a/sys.py import mymodule a/b/__init__.py a/b/x.py a/b/y.py a/b/z.py b/__init__.py import z b/unused.py b/x.py b/y.py b/z.py ) rrrr a.b.ya.b.za.b.c a.b.c.moduleCa.b.c.da.b.c.ea.b.xr amymodule.py a/__init__.py from .b import y, z # a.b.y, a.b.z a/module.py from __future__ import absolute_import # __future__ import gc # gc a/gc.py a/sys.py a/b/__init__.py from ..b import x # a.b.x #from a.b.c import moduleC from .c import moduleC # a.b.moduleC a/b/x.py a/b/y.py a/b/z.py a/b/g.py a/b/c/__init__.py from ..c import e # a.b.c.e a/b/c/moduleC.py from ..c import d # a.b.c.d a/b/c/d.py a/b/c/e.py a/b/c/x.py ) rrza.sysr r r rrrrza.b.c.frz a.anotheramymodule.py a/__init__.py from . import sys # a.sys a/another.py a/module.py from .b import y, z # a.b.y, a.b.z a/gc.py a/sys.py a/b/__init__.py from .c import moduleC # a.b.c.moduleC from .c import d # a.b.c.d a/b/x.py a/b/y.py a/b/z.py a/b/c/__init__.py from . import e # a.b.c.e a/b/c/moduleC.py # from . import f # a.b.c.f from .. import x # a.b.x from ... import another # a.another a/b/c/d.py a/b/c/e.py a/b/c/f.py rza.barza/__init__.py def foo(): pass a/module.py from . import foo from . import bar zza/__init__.py def foo(): pass a/module.py from . import * )rrrzb.moduleza/__init__.py a/module.py import b.module b/__init__.py b/module.py ? # SyntaxError: invalid syntax )rrrzb.cza/__init__.py a/module.py import c from b import c b/__init__.py b/c.py Za_utf8Zb_utf8ua_utf8.py # use the default of utf8 print('Unicode test A code point 2090 ₐ that is not valid in cp1252') import b_utf8 b_utf8.py # use the default of utf8 print('Unicode test B code point 2090 ₐ that is not valid in cp1252') uza_utf8.py # coding=utf8 print('Unicode test A code point 2090 ₐ that is not valid in cp1252') import b_utf8 b_utf8.py # use the default of utf8 print('Unicode test B code point 2090 ₐ that is not valid in cp1252') Za_cp1252sa_cp1252.py # coding=cp1252 # 0xe2 is not allowed in utf8 print('CP1252 test Pt') import b_utf8 ub_utf8.py # use the default of utf8 print('Unicode test A code point 2090 ₐ that is not valid in cp1252') utf-8c CsXtj|}zt|Wn2tyL}z|jtjkr8WYd}~n d}~00t|dS)Nwb)ospathdirnamemakedirsOSErrorerrnoEEXISTopen)rrerJ/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_modulefinder.py open_file%s  r!cCsd}z|D]z}t|tkr(|d}|ds<|drP||dq|r\|t|tkrr|d}t t j t |}qW|r|n|r|0dS)Nr   ) splitlinestypebytesencode startswithwritestripclosedecoder!rrjoinTEST_DIR)sourceZofilinerrr create_package/s       r2c@seZdZddgejfddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S)(ModuleFinderTestFrc Cs|\}}}} } t| zx|t||d} | ||r<| tt|}t| j} || || \} }|| |||| Wt t n t t 0dS)N)rdebug replace_paths) r2 TEST_PATHZ import_hookreportsortedsetmodulesZ assertEqualZany_missing_maybeshutilrmtreer/)selfinfor7r4r5modulefinder_classZ import_thisr:missingZ maybe_missingr0ZmffoundZbadmayberrr _do_testBs       zModuleFinderTest._do_testcCs|tdSN)rC package_testr=rrr test_package`szModuleFinderTest.test_packagecCs|tdSrD)rC maybe_testrFrrr test_maybecszModuleFinderTest.test_maybecCs|tdSrD)rCmaybe_test_newrFrrr test_maybe_newfszModuleFinderTest.test_maybe_newcCs|tdSrD)rCabsolute_import_testrFrrr test_absolute_importsisz&ModuleFinderTest.test_absolute_importscCs|tdSrD)rCrelative_import_testrFrrr test_relative_importslsz&ModuleFinderTest.test_relative_importscCs|tdSrD)rCrelative_import_test_2rFrrr test_relative_imports_2osz(ModuleFinderTest.test_relative_imports_2cCs|tdSrD)rCrelative_import_test_3rFrrr test_relative_imports_3rsz(ModuleFinderTest.test_relative_imports_3cCs|tdSrD)rCrelative_import_test_4rFrrr test_relative_imports_4usz(ModuleFinderTest.test_relative_imports_4cCs|tdSrD)rCsyntax_error_testrFrrr test_syntax_errorxsz"ModuleFinderTest.test_syntax_errorcCs|tdSrD)rCsame_name_as_bad_testrFrrr test_same_name_as_bad{sz&ModuleFinderTest.test_same_name_as_badcCstjtd}|tjjd}|tjjd}t| }| d dWdn1s\0Yt j ||dt ||tdS)Nrrztesting_modulefinder = True r)cfile)rrr.r/ importlib machinerySOURCE_SUFFIXESBYTECODE_SUFFIXESr!r*r( py_compilecompileremoverC bytecode_test)r= base_path source_path bytecode_pathfilerrr test_bytecode~s . zModuleFinderTest.test_bytecodecCstjtdd}tjtdd}t&}|jtd||fgdWdn1sT0Y|}d||f}| ||dS)Nrz module.pyzspam.py)r4r5zco_filename %r changed to %r) rrr.r/rZcaptured_stdoutrCrHgetvalueZassertIn)r=Zold_pathnew_pathoutputZexpectedrrr test_replace_pathss $ z#ModuleFinderTest.test_replace_pathscCs,dddgggdttdg}||dS)NrrzVa.py %r import b b.py i)listrangerC)r=Zextended_opargs_testrrr test_extended_opargss  z%ModuleFinderTest.test_extended_opargscCs|tdSrD)rCcoding_default_utf8_testrFrrr test_coding_default_utf8sz)ModuleFinderTest.test_coding_default_utf8cCs|tdSrD)rCcoding_explicit_utf8_testrFrrr test_coding_explicit_utf8sz*ModuleFinderTest.test_coding_explicit_utf8cCs|tdSrD)rCcoding_explicit_cp1252_testrFrrr test_coding_explicit_cp1252sz,ModuleFinderTest.test_coding_explicit_cp1252cCs$Gdddtj}|jt|ddS)Ncs(eZdZfddZfddZZS)zAModuleFinderTest.test_load_module_api..CheckLoadModuleApicstj|i|dSrD)super__init__)r=argskwds __class__rr rwszJModuleFinderTest.test_load_module_api..CheckLoadModuleApi.__init__cs|\}}}t||||SrD)rv load_module)r=Zfqnamefppathname file_infosuffixmoder&rzrr r|s zMModuleFinderTest.test_load_module_api..CheckLoadModuleApi.load_module)__name__ __module__ __qualname__rwr| __classcell__rrrzr CheckLoadModuleApis r)r?) modulefinder ModuleFinderrCrL)r=rrrr test_load_module_apis z%ModuleFinderTest.test_load_module_apiN)rrrrrrCrGrIrKrMrOrQrSrUrWrYrgrlrorqrsrurrrrr r3As$   r3__main__)&rrZimportlib.machineryr[r_r;Zunittesttempfiletestrrmkdtempr/rr__file__r6rHrJrErLrNrPrRrTrbrVrXrprrr(rtr!r2ZTestCaser3rmainrrrr s !% (   s