Skip to content

BUG: more numpy.distutils.log.* in test_all_modules_are_expected_2 #22827

@bnavigator

Description

@bnavigator

Describe the issue:

While packaging numpy for openSUSE Tumbleweed, this test fails with finding additional modules

Reproduce the code example:

import numpy as np
np.test(extra_argv=['-k', 'test_all_modules_are_expected_2'])

Error message:

NumPy version 1.24.0
NumPy relaxed strides checking option: True
NumPy CPU features:  SSE SSE2 SSE3 SSSE3* SSE41* POPCNT* SSE42* AVX* F16C* FMA3* AVX2* AVX512F? AVX512CD? AVX512_SKX? AVX512_CLX? AVX512_CNL? AVX512_ICL?
F                                                                                                                                                    [100%]
========================================================================= FAILURES =========================================================================
_____________________________________________________________ test_all_modules_are_expected_2 ______________________________________________________________

    def test_all_modules_are_expected_2():
        """
        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)
    
        """
    
        def find_unexpected_members(mod_name):
            members = []
            module = importlib.import_module(mod_name)
            if hasattr(module, '__all__'):
                objnames = module.__all__
            else:
                objnames = dir(module)
    
            for objname in objnames:
                if not objname.startswith('_'):
                    fullobjname = mod_name + '.' + objname
                    if isinstance(getattr(module, objname), types.ModuleType):
                        if is_unexpected(fullobjname):
                            if fullobjname not in SKIP_LIST_2:
                                members.append(fullobjname)
    
            return members
    
        unexpected_members = find_unexpected_members("numpy")
        for modname in PUBLIC_MODULES:
            unexpected_members.extend(find_unexpected_members(modname))
    
        if unexpected_members:
>           raise AssertionError("Found unexpected object(s) that look like "
                                 "modules: {}".format(unexpected_members))
E           AssertionError: Found unexpected object(s) that look like modules: ['numpy.distutils.log.logging', 'numpy.distutils.log.warnings']

find_unexpected_members = <function test_all_modules_are_expected_2.<locals>.find_unexpected_members at 0x7ffb9acda200>
modname    = 'numpy.version'
unexpected_members = ['numpy.distutils.log.logging', 'numpy.distutils.log.warnings']

../../../BUILDROOT/python-numpy-1.24.0-0.x86_64/usr/lib64/python3.10/site-packages/numpy/tests/test_public_api.py:418: AssertionError
================================================================= short test summary info ==================================================================
FAILED tests/test_public_api.py::test_all_modules_are_expected_2 - AssertionError: Found unexpected object(s) that look like modules: ['numpy.distutils.l...
1 failed, 22652 deselected in 3.01s
False

NumPy/Python version information:

1.24.0 3.10.9 (main, Dec 08 2022, 14:49:06) [GCC]

Context for the issue:

Index: numpy-1.24.0/numpy/tests/test_public_api.py
===================================================================
--- numpy-1.24.0.orig/numpy/tests/test_public_api.py
+++ numpy-1.24.0/numpy/tests/test_public_api.py
@@ -351,6 +351,8 @@ def test_all_modules_are_expected():
 SKIP_LIST_2 = [
     'numpy.math',
     'numpy.distutils.log.sys',
+    'numpy.distutils.log.logging',
+    'numpy.distutils.log.warnings,
     'numpy.doc.constants.re',
     'numpy.doc.constants.textwrap',
     'numpy.lib.emath',

should fix the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions