| 1 | This folder contains tests for `hypothesis.extra.array_api`. |
| 2 | |
| 3 | ## Mocked array module |
| 4 | |
| 5 | A mock of the Array API namespace exists as `mock_xp` in `extra.array_api`. This |
| 6 | wraps NumPy-proper to conform it to the *draft* spec, where `array_api_strict` |
| 7 | might not. This is not a fully compliant wrapper, but conforms enough for the |
| 8 | purposes of testing. |
| 9 | |
| 10 | ## Running against different array modules |
| 11 | |
| 12 | You can test other array modules which adopt the Array API via the |
| 13 | `HYPOTHESIS_TEST_ARRAY_API` environment variable. There are two recognized |
| 14 | options: |
| 15 | |
| 16 | * `"default"`: uses the mock. |
| 17 | * `"all"`: uses all array modules found via entry points, _and_ the mock. |
| 18 | |
| 19 | If neither of these, the test suite will then try resolve the variable like so: |
| 20 | |
| 21 | 1. If the variable matches a name of an available entry point, load said entry point. |
| 22 | 2. If the variables matches a valid import path, import said path. |
| 23 | |
| 24 | For example, to specify NumPy's Array API implementation[^1], you could use its |
| 25 | entry point (**1.**), |
| 26 | |
| 27 | HYPOTHESIS_TEST_ARRAY_API=numpy pytest tests/array_api |
| 28 | |
| 29 | or use the import path (**2.**), |
| 30 | |
| 31 | HYPOTHESIS_TEST_ARRAY_API=numpy.array_api pytest tests/array_api |
| 32 | |
| 33 | The former method is more ergonomic, but as entry points are optional for |
| 34 | adopting the Array API, you will need to use the latter method for libraries |
| 35 | that opt-out. |
| 36 | |
| 37 | ## Running against different API versions |
| 38 | |
| 39 | You can specify the `api_version` to use when testing array modules via the |
| 40 | `HYPOTHESIS_TEST_ARRAY_API_VERSION` environment variable. There is one |
| 41 | recognized option: |
| 42 | |
| 43 | * `"default"`: infers the latest API version for each array module. |
| 44 | |
| 45 | Otherwise the test suite will use the variable as the `api_version` argument for |
| 46 | `make_strategies_namespace()`. |
| 47 | |
| 48 | In the future we intend to support running tests against multiple API versioned |
| 49 | namespaces, likely with an additional recognized option that infers all |
| 50 | supported versions. |
| 51 | |
| 52 | [^1]: Note NumPy will likely remove `numpy.array_api` in the future ([NEP 56](https://github.com/numpy/numpy/pull/25542)) |
| 53 | in favour of the third-party [`array-api-strict`](https://github.com/data-apis/array-api-strict) library. |