a :jgQY@sddlZddlZddlZddlZddlZddlZddlZddlZddlZ ddlZddl m Z ddl Z z ddl Z WneydZ Yn0d9ddZddZe jje dde jd d gd d Zd dZddZddZe jje duddddZdddDZejdkr"edddD7ZgdZdddDZejdkrVeddd D7Zd!d"Zejdkrrd#gZngZe jd$d%d&Z gd'Z!ejdkre!gd(7Z!d)d*Z"d+d,Z#e jj$e%d-d.vd/dd0d1Z&d2d3Z'e jd4d5d6Z(d7d8Z)dS):N)IS_WASMcCsj|dur|j}i}t|D]J}|dkr(qt||}t|drt|dr|j|kr|jd|j||<q|S)zEReturns a mapping of all objects with the wrong __module__ attribute.Ncore __module____name__.)rdirgetattrhasattrr)module module_nameresultsnameitemrE/usr/local/lib/python3.9/site-packages/numpy/tests/test_public_api.py check_dirs  rcCs"ddd}tt}||ksJdS)Nznumpy.rec.recarrayznumpy.__config__.show)ZrecarrayZ show_config)rnp)Z allowlist bad_resultsrrrtest_numpy_namespace%s rzcan't start subprocess)reasonr testingcCs6tjdd|f}t|}|r"J|ttvs2JdS)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)sys executable subprocess check_outputrr)r exeresultrrrtest_import_lazy_import1s rcCs$tttttttks JdS)zWAssert that output of dir has only one "testing/tester" attribute without duplicateN)lenrrsetrrrrtest_dir_testingHsr cCsttj}|iksJdSN)rrlinalgrrrrtest_numpy_linalgNs r$cCsttj}|iksJdSr!)rrfftr#rrrtest_numpy_fftSs r&z#ctypes not available in this pythoncCs0ttjjj}t|dd}|dus,JddS)NZtest_not_exportedzG'test_not_exported' is mistakenly exported, NPY_NO_EXPORT does not work)ctypesCDLLr_coreZ_multiarray_tests__file__r)Zcdllfrrrtest_NPY_NO_EXPORTXs r,cCsg|] }d|qSnumpy.r.0srrr nr2) Z ctypeslibZdtypes exceptionsf2pyr%libzlib.array_utilsz lib.formatzlib.introspectz lib.mixinsz lib.npyiozlib.recfunctionsz lib.scimathzlib.stride_tricksr"maz ma.extrasz ma.mrecordsZ polynomialzpolynomial.chebyshevzpolynomial.hermitezpolynomial.hermite_ezpolynomial.laguerrezpolynomial.legendrezpolynomial.polynomialrandomstringsrztesting.overridestypingztyping.mypy_pluginversion) cCsg|] }d|qSr-rr/rrrr2s) distutilszdistutils.cpuinfozdistutils.exec_commandzdistutils.misc_utilz distutils.logzdistutils.system_info) numpy.charz numpy.emathz numpy.reccCsg|] }d|qSr-rr/rrrr2r3),compatz compat.py3kZconftestrzcore.multiarrayz core.numericz core.umathzcore.arrayprintzcore.defchararrayzcore.einsumfunczcore.fromnumericzcore.function_basezcore.getlimitszcore.numerictypeszcore.overridesz core.recordszcore.shape_basez f2py.auxfuncszf2py.capi_mapsz f2py.cb_rulesz f2py.cfuncszf2py.common_ruleszf2py.crackfortranz f2py.diagnosez f2py.f2py2ezf2py.f90mod_ruleszf2py.func2subrz f2py.rulesz f2py.symboliczf2py.use_rulesz fft.helperzlib.user_arrayzlinalg.lapack_litez linalg.linalgzma.corez ma.testutilszma.timer_comparisonZmatlibZ matrixlibzmatrixlib.defmatrixzpolynomial.polyutilsz random.mtrandzrandom.bit_generatorztesting.print_coercion_tablescCsg|] }d|qSr-rr/rrrr2s)7zdistutils.armccompilerzdistutils.fujitsuccompilerzdistutils.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.armzdistutils.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.unixccompilercCsDd|vsd|vsd|vrdS|tvr(dS|tvr4dS|tvr@dSdS)z%Check if this needs to be considered.z._z.testsz.setupFT)PUBLIC_MODULESPUBLIC_ALIASED_MODULESPRIVATE_BUT_PRESENT_MODULESr rrr is_unexpectedsrEznumpy.distutils.msvc9compilerz'ignore:.*np.compat.*:DeprecationWarningcCsXg}tjtjtjdddD]$\}}}t|r|tvr||q|rTtd|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_packagesr__path__rrE SKIP_LISTappendAssertionError)modnames_modnameispkgrrrtest_all_modules_are_expected)s rS) znumpy.lib.mathznumpy.matlib.charznumpy.matlib.recznumpy.matlib.emathznumpy.matlib.exceptionsznumpy.matlib.mathznumpy.matlib.linalgznumpy.matlib.fftznumpy.matlib.randomznumpy.matlib.ctypeslibznumpy.matlib.ma)znumpy.distutils.log.sysznumpy.distutils.log.loggingznumpy.distutils.log.warningscCs>dd}|d}tD]}|||q|r:td|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]F}|ds,|d|}tt||tj r,t |r,|t vr,| |q,|S)N__all__rPr) importlib import_moduler rTr startswith isinstancertypes ModuleTyperE SKIP_LIST_2rM)mod_namemembersr ZobjnamesZobjnameZ fullobjnamerrrfind_unexpected_membersns     z@test_all_modules_are_expected_2..find_unexpected_membersnumpyz5Found unexpected object(s) that look like modules: {}N)rAextendrNformat)r^Zunexpected_membersrQrrrtest_all_modules_are_expected_2Usrbc Csdd}g}tD]}||s||q|r:td|tD].}z t|Wq>tyj||Yq>0q>|rtd|tjddH}tj dt dtj dt dt D]}||s||qWd n1s0Y|rtd |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|Wnttfy&YdS0dS)NFT)rUrV ImportErrorAttributeError)r rrrcheck_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: {}) rArMrNrarBevalrdwarningscatch_warningsfilterwarningsDeprecationWarning ImportWarningrC)reZ module_namesr wrrrtest_api_importables8   *rpPy_DEBUG)Nr0zNumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, which does not expose the `array_api` entry point. See https://github.com/numpy/numpy/pull/19800cCstdtjv}tj}z|jdd}WntyH| dg}Yn0t |dkrl|rhd}t |ddSzt dd|D}Wn&t y|rd }t |dYdS0|jd krdS|}d |jd }|tusJ|dS) zx Entry point for Array API implementation can be found with importlib and returns the main numpy namespace. platlibZ array_api)grouprz%No entry points for 'array_api' foundNcss|]}|jdkr|VqdS)r_NrD)r0eprrr r3z-test_array_api_entry_point..z%'numpy' not in array_api entry pointsznumpy.array_apiznumpy entry point value 'z0' does not point to our Array API implementation) sysconfigget_pathrr*rUmetadata entry_pointsselectrdgetrrNnext StopIterationvalueloadr_)Znumpy_in_sitepackagesepsZxp_epsmsgruZxprrrtest_array_api_entry_points0        rcCsVdd}dd}|tj}||}|t}||}||ksRJd||dS)z Checks if `dir(np)` and `np.__all__` are consistent and return the same content, excluding exceptions and private members. cSsdd|DS)NcSsh|]}|ds|qS)rP)rW)r0mrrr r3zYtest_main_namespace_all_dir_coherence.._remove_private_members..rZ member_setrrr_remove_private_membersszFtest_main_namespace_all_dir_coherence.._remove_private_memberscSs |dhS)Nbool) differencerrrr_remove_exceptionsszAtest_main_namespace_all_dir_coherence.._remove_exceptionszMembers that break symmetry: N)rrT__dir__symmetric_difference)rrZ all_membersZ dir_membersrrr%test_main_namespace_all_dir_coherences   rz:ignore:numpy.core(\.\w+)? is deprecated:DeprecationWarningcCsddlm}ttjD]}|ds|dvsd|tvr| jd kr>qf| jd krLqf| |j| j| |fqf||| j| |<qfqH~~~ t | dksJ| dS)z Check that each public function is available from one location only. Test performs BFS search traversing NumPy's public API. It flags any function-like object that is accessible from more that one place. r)AnyCallableDictListSetTuple)_ArrayFunctionDispatcherr_rPz numpy._core)r5r7rr)absoluteZarccosZarccoshZarcsinZarcsinhZarctanZarctan2ZarctanhZ left_shiftZ right_shift conjugateinvert remainderdivideZ concatenatepowerZ transposeZtrimcoefznumpy.polynomial)addequal not_equalZgreaterZ greater_equallessZ less_equalz numpy.stringsr?N)r:rrrrrrZnumpy._core._multiarray_umathrrrdictrpoprrrrrrWrMr isfunctionrXZufunc)rrrrrrZdispatched_functionZvisited_modulesZvisited_functionsZfunctions_original_pathsZduplicated_functionsZ modules_queuer rrrrrtest_functions_single_location:st            r)N)*rrwrrIrYrUrrjr_rZ numpy.testingrZpytestr'rcrrmarkZskipifZ parametrizerr r$r&r,rA version_inforBrCrErLrlrSr[rbrpZxfailget_config_varrrrrrrrrsx         "  . =     40  1 ,