o 6a:@s$ddlZddlZddlZddlZddlZddlZddlZddlZddlZzddl Z Wn e y5dZ Ynwd%ddZ ddZ ej dddgd d Zd d Zd dZddZej je duddddZdddDZgdZdddDZddZgdZddZgd Zd!d"Zd#d$ZdS)&NcCs`|dur|j}i}t|D] }t||}t|dr-t|dr-|j|kr-|jd|j||<q |S)zEReturns a mapping of all objects with the wrong __module__ attribute.N __module____name__.)rdirgetattrhasattrr)module module_nameresultsnameitemr =/usr/lib/python3/dist-packages/numpy/tests/test_public_api.py check_dirs   rc Csiddddddddd dd d d d ddddddddddddddddddd d!d"d#d$d%d&}tjd'krUd(d)d*d+d+d,d-d-d.}t|fi|}n|}tt}||ksaJdS)/NTesterz,numpy.testing._private.nosetester.NoseTester_add_newdoc_ufuncz.numpy.core._multiarray_umath._add_newdoc_ufunc add_docstringz*numpy.core._multiarray_umath.add_docstring add_newdocz#numpy.core.function_base.add_newdocadd_newdoc_ufunc byte_boundsznumpy.lib.utils.byte_boundscompare_chararraysz/numpy.core._multiarray_umath.compare_chararrays deprecateznumpy.lib.utils.deprecatedeprecate_with_docz"numpy.lib.utils.deprecate_with_docdispznumpy.lib.function_base.dispfastCopyAndTransposez2numpy.core._multiarray_umath._fastCopyAndTransposeget_array_wrapz#numpy.lib.shape_base.get_array_wrap get_includeznumpy.lib.utils.get_include mafromtxtznumpy.lib.npyio.mafromtxt ndfromtxtznumpy.lib.npyio.ndfromtxt recfromcsvznumpy.lib.npyio.recfromcsv recfromtxtznumpy.lib.npyio.recfromtxtznumpy.lib.utils.safe_evalz)numpy.core.arrayprint.set_string_functionznumpy.__config__.showznumpy.lib.utils.who) safe_evalset_string_function show_configwho)z builtins.boolzbuiltins.complexzbuiltins.floatz builtins.intzbuiltins.objectz builtins.str)boolcomplexfloatintlongobjectstrunicode)sys version_infodictrnp) undocumentedbuiltins allowlist bad_resultsr r rtest_numpy_namespacesl       r7r testingrcCs6tjdd|f}t|}|rJ|ttvsJdS)aMake sure we can actually use the modules we lazy load. While not exported as part of the public API, it was accessible. With the use of __getattr__ and __dir__, this isn't always true It can happen that an infinite recursion may happen. This is the only way I found that would force the failure to appear on the badly implemented code. We also test for the presence of the lazily imported modules in dir z-czimport numpy; numpy.N)r/ executable subprocess check_outputrr2)r exeresultr r rtest_import_lazy_importOs r>cCs$tttttttksJdS)zWAssert that output of dir has only one "testing/tester" attribute without duplicateN)lenrr2setr r r rtest_dir_testinges$rAcCttj}|iks JdSN)rr2linalgr6r r rtest_numpy_linalgk rFcCrBrC)rr2fftrEr r rtest_numpy_fftprGrIz#ctypes not available in this python)reasoncCs0ttjjj}t|dd}|dusJddS)Ntest_not_exportedzG'test_not_exported' is mistakenly exported, NPY_NO_EXPORT does not work)ctypesCDLLr2core_multiarray_tests__file__r)cdllfr r rtest_NPY_NO_EXPORTus rScCg|]}d|qSznumpy.r .0sr r r rY)# ctypeslib distutilszdistutils.cpuinfozdistutils.exec_commandzdistutils.misc_utilz distutils.logzdistutils.system_infodocz doc.constantsz doc.ufuncsf2pyrHlibz lib.formatz lib.mixinszlib.recfunctionsz lib.scimathzlib.stride_tricksrDmaz ma.extrasz ma.mrecordsmatlib polynomialzpolynomial.chebyshevzpolynomial.hermitezpolynomial.hermite_ezpolynomial.laguerrezpolynomial.legendrezpolynomial.polynomialrandomr8typingztyping.mypy_pluginversion)z numpy.charz numpy.emathz numpy.reccCrTrUr rVr r rrYrZ)scompatz compat.py3kconftestrNzcore.arrayprintzcore.defchararrayzcore.einsumfunczcore.fromnumericzcore.function_basezcore.getlimitsz core.macharz core.memmapzcore.multiarrayz core.numericzcore.numerictypeszcore.overridesz core.recordszcore.shape_basez core.umathzcore.umath_testszdistutils.ccompilerzdistutils.ccompiler_optzdistutils.commandzdistutils.command.autodistzdistutils.command.bdist_rpmzdistutils.command.buildzdistutils.command.build_clibzdistutils.command.build_extzdistutils.command.build_pyzdistutils.command.build_scriptszdistutils.command.build_srczdistutils.command.configz!distutils.command.config_compilerzdistutils.command.developzdistutils.command.egg_infozdistutils.command.installzdistutils.command.install_clibzdistutils.command.install_dataz!distutils.command.install_headerszdistutils.command.sdistzdistutils.conv_templatezdistutils.corezdistutils.extensionzdistutils.fcompilerzdistutils.fcompiler.absoftzdistutils.fcompiler.compaqzdistutils.fcompiler.environmentzdistutils.fcompiler.g95zdistutils.fcompiler.gnuzdistutils.fcompiler.hpuxzdistutils.fcompiler.ibmzdistutils.fcompiler.intelzdistutils.fcompiler.laheyzdistutils.fcompiler.mipszdistutils.fcompiler.nagzdistutils.fcompiler.nonezdistutils.fcompiler.pathf95zdistutils.fcompiler.pgzdistutils.fcompiler.nvzdistutils.fcompiler.sunzdistutils.fcompiler.vastzdistutils.fcompiler.fujitsuzdistutils.from_templatezdistutils.intelccompilerzdistutils.lib2defzdistutils.line_endingszdistutils.mingw32ccompilerzdistutils.msvccompilerzdistutils.npy_pkg_configzdistutils.numpy_distributionzdistutils.pathccompilerzdistutils.unixccompilerdualz f2py.auxfuncszf2py.capi_mapsz f2py.cb_rulesz f2py.cfuncszf2py.common_ruleszf2py.crackfortranz f2py.diagnosez f2py.f2py2ezf2py.f2py_testingzf2py.f90mod_ruleszf2py.func2subrz f2py.ruleszf2py.use_rulesz fft.helperz lib.arraypadzlib.arraysetopszlib.arrayteratorzlib.function_basezlib.histogramszlib.index_trickszlib.nanfunctionsz lib.npyiozlib.polynomialzlib.shape_basezlib.twodim_basezlib.type_checkz lib.ufunclikezlib.user_arrayz lib.utilszlinalg.lapack_litez linalg.linalgzma.benchzma.corez ma.testutilszma.timer_comparison matrixlibzmatrixlib.defmatrixzpolynomial.polyutilsz random.mtrandzrandom.bit_generatorztesting.print_coercion_tablesz testing.utilscCsDd|vs d|vs d|vrdS|tvrdS|tvrdS|tvr dSdS)z%Check if this needs to be considered.z._z.testsz.setupFT)PUBLIC_MODULESPUBLIC_ALIASED_MODULESPRIVATE_BUT_PRESENT_MODULES)r r r r is_unexpected0srm) znumpy.core.code_generatorsz!numpy.core.code_generators.genapiz)numpy.core.code_generators.generate_umathz+numpy.core.code_generators.ufunc_docstringsz-numpy.core.code_generators.generate_numpy_apiz-numpy.core.code_generators.generate_ufunc_apiz$numpy.core.code_generators.numpy_apiznumpy.core.cversionsznumpy.core.generate_numpy_apiznumpy.distutils.msvc9compilercCsXg}tjtjtjdddD]\}}}t|r |tvr ||q|r*td|dS)z| Test that we don't add anything that looks like a new public module by accident. Check is based on filenames. rN)pathprefixonerrorzFound unexpected modules: ) pkgutil walk_packagesr2__path__rrm SKIP_LISTappendAssertionError)modnames_modnameispkgr r rtest_all_modules_are_expectedQs r{)z numpy.mathznumpy.distutils.log.sysznumpy.doc.constants.reznumpy.doc.constants.textwrapznumpy.lib.emathznumpy.lib.mathznumpy.matlib.charznumpy.matlib.recznumpy.matlib.emathznumpy.matlib.mathznumpy.matlib.linalgznumpy.matlib.fftznumpy.matlib.randomznumpy.matlib.ctypeslibznumpy.matlib.macCs>dd}|d}tD] }|||q |rtd|dS)a Method checking all objects. The pkgutil-based method in `test_all_modules_are_expected` does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like: import .lib.scimath as emath To check if something in a module is (effectively) public, one can check if there's anything in that namespace that's a public function/object but is not exposed in a higher-level namespace. For example for a `numpy.lib` submodule:: mod = np.lib.mixins for obj in mod.__all__: if obj in np.__all__: continue elif obj in np.lib.__all__: continue else: print(obj) cSsxg}t|}t|dr|j}nt|}|D]#}|ds9|d|}tt||tj r9t |r9|t vr9| |q|S)N__all__rxr) importlib import_modulerr|r startswith isinstancertypes ModuleTyperm SKIP_LIST_2ru)mod_namemembersrobjnamesobjname fullobjnamer r rfind_unexpected_memberss     z@test_all_modules_are_expected_2..find_unexpected_membersnumpyz5Found unexpected object(s) that look like modules: {}N)rjextendrvformat)runexpected_membersryr r rtest_all_modules_are_expected_2zsrc Csdd}g}tD] }||s||q|rtd|tD]}zt|Wqty5||Yqw|r?td|tjdd$}tj dt dtj dt dt D] }||sa||qVWd n1slwY|rztd |d S) a  Check that all submodules listed higher up in this file can be imported Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may simply need to be removed from the list (deprecation may or may not be needed - apply common sense). c Ss*zt|WdSttfyYdSw)NFT)r}r~ ImportErrorAttributeError)r r r rcheck_importables  z-test_api_importable..check_importablez5Modules in the public API that cannot be imported: {}z1Modules in the public API that were not found: {}T)recordalways)categoryNzPModules that are not really public but looked public and can not be imported: {}) rjrurvrrkevalrwarningscatch_warningsfilterwarningsDeprecationWarning ImportWarningrl)r module_namesr wr r rtest_api_importablesD    rrC)r/r:rqrr}rrr2pytestrLrrr7mark parametrizer>rArFrIskipifrSrjrkrlrmrtr{rrrr r r rsD    0   'w 4