3
eåU^¬<  ã            y   @   s�  d dl mZmZm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
d dlZyd dlZW n ek
r€   dZY nX dådd„Zejjejd  dk dd�dd	„ ƒZejjd
ddgƒdd„ ƒZdd„ Zdd„ Zejjedkdd�dd„ ƒZdd„ dæD ƒZdDdEdFgZdGd„ dçD ƒZd¸d¹„ Zdºd»d¼d½d¾d¿dÀdÁdÂdÃg
ZdÄdÅ„ Z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àgZdádâ„ Z dãdä„ Z!dS )èé    )ÚdivisionÚabsolute_importÚprint_functionNc             C   sd   |dkr| j }i }xLt| ƒD ]@}t| |ƒ}t|dƒrt|dƒr|j|kr|jd |j  ||< qW |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   ú</tmp/pip-build-fou5mlat/numpy/numpy/tests/test_public_api.pyÚ	check_dir   s    

r   é   z6NumPy exposes slightly different functions on Python 2)Úreasonc              C   sl   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 | f|Ž}ttƒ}||ksht‚d S )Nz,numpy.testing._private.nosetester.NoseTesterz.numpy.core._multiarray_umath._add_newdoc_ufuncz*numpy.core._multiarray_umath.add_docstringz#numpy.core.function_base.add_newdocznumpy.lib.utils.byte_boundsz/numpy.core._multiarray_umath.compare_chararraysznumpy.lib.utils.deprecateznumpy.lib.utils.<lambda>znumpy.lib.function_base.dispz2numpy.core._multiarray_umath._fastCopyAndTransposez#numpy.lib.shape_base.get_array_wrapznumpy.lib.utils.get_includez)numpy.core._multiarray_umath.int_asbufferznumpy.lib.npyio.mafromtxtznumpy.lib.npyio.ndfromtxtznumpy.lib.npyio.recfromcsvznumpy.lib.npyio.recfromtxtznumpy.lib.utils.safe_evalz)numpy.core.arrayprint.set_string_functionznumpy.__config__.showznumpy.lib.utils.who)ÚTesterZ_add_newdoc_ufuncZadd_docstringZ
add_newdocZadd_newdoc_ufuncZbyte_boundsZcompare_chararraysZ	deprecateZdeprecate_with_docZdispZfastCopyAndTransposeZget_array_wrapZget_includeZint_asbufferZ	mafromtxtZ	ndfromtxtZ
recfromcsvZ
recfromtxtZ	safe_evalZset_string_functionZshow_configZwhozbuiltins.boolzbuiltins.complexzbuiltins.floatzbuiltins.intzbuiltins.objectzbuiltins.str)ÚboolÚcomplexÚfloatÚintÚlongÚobjectÚstrÚunicode)Údictr   ÚnpÚAssertionError)ZundocumentedÚbuiltinsZ	whitelistÚbad_resultsr   r   r   Útest_numpy_namespace!   sB    r#   r   Útestingr   c             C   s8   t jdd|  f}tj|ƒ}| s$t‚| ttƒks4t‚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)ÚsysÚ
executableÚ
subprocessÚcheck_outputr    r   r   )r   ZexeÚresultr   r   r   Útest_import_lazy_importQ   s    

