Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test failures on Guix #128

Open
Apteryks opened this issue Feb 25, 2025 · 3 comments
Open

test failures on Guix #128

Apteryks opened this issue Feb 25, 2025 · 3 comments

Comments

@Apteryks
Copy link

Hi,

Testing this package at version 2.2 with my system (Guix), I get:

================================================== FAILURES ==================================================
_______________________________________________ test_operators _______________________________________________

    def test_operators():
        # For every operator, we test that it works for the required type
        # combinations and raises TypeError otherwise
        binary_op_dtypes = {
            "__add__": "numeric",
            "__and__": "integer_or_boolean",
            "__eq__": "all",
            "__floordiv__": "real numeric",
            "__ge__": "real numeric",
            "__gt__": "real numeric",
            "__le__": "real numeric",
            "__lshift__": "integer",
            "__lt__": "real numeric",
            "__mod__": "real numeric",
            "__mul__": "numeric",
            "__ne__": "all",
            "__or__": "integer_or_boolean",
            "__pow__": "numeric",
            "__rshift__": "integer",
            "__sub__": "numeric",
            "__truediv__": "floating",
            "__xor__": "integer_or_boolean",
        }
        # Recompute each time because of in-place ops
        def _array_vals():
            for d in _integer_dtypes:
                yield asarray(1, dtype=d)
            for d in _boolean_dtypes:
                yield asarray(False, dtype=d)
            for d in _floating_dtypes:
                yield asarray(1.0, dtype=d)
    
    
        BIG_INT = int(1e30)
        for op, dtypes in binary_op_dtypes.items():
            ops = [op]
            if op not in ["__eq__", "__ne__", "__le__", "__ge__", "__lt__", "__gt__"]:
                rop = "__r" + op[2:]
                iop = "__i" + op[2:]
                ops += [rop, iop]
            for s in [1, 1.0, 1j, BIG_INT, False]:
                for _op in ops:
                    for a in _array_vals():
                        # Test array op scalar. From the spec, the following combinations
                        # are supported:
    
                        # - Python bool for a bool array dtype,
                        # - a Python int within the bounds of the given dtype for integer array dtypes,
                        # - a Python int or float for real floating-point array dtypes
                        # - a Python int, float, or complex for complex floating-point array dtypes
    
                        if ((dtypes == "all"
                             or dtypes == "numeric" and a.dtype in _numeric_dtypes
                             or dtypes == "real numeric" and a.dtype in _real_numeric_dtypes
                             or dtypes == "integer" and a.dtype in _integer_dtypes
                             or dtypes == "integer_or_boolean" and a.dtype in _integer_or_boolean_dtypes
                             or dtypes == "boolean" and a.dtype in _boolean_dtypes
                             or dtypes == "floating" and a.dtype in _floating_dtypes
                            )
                            # bool is a subtype of int, which is why we avoid
                            # isinstance here.
                            and (a.dtype in _boolean_dtypes and type(s) == bool
                                 or a.dtype in _integer_dtypes and type(s) == int
                                 or a.dtype in _real_floating_dtypes and type(s) in [float, int]
                                 or a.dtype in _complex_floating_dtypes and type(s) in [complex, float, int]
                            )):
                            if a.dtype in _integer_dtypes and s == BIG_INT:
                                assert_raises(OverflowError, lambda: getattr(a, _op)(s))
                            else:
                                # Only test for no error
                                with suppress_warnings() as sup:
                                    # ignore warnings from pow(BIG_INT)
                                    sup.filter(RuntimeWarning,
                                               "invalid value encountered in power")
                                    getattr(a, _op)(s)
                        else:
                            assert_raises(TypeError, lambda: getattr(a, _op)(s))
    
                    # Test array op array.
                    for _op in ops:
                        for x in _array_vals():
                            for y in _array_vals():
                                # See the promotion table in NEP 47 or the array
                                # API spec page on type promotion. Mixed kind
                                # promotion is not defined.
                                if (x.dtype == uint64 and y.dtype in [int8, int16, int32, int64]
                                    or y.dtype == uint64 and x.dtype in [int8, int16, int32, int64]
                                    or x.dtype in _integer_dtypes and y.dtype not in _integer_dtypes
                                    or y.dtype in _integer_dtypes and x.dtype not in _integer_dtypes
                                    or x.dtype in _boolean_dtypes and y.dtype not in _boolean_dtypes
                                    or y.dtype in _boolean_dtypes and x.dtype not in _boolean_dtypes
                                    or x.dtype in _floating_dtypes and y.dtype not in _floating_dtypes
                                    or y.dtype in _floating_dtypes and x.dtype not in _floating_dtypes
                                    ):
                                    assert_raises(TypeError, lambda: getattr(x, _op)(y))
                                # Ensure in-place operators only promote to the same dtype as the left operand.
                                elif (
                                    _op.startswith("__i")
                                    and result_type(x.dtype, y.dtype) != x.dtype
                                ):
                                    assert_raises(TypeError, lambda: getattr(x, _op)(y))
                                # Ensure only those dtypes that are required for every operator are allowed.
                                elif (dtypes == "all" and (x.dtype in _boolean_dtypes and y.dtype in _boolean_dtypes
                                                          or x.dtype in _numeric_dtypes and y.dtype in _numeric_dtypes)
                                    or (dtypes == "real numeric" and x.dtype in _real_numeric_dtypes and y.dtype in _real_numeric_dtypes)
                                    or (dtypes == "numeric" and x.dtype in _numeric_dtypes and y.dtype in _numeric_dtypes)
                                    or dtypes == "integer" and x.dtype in _integer_dtypes and y.dtype in _integer_dtypes
                                    or dtypes == "integer_or_boolean" and (x.dtype in _integer_dtypes and y.dtype in _integer_dtypes
                                                                           or x.dtype in _boolean_dtypes and y.dtype in _boolean_dtypes)
                                    or dtypes == "boolean" and x.dtype in _boolean_dtypes and y.dtype in _boolean_dtypes
                                    or dtypes == "floating" and x.dtype in _floating_dtypes and y.dtype in _floating_dtypes
                                ):
                                    getattr(x, _op)(y)
                                else:
                                    assert_raises(TypeError, lambda: getattr(x, _op)(y))
    
        unary_op_dtypes = {
            "__abs__": "numeric",
            "__invert__": "integer_or_boolean",
            "__neg__": "numeric",
            "__pos__": "numeric",
        }
        for op, dtypes in unary_op_dtypes.items():
            for a in _array_vals():
                if (
                    dtypes == "numeric"
                    and a.dtype in _numeric_dtypes
                    or dtypes == "integer_or_boolean"
                    and a.dtype in _integer_or_boolean_dtypes
                ):
                    # Only test for no error
                    getattr(a, op)()
                else:
                    assert_raises(TypeError, lambda: getattr(a, op)())
    
        # Finally, matmul() must be tested separately, because it works a bit
        # different from the other operations.
        def _matmul_array_vals():
            yield from _array_vals()
            for d in _all_dtypes:
                yield ones((3, 4), dtype=d)
                yield ones((4, 2), dtype=d)
                yield ones((4, 4), dtype=d)
    
        # Scalars always error
        for _op in ["__matmul__", "__rmatmul__", "__imatmul__"]:
            for s in [1, 1.0, False]:
                for a in _matmul_array_vals():
                    if (type(s) in [float, int] and a.dtype in _floating_dtypes
                        or type(s) == int and a.dtype in _integer_dtypes):
                        # Type promotion is valid, but @ is not allowed on 0-D
                        # inputs, so the error is a ValueError
