GithubHelp home page GithubHelp logo

szha / array-api-tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from data-apis/array-api-tests

1.0 1.0 0.0 344 KB

Test suite for the PyData Array APIs standard

License: MIT License

Python 100.00%

array-api-tests's Introduction

Array API Standard Test Suite

This is the test suite for the PyData Array APIs standard.

NOTE: This test suite is still a work in progress.

Feedback and contributions are welcome, but be aware that this suite is not yet completed. In particular, there are still many parts of the array API specification that are not yet tested here.

Running the tests

To run the tests, first install the testing dependencies

pip install pytest hypothesis

or

conda install pytest hypothesis

as well as the array libraries that you want to test. To run the tests, you need to set the array library that is to be tested. There are two ways to do this. One way is to set the ARRAY_API_TESTS_MODULE environment variable. For example

ARRAY_API_TESTS_MODULE=numpy pytest

Alternately, edit the array_api_tests/_array_module.py file and change the line

array_module = None

to

import numpy as array_module

(replacing numpy with the array module namespace to be tested).

Notes on Interpreting Errors

  • Some tests cannot be run unless other tests pass first. This is because very basic APIs such as certain array creation APIs are required for a large fraction of the tests to run. TODO: Write which tests are required to pass first here.

  • If an error message involves _UndefinedStub, it means some name that is required for the test to run is not defined in the array library.

  • Due to the nature of the array api spec, virtually every array library will produce a large number of errors from nonconformance. It is still a work in progress to enable reporting the errors in a way that makes them easy to understand, even if there are a large number of them.

  • The spec documents are the ground source of truth. If the test suite appears to be testing something that is different from the spec, or something that isn't actually mentioned in the spec, this is a bug. Please report it. Furthermore, be aware that some aspects of the spec are either impossible or extremely difficult to actually test, so they are not covered in the test suite (TODO: list what these are).

Contributing

Adding Tests

It is important that every test in the test suite only uses APIs that are part of the standard. This means that, for instance, when creating test arrays, you should only use array creation functions that are part of the spec, such as ones or full. It also means that many array testing functions that are built-in to libraries like numpy are reimplemented in the test suite (see array_api_tests/pytest_helpers.py, array_api_tests/array_helpers.py, and array_api_tests/hypothesis_helpers.py).

In order to enforce this, the array_api_tests._array_module should be used everywhere in place of the actual array module that is being tested.

Hypothesis

The test suite uses Hypothesis to generate random input data. Any test that should be applied over all possible array inputs should use hypothesis tests. Custom Hypothesis strategies are in the array_api_tests/hypothesis_helpers.py file.

Parameterization

Any test that applies over all functions in a module should use pytest.mark.parametrize to parameterize over them. For example,

from . import function_stubs

@pytest.mark.parametrize('name', function_stubs.__all__)
def test_whatever(name):
    ...

will parameterize test_whatever over all the functions stubs generated from the spec. Parameterization should be preferred over using Hypothesis whenever there are a finite number of input possibilities, as this will cause pytest to report failures for all input values separately, as opposed to Hypothesis which will only report one failure.

Error Strings

Any assertion or exception should be accompanied with a useful error message. The test suite is designed to be ran by people who are not familiar with the test suite code, so the error messages should be self explanatory as to why the module fails a given test.

Meta-errors

Any error that indicates a bug in the test suite itself, rather than in the array module not following the spec, should use RuntimeError whenever possible.

(TODO: Update this policy to something better. See #5.)

Automatically Generated Files

Some files in the test suite are automatically generated from the API spec files. These files should not be edited directly. To regenerate these files, run the script

./generate_stubs.py path/to/array-api

where path/to/array-api is the path to the local clone of the array-api repo. To modify the automatically generated files, edit the code that generates them in the generate_stubs.py script.

array-api-tests's People

Contributors

asmeurer avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.