r*   c              C   s   t tjƒ} | i kst‚d S )N)r   r   Úlinalgr    )r"   r   r   r   Útest_numpy_linalgg   s    
r,   c              C   s   t tjƒ} | i kst‚d S )N)r   r   Úfftr    )r"   r   r   r   Útest_numpy_fftl   s    
r.   z#ctypes not available in this pythonc              C   s0   t jtjjjƒ} t| dd ƒ}|d ks,tdƒ‚d S )NZtest_not_exportedzG'test_not_exported' is mistakenly exported, NPY_NO_EXPORT does not work)ÚctypesÚCDLLr   ÚcoreZ_multiarray_testsÚ__file__r	   r    )ÚcdllÚfr   r   r   Útest_NPY_NO_EXPORTq   s    r5   c             C   s   g | ]}d | ‘qS )znumpy.r   )Ú.0Úsr   r   r   ú
<listcomp>‡   s    r8   Ú	ctypeslibÚ	distutilsúdistutils.cpuinfoúdistutils.exec_commandúdistutils.misc_utilúdistutils.logúdistutils.system_infoÚdocú
doc.basicsúdoc.broadcastingúdoc.byteswappingúdoc.constantsúdoc.creationúdoc.dispatchúdoc.glossaryúdoc.indexingúdoc.internalsúdoc.miscúdoc.structured_arraysúdoc.subclassingú
doc.ufuncsÚdualÚf2pyr-   Úlibú
lib.formatú
lib.mixinsúlib.recfunctionsúlib.scimathr+   Úmaú	ma.extrasúma.mrecordsÚmatlibÚ
polynomialúpolynomial.chebyshevúpolynomial.hermiteúpolynomial.hermite_eúpolynomial.laguerreúpolynomial.legendreúpolynomial.polynomialúpolynomial.polyutilsÚrandomÚversionz
numpy.charznumpy.emathz	numpy.recc             C   s   g | ]}d | ‘qS )znumpy.r   )r6   r7   r   r   r   r8   ¿   s    Úcompatúcompat.py3kÚconftestr1   úcore.arrayprintúcore.defchararrayúcore.einsumfuncúcore.fromnumericúcore.function_baseúcore.getlimitsúcore.macharúcore.memmapúcore.multiarrayúcore.numericúcore.numerictypesúcore.overridesúcore.recordsúcore.shape_baseú
core.umathúcore.umath_testsúdistutils.ccompilerúdistutils.commandúdistutils.command.autodistúdistutils.command.bdist_rpmúdistutils.command.buildúdistutils.command.build_clibúdistutils.command.build_extúdistutils.command.build_pyúdistutils.command.build_scriptsúdistutils.command.build_srcúdistutils.command.configú!distutils.command.config_compilerúdistutils.command.developúdistutils.command.egg_infoúdistutils.command.installúdistutils.command.install_clibúdistutils.command.install_dataú!distutils.command.install_headersúdistutils.command.sdistúdistutils.compatúdistutils.conv_templateúdistutils.coreúdistutils.extensionúdistutils.fcompilerúdistutils.fcompiler.absoftúdistutils.fcompiler.compaqúdistutils.fcompiler.environmentúdistutils.fcompiler.g95údistutils.fcompiler.gnuúdistutils.fcompiler.hpuxúdistutils.fcompiler.ibmúdistutils.fcompiler.intelúdistutils.fcompiler.laheyúdistutils.fcompiler.mipsúdistutils.fcompiler.nagúdistutils.fcompiler.noneúdistutils.fcompiler.pathf95údistutils.fcompiler.pgúdistutils.fcompiler.sunúdistutils.fcompiler.vastúdistutils.from_templateúdistutils.intelccompilerúdistutils.lib2defúdistutils.line_endingsúdistutils.mingw32ccompilerúdistutils.msvccompilerúdistutils.npy_pkg_configúdistutils.numpy_distributionúdistutils.pathccompilerúdistutils.unixccompilerúf2py.auxfuncsúf2py.capi_mapsúf2py.cb_rulesúf2py.cfuncsúf2py.common_rulesúf2py.crackfortranúf2py.diagnoseúf2py.f2py2eúf2py.f2py_testingúf2py.f90mod_rulesúf2py.func2subrú
f2py.rulesúf2py.use_rulesú
fft.helperúlib.arraypadúlib.arraysetopsúlib.arrayteratorúlib.financialúlib.function_baseúlib.histogramsúlib.index_tricksúlib.nanfunctionsú	lib.npyioúlib.polynomialúlib.shape_baseúlib.stride_tricksúlib.twodim_baseúlib.type_checkúlib.ufunclikeúlib.user_arrayú	lib.utilsúlinalg.lapack_liteúlinalg.linalgúma.benchúma.coreúma.testutilsúma.timer_comparisonÚ	matrixlibúmatrixlib.defmatrixúrandom.mtrandútesting.print_coercion_tablesútesting.utilsc             C   sD   d| ksd| ksd| krdS | t kr(dS | tkr4dS | tk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_unexpected3  s    rÕ   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   s\   g } x@t jtjtjd dd�D ]$\}}}t|ƒr|tkr| j|ƒ qW | rXtdj	| ƒƒ‚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_packagesr   Ú__path__r   rÕ   Ú	SKIP_LISTÚappendr    Úformat)ÚmodnamesÚ_ÚmodnameÚispkgr   r   r   Útest_all_modules_are_expectedT  s    
rã   z
numpy.mathznumpy.distutils.log.sysz numpy.distutils.system_info.copyz%numpy.distutils.system_info.distutilsznumpy.distutils.system_info.logznumpy.distutils.system_info.osz$numpy.distutils.system_info.platformznumpy.distutils.system_info.rez"numpy.distutils.system_info.shutilz&numpy.distutils.system_info.subprocessznumpy.distutils.system_info.sysz$numpy.distutils.system_info.tempfilez$numpy.distutils.system_info.textwrapz$numpy.distutils.system_info.warningsz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   sB   dd„ } | dƒ}xt D ]}|j| |ƒƒ qW |r>tdj|ƒƒ‚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   s|   g }t j| ƒ}t|dƒr |j}nt|ƒ}xN|D ]F}|jdƒs.| d | }tt||ƒtj	ƒr.t
|ƒr.|tkr.|j|ƒ q.W |S )NÚ__all__rà   r   )Ú	importlibÚimport_moduler
   rä   r   Ú
startswithÚ
isinstancer	   ÚtypesÚ
ModuleTyperÕ   ÚSKIP_LIST_2rÝ   )Úmod_nameÚmembersr   ZobjnamesZobjnameZ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)rÒ   Úextendr    rÞ   )rî   Zunexpected_membersrá   r   r   r   Útest_all_modules_are_expected_2‰  s    
rñ   c              C   sô   dd„ } g }xt D ]}| |ƒs|j|ƒ qW |r>tdj|ƒƒ‚x8tD ]0}yt|ƒ W qD tk
rr   |j|ƒ Y qDX qDW |rŠtdj|ƒƒ‚tjdd��B}tj	dt
d� tj	dtd� xtD ]}| |ƒsº|j|ƒ qºW W d	Q R X |rðtd
j|ƒƒ‚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,   yt j| ƒ W n ttfk
r&   dS X dS )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: {})rÒ   rÝ   r    rÞ   rÓ   Úevalró   ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningÚImportWarningrÔ   )rô   Zmodule_namesr   Úwr   r   r   Útest_api_importable½  s2    


rÿ   )N)-r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   r-   rP   rQ   rR   rS   rT   r+   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   r$   rb   )prc   rd   re   r1   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   r–   r—   r˜   r™   rš   r›   rœ   r�   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¨   r©   rª   r«   r¬   r­   r®   r¯   r°   r±   r²   r³   r´   rµ   r¶   r·   r¸   r¹   rº   r»   r¼   r½   r¾   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   rÇ   rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rÐ   rÑ   )"Ú
__future__r   r   r   r%   r'   rÙ   ré   rå   rù   rï   r   Zpytestr/   rò   r   ÚmarkZskipifÚversion_infor#   Zparametrizer*   r,   r.   r5   rÒ   rÓ   rÔ   rÕ   rÜ   rã   rë   rñ   rÿ   r   r   r   r   Ú<module>   sÂ  

.                                                                                                                                                           4