>                       assert_raises(ValueError, lambda: getattr(a, _op)(s))

array_api_strict/tests/test_array_object.py:251: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/gnu/store/50047r6f9chb6dwd01f9hai90y9arwb4-python-3.10.7/lib/python3.10/unittest/case.py:738: in assertRaises
    return context.handle('assertRaises', args, kwargs)
/gnu/store/50047r6f9chb6dwd01f9hai90y9arwb4-python-3.10.7/lib/python3.10/unittest/case.py:201: in handle
    callable_obj(*args, **kwargs)
array_api_strict/tests/test_array_object.py:251: in <lambda>
    assert_raises(ValueError, lambda: getattr(a, _op)(s))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def __imatmul__(self: Array, other: Array, /) -> Array:
        """
        Performs the operation __imatmul__.
        """
        # matmul is not defined for scalars, but without this, we may get
        # the wrong error message from asarray.
        other = self._check_allowed_dtypes(other, "numeric", "__imatmul__")
        if other is NotImplemented:
            return other
        self._check_device(other)
>       res = self._array.__imatmul__(other._array)
E       TypeError: In-place matrix multiplication is not (yet) supported. Use 'a = a @ b' instead of 'a @= b'.

array_api_strict/_array_object.py:1049: TypeError
__________________________________________ test_disabled_extensions __________________________________________

    def test_disabled_extensions():
        # Test that xp.extension errors when an extension is disabled, and that
        # xp.__all__ is updated properly.
    
        # First test that things are correct on the initial import. Since we have
        # already called set_array_api_strict_flags many times throughout running
        # the tests, we have to test this in a subprocess.
        subprocess_tests = [('''\
    import array_api_strict
    
    array_api_strict.linalg # No error
    array_api_strict.fft # No error
    assert "linalg" in array_api_strict.__all__
    assert "fft" in array_api_strict.__all__
    assert len(array_api_strict.__all__) == len(set(array_api_strict.__all__))
    ''', {}),
    # Test that the initial population of __all__ works correctly
    ('''\
    from array_api_strict import * # No error
    linalg # Should have been imported by the previous line
    fft
    ''', {}),
    ('''\
    from array_api_strict import * # No error
    linalg # Should have been imported by the previous line
    assert 'fft' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": "linalg"}),
    ('''\
    from array_api_strict import * # No error
    fft # Should have been imported by the previous line
    assert 'linalg' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": "fft"}),
    ('''\
    from array_api_strict import * # No error
    assert 'linalg' not in globals()
    assert 'fft' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": ""}),
    ]
        for test, env in subprocess_tests:
            try:
>               subprocess.run([sys.executable, '-c', test], check=True,
                               capture_output=True, encoding='utf-8', env=env)

array_api_strict/tests/test_flags.py:374: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input = None, capture_output = True, timeout = None, check = True
popenargs = (['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-python-wrapper-3.10.7/bin/python', '-c', 'import array_api_strict\n\nar...ert "fft" in array_api_strict.__all__\nassert len(array_api_strict.__all__) == len(set(array_api_strict.__all__))\n'],)
kwargs = {'encoding': 'utf-8', 'env': {}, 'stderr': -1, 'stdout': -1}
process = <Popen: returncode: 1 args: ['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-py...>, stdout = ''
stderr = 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\n  File "/tmp/guix-build-python-array-api-...i_strict/_constants.py", line 1, in <module>\n    import numpy as np\nModuleNotFoundError: No module named \'numpy\'\n'
retcode = 1

    def run(*popenargs,
            input=None, capture_output=False, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.
    
        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
    
        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.
    
        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.
    
        There is an optional argument "input", allowing you to
        pass bytes or a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.
    
        By default, all communication is in bytes, and therefore any "input" should
        be bytes, and the stdout and stderr will be bytes. If in text mode, any
        "input" should be a string, and stdout and stderr will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode is
        triggered by setting any of text, encoding, errors or universal_newlines.
    
        The other arguments are the same as for the Popen constructor.
        """
        if input is not None:
            if kwargs.get('stdin') is not None:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE
    
        if capture_output:
            if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                raise ValueError('stdout and stderr arguments may not be used '
                                 'with capture_output.')
            kwargs['stdout'] = PIPE
            kwargs['stderr'] = PIPE
    
        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired as exc:
                process.kill()
                if _mswindows:
                    # Windows accumulates the output in a single blocking
                    # read() call run on child threads, with the timeout
                    # being done in a join() on those threads.  communicate()
                    # _after_ kill() is required to collect that and add it
                    # to the exception.
                    exc.stdout, exc.stderr = process.communicate()
                else:
                    # POSIX _communicate already populated the output so
                    # far into the TimeoutExpired exception.
                    process.wait()
                raise
            except:  # Including KeyboardInterrupt, communicate handled that.
                process.kill()
                # We don't call process.wait() as .__exit__ does that for us.
                raise
            retcode = process.poll()
            if check and retcode:
>               raise CalledProcessError(retcode, process.args,
                                         output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-python-wrapper-3.10.7/bin/python', '-c', 'import array_api_strict\n\narray_api_strict.linalg # No error\narray_api_strict.fft # No error\nassert "linalg" in array_api_strict.__all__\nassert "fft" in array_api_strict.__all__\nassert len(array_api_strict.__all__) == len(set(array_api_strict.__all__))\n']' returned non-zero exit status 1.

/gnu/store/50047r6f9chb6dwd01f9hai90y9arwb4-python-3.10.7/lib/python3.10/subprocess.py:524: CalledProcessError

During handling of the above exception, another exception occurred:

    def test_disabled_extensions():
        # Test that xp.extension errors when an extension is disabled, and that
        # xp.__all__ is updated properly.
    
        # First test that things are correct on the initial import. Since we have
        # already called set_array_api_strict_flags many times throughout running
        # the tests, we have to test this in a subprocess.
        subprocess_tests = [('''\
    import array_api_strict
    
    array_api_strict.linalg # No error
    array_api_strict.fft # No error
    assert "linalg" in array_api_strict.__all__
    assert "fft" in array_api_strict.__all__
    assert len(array_api_strict.__all__) == len(set(array_api_strict.__all__))
    ''', {}),
    # Test that the initial population of __all__ works correctly
    ('''\
    from array_api_strict import * # No error
    linalg # Should have been imported by the previous line
    fft
    ''', {}),
    ('''\
    from array_api_strict import * # No error
    linalg # Should have been imported by the previous line
    assert 'fft' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": "linalg"}),
    ('''\
    from array_api_strict import * # No error
    fft # Should have been imported by the previous line
    assert 'linalg' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": "fft"}),
    ('''\
    from array_api_strict import * # No error
    assert 'linalg' not in globals()
    assert 'fft' not in globals()
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": ""}),
    ]
        for test, env in subprocess_tests:
            try:
                subprocess.run([sys.executable, '-c', test], check=True,
                               capture_output=True, encoding='utf-8', env=env)
            except subprocess.CalledProcessError as e:
                print(e.stdout, end='')
                # Ensure the exception is shown in the output log
>               raise AssertionError(e.stderr)
E               AssertionError: Traceback (most recent call last):
E                 File "<string>", line 1, in <module>
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/__init__.py", line 29, in <module>
E                   from ._constants import e, inf, nan, pi, newaxis
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/_constants.py", line 1, in <module>
E                   import numpy as np
E               ModuleNotFoundError: No module named 'numpy'

array_api_strict/tests/test_flags.py:379: AssertionError
_________________________________________ test_environment_variables _________________________________________

    def test_environment_variables():
        # Test that the environment variables work as expected
        subprocess_tests = [
            # ARRAY_API_STRICT_API_VERSION
            ('''\
    import array_api_strict as xp
    assert xp.__array_api_version__ == '2023.12'
    
    assert xp.get_array_api_strict_flags()['api_version'] == '2023.12'
    
    ''', {}),
            *[
            (f'''\
    import array_api_strict as xp
    assert xp.__array_api_version__ == '{version}'
    
    assert xp.get_array_api_strict_flags()['api_version'] == '{version}'
    
    if {version} == '2021.12':
        assert hasattr(xp, 'linalg')
        assert not hasattr(xp, 'fft')
    
    ''', {"ARRAY_API_STRICT_API_VERSION": version}) for version in ('2021.12', '2022.12', '2023.12')],
    
           # ARRAY_API_STRICT_BOOLEAN_INDEXING
            ('''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    mask = xp.asarray([True, False, True])
    
    assert xp.all(a[mask] == xp.asarray([1., 1.]))
    assert xp.get_array_api_strict_flags()['boolean_indexing'] == True
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    mask = xp.asarray([True, False, True])
    
    if {boolean_indexing}:
        assert xp.all(a[mask] == xp.asarray([1., 1.]))
    else:
        try:
            a[mask]
        except RuntimeError:
            pass
        else:
            assert False
    
    assert xp.get_array_api_strict_flags()['boolean_indexing'] == {boolean_indexing}
    ''', {"ARRAY_API_STRICT_BOOLEAN_INDEXING": boolean_indexing})
                for boolean_indexing in ('True', 'False')],
    
            # ARRAY_API_STRICT_DATA_DEPENDENT_SHAPES
            ('''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    xp.unique_all(a)
    
    assert xp.get_array_api_strict_flags()['data_dependent_shapes'] == True
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    if {data_dependent_shapes}:
        xp.unique_all(a)
    else:
        try:
            xp.unique_all(a)
        except RuntimeError:
            pass
        else:
            assert False
    
    assert xp.get_array_api_strict_flags()['data_dependent_shapes'] == {data_dependent_shapes}
    ''', {"ARRAY_API_STRICT_DATA_DEPENDENT_SHAPES": data_dependent_shapes})
                for data_dependent_shapes in ('True', 'False')],
    
            # ARRAY_API_STRICT_ENABLED_EXTENSIONS
            ('''\
    import array_api_strict as xp
    assert hasattr(xp, 'linalg')
    assert hasattr(xp, 'fft')
    
    assert xp.get_array_api_strict_flags()['enabled_extensions'] == ('linalg', 'fft')
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    assert hasattr(xp, 'linalg') == ('linalg' in {extensions.split(',')})
    assert hasattr(xp, 'fft') == ('fft' in {extensions.split(',')})
    
    assert sorted(xp.get_array_api_strict_flags()['enabled_extensions']) == {sorted(set(extensions.split(','))-{''})}
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": extensions})
                for extensions in ('', 'linalg', 'fft', 'linalg,fft')],
        ]
    
        for test, env in subprocess_tests:
            try:
>               subprocess.run([sys.executable, '-c', test], check=True,
                               capture_output=True, encoding='utf-8', env=env)

array_api_strict/tests/test_flags.py:532: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input = None, capture_output = True, timeout = None, check = True
popenargs = (['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-python-wrapper-3.10.7/bin/python', '-c', "import array_api_strict as xp...ert xp.__array_api_version__ == '2023.12'\n\nassert xp.get_array_api_strict_flags()['api_version'] == '2023.12'\n\n"],)
kwargs = {'encoding': 'utf-8', 'env': {}, 'stderr': -1, 'stdout': -1}
process = <Popen: returncode: 1 args: ['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-py...>, stdout = ''
stderr = 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\n  File "/tmp/guix-build-python-array-api-...i_strict/_constants.py", line 1, in <module>\n    import numpy as np\nModuleNotFoundError: No module named \'numpy\'\n'
retcode = 1

    def run(*popenargs,
            input=None, capture_output=False, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.
    
        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
    
        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.
    
        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.
    
        There is an optional argument "input", allowing you to
        pass bytes or a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.
    
        By default, all communication is in bytes, and therefore any "input" should
        be bytes, and the stdout and stderr will be bytes. If in text mode, any
        "input" should be a string, and stdout and stderr will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode is
        triggered by setting any of text, encoding, errors or universal_newlines.
    
        The other arguments are the same as for the Popen constructor.
        """
        if input is not None:
            if kwargs.get('stdin') is not None:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE
    
        if capture_output:
            if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                raise ValueError('stdout and stderr arguments may not be used '
                                 'with capture_output.')
            kwargs['stdout'] = PIPE
            kwargs['stderr'] = PIPE
    
        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired as exc:
                process.kill()
                if _mswindows:
                    # Windows accumulates the output in a single blocking
                    # read() call run on child threads, with the timeout
                    # being done in a join() on those threads.  communicate()
                    # _after_ kill() is required to collect that and add it
                    # to the exception.
                    exc.stdout, exc.stderr = process.communicate()
                else:
                    # POSIX _communicate already populated the output so
                    # far into the TimeoutExpired exception.
                    process.wait()
                raise
            except:  # Including KeyboardInterrupt, communicate handled that.
                process.kill()
                # We don't call process.wait() as .__exit__ does that for us.
                raise
            retcode = process.poll()
            if check and retcode:
>               raise CalledProcessError(retcode, process.args,
                                         output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '['/gnu/store/cd9xnk7dcn5dfibjzvl6l7wk43s5ifg1-python-wrapper-3.10.7/bin/python', '-c', "import array_api_strict as xp\nassert xp.__array_api_version__ == '2023.12'\n\nassert xp.get_array_api_strict_flags()['api_version'] == '2023.12'\n\n"]' returned non-zero exit status 1.

/gnu/store/50047r6f9chb6dwd01f9hai90y9arwb4-python-3.10.7/lib/python3.10/subprocess.py:524: CalledProcessError

During handling of the above exception, another exception occurred:

    def test_environment_variables():
        # Test that the environment variables work as expected
        subprocess_tests = [
            # ARRAY_API_STRICT_API_VERSION
            ('''\
    import array_api_strict as xp
    assert xp.__array_api_version__ == '2023.12'
    
    assert xp.get_array_api_strict_flags()['api_version'] == '2023.12'
    
    ''', {}),
            *[
            (f'''\
    import array_api_strict as xp
    assert xp.__array_api_version__ == '{version}'
    
    assert xp.get_array_api_strict_flags()['api_version'] == '{version}'
    
    if {version} == '2021.12':
        assert hasattr(xp, 'linalg')
        assert not hasattr(xp, 'fft')
    
    ''', {"ARRAY_API_STRICT_API_VERSION": version}) for version in ('2021.12', '2022.12', '2023.12')],
    
           # ARRAY_API_STRICT_BOOLEAN_INDEXING
            ('''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    mask = xp.asarray([True, False, True])
    
    assert xp.all(a[mask] == xp.asarray([1., 1.]))
    assert xp.get_array_api_strict_flags()['boolean_indexing'] == True
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    mask = xp.asarray([True, False, True])
    
    if {boolean_indexing}:
        assert xp.all(a[mask] == xp.asarray([1., 1.]))
    else:
        try:
            a[mask]
        except RuntimeError:
            pass
        else:
            assert False
    
    assert xp.get_array_api_strict_flags()['boolean_indexing'] == {boolean_indexing}
    ''', {"ARRAY_API_STRICT_BOOLEAN_INDEXING": boolean_indexing})
                for boolean_indexing in ('True', 'False')],
    
            # ARRAY_API_STRICT_DATA_DEPENDENT_SHAPES
            ('''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    xp.unique_all(a)
    
    assert xp.get_array_api_strict_flags()['data_dependent_shapes'] == True
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    a = xp.ones(3)
    if {data_dependent_shapes}:
        xp.unique_all(a)
    else:
        try:
            xp.unique_all(a)
        except RuntimeError:
            pass
        else:
            assert False
    
    assert xp.get_array_api_strict_flags()['data_dependent_shapes'] == {data_dependent_shapes}
    ''', {"ARRAY_API_STRICT_DATA_DEPENDENT_SHAPES": data_dependent_shapes})
                for data_dependent_shapes in ('True', 'False')],
    
            # ARRAY_API_STRICT_ENABLED_EXTENSIONS
            ('''\
    import array_api_strict as xp
    assert hasattr(xp, 'linalg')
    assert hasattr(xp, 'fft')
    
    assert xp.get_array_api_strict_flags()['enabled_extensions'] == ('linalg', 'fft')
    ''', {}),
            *[(f'''\
    import array_api_strict as xp
    
    assert hasattr(xp, 'linalg') == ('linalg' in {extensions.split(',')})
    assert hasattr(xp, 'fft') == ('fft' in {extensions.split(',')})
    
    assert sorted(xp.get_array_api_strict_flags()['enabled_extensions']) == {sorted(set(extensions.split(','))-{''})}
    ''', {"ARRAY_API_STRICT_ENABLED_EXTENSIONS": extensions})
                for extensions in ('', 'linalg', 'fft', 'linalg,fft')],
        ]
    
        for test, env in subprocess_tests:
            try:
                subprocess.run([sys.executable, '-c', test], check=True,
                               capture_output=True, encoding='utf-8', env=env)
            except subprocess.CalledProcessError as e:
                print(e.stdout, end='')
                # Ensure the exception is shown in the output log
>               raise AssertionError(f"""\
    STDOUT:
    {e.stderr}
    
    STDERR:
    {e.stderr}
    
    TEST:
    {test}
    
    ENV:
    {env}""")
E               AssertionError: STDOUT:
E               Traceback (most recent call last):
E                 File "<string>", line 1, in <module>
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/__init__.py", line 29, in <module>
E                   from ._constants import e, inf, nan, pi, newaxis
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/_constants.py", line 1, in <module>
E                   import numpy as np
E               ModuleNotFoundError: No module named 'numpy'
E               
E               
E               STDERR:
E               Traceback (most recent call last):
E                 File "<string>", line 1, in <module>
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/__init__.py", line 29, in <module>
E                   from ._constants import e, inf, nan, pi, newaxis
E                 File "/tmp/guix-build-python-array-api-strict-2.2.drv-0/array_api_strict-2.2/array_api_strict/_constants.py", line 1, in <module>
E                   import numpy as np
E               ModuleNotFoundError: No module named 'numpy'
E               
E               
E               TEST:
E               import array_api_strict as xp
E               assert xp.__array_api_version__ == '2023.12'
E               
E               assert xp.get_array_api_strict_flags()['api_version'] == '2023.12'
E               
E               
E               
E               ENV:
E               {}

array_api_strict/tests/test_flags.py:537: AssertionError
========================================== short test summary info ===========================================
FAILED array_api_strict/tests/test_array_object.py::test_operators - TypeError: In-place matrix multiplicat...
FAILED array_api_strict/tests/test_flags.py::test_disabled_extensions - AssertionError: Traceback (most rec...
FAILED array_api_strict/tests/test_flags.py::test_environment_variables - AssertionError: STDOUT:
======================================= 3 failed, 171 passed in 3.36s ========================================

The first failure appears to be related to my version of numpy used: 1.24.4 though I see no specific numpy version requirement in this project.

The last two, I think are caused by resetting the environment variables; on my system the Python libraries are looked up via the GUIX_PYTHONPATH environment variable.

@Apteryks
Copy link
Author

Yeah, for the last two tests, it should probably override/set specific environment variables instead of overriding everything.

@ev-br
Copy link
Member

ev-br commented Feb 26, 2025

for the last two tests, it should probably override/set specific environment variables instead of overriding everything.

Indeed. A pull request with a fix is welcome!

The __imatmul__ error is a bit bizzare. It is true that we only test with numpy 1.26 and above, so it's possible that something is slightly off in earlier numpy versions. The failure though is in a code path which raises anyway, so here it's a slightly different error type, for an older numpy version. My gut feeling is it's OK to just ignore the failure. If it bothers you enough to dig in, great, we can review a PR with a fix.

@ev-br ev-br changed the title test failures test failures on Guix Feb 26, 2025
@Apteryks
Copy link
Author

I'm happy to ignore the last one knowing it'll auto-resolves itself by the time we upgrade our numpy. For the other fix, it looks simple to do, so let's it open so myself or someone can produce a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants