o
    6a:                     @   s$  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Zd dlZd dlZzd dl	Z	W n e
y5   dZ	Y nw d%ddZdd Zejdddgd	d
 Zdd Zdd Zdd Zejje	du dddd Zdd dD Zg dZdd dD Zdd Zg dZdd Zg d Zd!d" Zd#d$ ZdS )&    Nc                 C   s`   |du r| j }i }t| D ] }t| |}t|dr-t|dr-|j|kr-|jd |j  ||< q|S )zEReturns a mapping of all objects with the wrong __module__ attribute.N
__module____name__.)r   dirgetattrhasattrr   )modulemodule_nameresultsnameitem r   =/usr/lib/python3/dist-packages/numpy/tests/test_public_api.py	check_dir   s   
r   c               	   C   s   i ddddddddd	dd
dddddddddddddddddddddd d!d"d#d$d%d&} t jd'k rUd(d)d*d+d+d,d-d-d.}t| fi |}n| }tt}||ksaJ d S )/NTesterz,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_newdocadd_newdoc_ufuncbyte_boundsznumpy.lib.utils.byte_boundscompare_chararraysz/numpy.core._multiarray_umath.compare_chararrays	deprecateznumpy.lib.utils.deprecatedeprecate_with_docz"numpy.lib.utils.deprecate_with_docdispznumpy.lib.function_base.dispfastCopyAndTransposez2numpy.core._multiarray_umath._fastCopyAndTransposeget_array_wrapz#numpy.lib.shape_base.get_array_wrapget_includeznumpy.lib.utils.get_include	mafromtxtznumpy.lib.npyio.mafromtxt	ndfromtxtznumpy.lib.npyio.ndfromtxt
recfromcsvznumpy.lib.npyio.recfromcsv
recfromtxtznumpy.lib.npyio.recfromtxtznumpy.lib.utils.safe_evalz)numpy.core.arrayprint.set_string_functionznumpy.__config__.showznumpy.lib.utils.who)	safe_evalset_string_functionshow_configwho)      zbuiltins.boolzbuiltins.complexzbuiltins.floatzbuiltins.intzbuiltins.objectzbuiltins.str)boolcomplexfloatintlongobjectstrunicode)sysversion_infodictr   np)undocumentedbuiltins	allowlistbad_resultsr   r   r   test_numpy_namespace   sl   	


r7   r   testingr   c                 C   s6   t jdd|  f}t|}|rJ | ttv sJ dS )a  Make 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-czimport numpy; numpy.N)r/   
executable
subprocesscheck_outputr   r2   )r   exeresultr   r   r   test_import_lazy_importO   s   
r>   c                   C   s$   t ttt tttksJ dS )zWAssert that output of dir has only one "testing/tester"
    attribute without duplicateN)lenr   r2   setr   r   r   r   test_dir_testinge   s   $rA   c                  C      t tj} | i ksJ d S N)r   r2   linalgr6   r   r   r   test_numpy_linalgk      
rF   c                  C   rB   rC   )r   r2   fftrE   r   r   r   test_numpy_fftp   rG   rI   z#ctypes not available in this python)reasonc                  C   s0   t tjjj} t| dd }|d u sJ dd S )Ntest_not_exportedzG'test_not_exported' is mistakenly exported, NPY_NO_EXPORT does not work)ctypesCDLLr2   core_multiarray_tests__file__r   )cdllfr   r   r   test_NPY_NO_EXPORTu   s   rS   c                 C      g | ]}d | qS znumpy.r   .0sr   r   r   
<listcomp>       rY   )#	ctypeslib	distutilszdistutils.cpuinfozdistutils.exec_commandzdistutils.misc_utilzdistutils.logzdistutils.system_infodoczdoc.constantsz
doc.ufuncsf2pyrH   libz
lib.formatz
lib.mixinszlib.recfunctionszlib.scimathzlib.stride_tricksrD   maz	ma.extraszma.mrecordsmatlib
polynomialzpolynomial.chebyshevzpolynomial.hermitezpolynomial.hermite_ezpolynomial.laguerrezpolynomial.legendrezpolynomial.polynomialrandomr8   typingztyping.mypy_pluginversion)z
numpy.charznumpy.emathz	numpy.recc                 C   rT   rU   r   rV   r   r   r   rY      rZ   )scompatzcompat.py3kconftestrN   zcore.arrayprintzcore.defchararrayzcore.einsumfunczcore.fromnumericzcore.function_basezcore.getlimitszcore.macharzcore.memmapzcore.multiarrayzcore.numericzcore.numerictypeszcore.overrideszcore.recordszcore.shape_basez
core.umathzcore.umath_testszdistutils.ccompilerzdistutils.ccompiler_optzdistutils.commandzdistutils.command.autodistzdistutils.command.bdist_rpmzdistutils.command.buildzdistutils.command.build_clibzdistutils.command.build_extzdistutils.command.build_pyzdistutils.command.build_scriptszdistutils.command.build_srczdistutils.command.configz!distutils.command.config_compilerzdistutils.command.developzdistutils.command.egg_infozdistutils.command.installzdistutils.command.install_clibzdistutils.command.install_dataz!distutils.command.install_headerszdistutils.command.sdistzdistutils.conv_templatezdistutils.corezdistutils.extensionzdistutils.fcompilerzdistutils.fcompiler.absoftzdistutils.fcompiler.compaqzdistutils.fcompiler.environmentzdistutils.fcompiler.g95zdistutils.fcompiler.gnuzdistutils.fcompiler.hpuxzdistutils.fcompiler.ibmzdistutils.fcompiler.intelzdistutils.fcompiler.laheyzdistutils.fcompiler.mipszdistutils.fcompiler.nagzdistutils.fcompiler.nonezdistutils.fcompiler.pathf95zdistutils.fcompiler.pgzdistutils.fcompiler.nvzdistutils.fcompiler.sunzdistutils.fcompiler.vastzdistutils.fcompiler.fujitsuzdistutils.from_templatezdistutils.intelccompilerzdistutils.lib2defzdistutils.line_endingszdistutils.mingw32ccompilerzdistutils.msvccompilerzdistutils.npy_pkg_configzdistutils.numpy_distributionzdistutils.pathccompilerzdistutils.unixccompilerdualzf2py.auxfuncszf2py.capi_mapszf2py.cb_ruleszf2py.cfuncszf2py.common_ruleszf2py.crackfortranzf2py.diagnosezf2py.f2py2ezf2py.f2py_testingzf2py.f90mod_ruleszf2py.func2subrz
f2py.ruleszf2py.use_rulesz
fft.helperzlib.arraypadzlib.arraysetopszlib.arrayteratorzlib.function_basezlib.histogramszlib.index_trickszlib.nanfunctionsz	lib.npyiozlib.polynomialzlib.shape_basezlib.twodim_basezlib.type_checkzlib.ufunclikezlib.user_arrayz	lib.utilszlinalg.lapack_litezlinalg.linalgzma.benchzma.corezma.testutilszma.timer_comparison	matrixlibzmatrixlib.defmatrixzpolynomial.polyutilszrandom.mtrandzrandom.bit_generatorztesting.print_coercion_tablesztesting.utilsc                 C   sD   d| v sd| v sd| v rdS | t v rdS | tv rdS | tv r dS dS )z%Check if this needs to be considered.z._z.testsz.setupFT)PUBLIC_MODULESPUBLIC_ALIASED_MODULESPRIVATE_BUT_PRESENT_MODULES)r   r   r   r   is_unexpected0  s   rm   )
znumpy.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_apiznumpy.core.cversionsznumpy.core.generate_numpy_apiznumpy.distutils.msvc9compilerc                  C   sX   g } t jtjtjd ddD ]\}}}t|r |tvr | | q| r*td|  dS )z|
    Test that we don't add anything that looks like a new public module by
    accident.  Check is based on filenames.
    r   N)pathprefixonerrorzFound unexpected modules: )	pkgutilwalk_packagesr2   __path__r   rm   	SKIP_LISTappendAssertionError)modnames_modnameispkgr   r   r   test_all_modules_are_expectedQ  s   
r{   )z
numpy.mathznumpy.distutils.log.sysznumpy.doc.constants.reznumpy.doc.constants.textwrapznumpy.lib.emathznumpy.lib.mathznumpy.matlib.charznumpy.matlib.recznumpy.matlib.emathznumpy.matlib.mathznumpy.matlib.linalgznumpy.matlib.fftznumpy.matlib.randomznumpy.matlib.ctypeslibznumpy.matlib.mac                  C   s>   dd } | d}t D ]	}|| | q
|rtd|dS )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)

    c                 S   sx   g }t | }t|dr|j}nt|}|D ]#}|ds9| d | }tt||tj	r9t
|r9|tvr9|| q|S )N__all__rx   r   )	importlibimport_moduler   r|   r   
startswith
isinstancer   types
ModuleTyperm   SKIP_LIST_2ru   )mod_namemembersr   objnamesobjnamefullobjnamer   r   r   find_unexpected_members  s   



z@test_all_modules_are_expected_2.<locals>.find_unexpected_membersnumpyz5Found unexpected object(s) that look like modules: {}N)rj   extendrv   format)r   unexpected_membersry   r   r   r   test_all_modules_are_expected_2z  s   r   c               	   C   s   dd } g }t D ]}| |s|| q|rtd|tD ]}zt| W q ty5   || Y qw |r?td|tjdd$}tj	dt
d tj	dtd tD ]}| |sa|| qVW d	   n1 slw   Y  |rztd
|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              	   S   s*   zt |  W dS  ttfy   Y dS w )NFT)r}   r~   ImportErrorAttributeError)r	   r   r   r   check_importable  s   z-test_api_importable.<locals>.check_importablez5Modules in the public API that cannot be imported: {}z1Modules in the public API that were not found: {}T)recordalways)categoryNzPModules that are not really public but looked public and can not be imported: {})rj   ru   rv   r   rk   evalr   warningscatch_warningsfilterwarningsDeprecationWarningImportWarningrl   )r   module_namesr	   wr   r   r   test_api_importable  sD   

r   rC   )r/   r:   rq   r   r}   r   r   r2   pytestrL   r   r   r7   markparametrizer>   rA   rF   rI   skipifrS   rj   rk   rl   rm   rt   r{   r   r   r   r   r   r   r   <module>   sD    
0

'w4