Skip to content

TST: Redesign test_all #315

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

crusaderky
Copy link
Contributor

@crusaderky crusaderky commented Apr 21, 2025

#288 introduced __dir__, which completely neutered test_all.
Instead of reverting the change, this PR attempts to reinvent the test to be more useful.

CC @jorenham @ev-br

@Copilot Copilot AI review requested due to automatic review settings April 21, 2025 10:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR overhauls the testing of exported names by replacing the old test_all function with new, more focused tests and by standardizing the dir implementations across multiple array_api_compat modules. Key changes include:

  • Replacing the test_all function with new tests (test_dir and test_builtins_collision) that better validate module exports.
  • Removing redundant _all_ignore variables and cleaning up all definitions and dir implementations in various modules.
  • Consolidating all settings in numpy, torch, dask, cupy, and common modules for more consistent behavior.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_all.py New tests using NAMES/XFAILS and updated parameterizations replacing test_all.
array_api_compat/torch/linalg.py Removed _all_ignore and cleaned up all and dir definitions.
array_api_compat/torch/fft.py Removed _all_ignore; standardized dir definition.
array_api_compat/torch/_aliases.py Removed _all_ignore to simplify export handling.
array_api_compat/numpy/linalg.py Revised all composition and removed redundant concatenation of all.
array_api_compat/numpy/fft.py Modified all concatenation and removed extra deletion lines for cleanup.
array_api_compat/numpy/_typing.py Removed _all_ignore.
array_api_compat/numpy/_aliases.py Updated all assembly and removed _all_ignore for consistency.
array_api_compat/dask/array/linalg.py Removed _all_ignore and added a dir function returning all.
array_api_compat/dask/array/fft.py Removed _all_ignore and standardized dir implementation.
array_api_compat/dask/array/_aliases.py Removed _all_ignore.
array_api_compat/cupy/_typing.py Removed _all_ignore.
array_api_compat/cupy/_aliases.py Removed _all_ignore.
array_api_compat/common/_linalg.py Removed _all_ignore.
array_api_compat/common/_helpers.py Removed _all_ignore.
array_api_compat/common/_aliases.py Removed _all_ignore.

@crusaderky crusaderky changed the title Overhaul test_all TST: Redesign test_all Apr 21, 2025

NAMES = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better version of this test could automatically scrape data-apis/array-api/?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@crusaderky crusaderky Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting that array-api-compat should add array-api as a git submodule, for testing only?
If so, do you agree that such a change is best left to a follow-up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting that array-api-compat should add array-api as a git submodule, for testing only?

Definitely not.

If so, do you agree that such a change is best left to a follow-up?

Absolutely yes.

Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the purpose of test_all --- with all its considerable sins! --- was three-fold:

  • make sure that the user-visible dir/all lists contain everything they should
  • make sure that unwanted names do not bleed into the user-visible dir/all lists
  • make sure that internal implementation modules __all__ lists are sensible

This PR seems to work for the first item; the second one seems to still allow some strange things:

In [11]: import array_api_compat.numpy as anp

In [12]: "Final" in dir(anp)
Out[12]: True

In [13]: import numpy as np

In [14]: "Final" in dir(np)
Out[14]: False

For the third item, maybe we should somehow check that __all__ lists do not contain duplicate items? This would be useful for development (for one recent example, I'm not entirely sure if #317 does it right with __all__ lists; would be nice to have a test support for this)

@crusaderky
Copy link
Contributor Author

I've heavily reworked the PR and fixed many issues where array-api-compat was hiding objects declared in the wrapped module.
Output of the new test vs. the old array_api_compat is as follows:

FAILED tests/test_all.py::test_array_api_names[numpy-] - AssertionError: Missing exports: {'__array_api_version__', '__array_namespace_info__'}
FAILED tests/test_all.py::test_array_api_names[cupy-] - AssertionError: Missing exports: {'__array_api_version__', '__array_namespace_info__'}
FAILED tests/test_all.py::test_array_api_names[torch-] - AssertionError: Missing exports: {'__array_api_version__', '__array_namespace_info__'}
FAILED tests/test_all.py::test_array_api_names[dask.array-] - AssertionError: Missing exports: {'__array_api_version__', '__array_namespace_info__'}
FAILED tests/test_all.py::test_compat_doesnt_hide_names[numpy-] - AssertionError: Non-Array API names have been hidden: {'test', 'kernel_version', 'numarray', 'polynomial', 'compat', 'typing', 'testing', 'version', 'dtypes', 'l...
FAILED tests/test_all.py::test_compat_doesnt_hide_names[numpy-fft] - AssertionError: Non-Array API names have been hidden: {'test', 'helper'}
FAILED tests/test_all.py::test_compat_doesnt_hide_names[numpy-linalg] - AssertionError: Non-Array API names have been hidden: {'test', 'linalg'}
FAILED tests/test_all.py::test_compat_doesnt_hide_names[torch-] - AssertionError: Non-Array API names have been hidden: {'cpu', 'cuda'}
FAILED tests/test_all.py::test_compat_doesnt_hide_names[torch-fft] - AssertionError: Non-Array API names have been hidden: {'ihfftn', 'common_args', 'hfft2', 'factory_common_args', 'ihfft2', 'sys', 'hfftn'}
FAILED tests/test_all.py::test_compat_doesnt_hide_names[dask.array-] - AssertionError: Non-Array API names have been hidden: {'einsumfuncs', 'annotations', 'utils', 'optimization', 'chunk_types', 'warnings', 'wrap', 'reductions', 'r...
FAILED tests/test_all.py::test_compat_doesnt_add_names[numpy-] - AssertionError: array-api-compat is adding non-Array API names: {'is_pydata_sparse_namespace', 'is_numpy_array', 'is_ndonnx_namespace', 'is_cupy_namespace', 'is_...
FAILED tests/test_all.py::test_compat_doesnt_add_names[torch-fft] - AssertionError: array-api-compat is adding non-Array API names: {'annotations', 'Sequence', 'Union', 'Literal', 'Array'}
FAILED tests/test_all.py::test_compat_doesnt_add_names[dask.array-] - AssertionError: array-api-compat is adding non-Array API names: {'Final'}
FAILED tests/test_all.py::test_compat_doesnt_add_names[dask.array-fft] - AssertionError: array-api-compat is adding non-Array API names: {'get_xp', 'fft_all', 'da'}
FAILED tests/test_all.py::test_compat_doesnt_add_names[dask.array-linalg] - AssertionError: array-api-compat is adding non-Array API names: {'Literal', 'linalg_all', 'get_xp', 'da'}

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

Successfully merging this pull request may close these issues.

2 participants