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

JSON reporting #131

Merged
merged 23 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
17b3eab
Reintroduce test_has_names
asmeurer Jun 24, 2022
fdb7ffd
Move test_has_names to its own file
asmeurer Jun 24, 2022
cfbef56
Add .report.json to .gitignore
asmeurer Jun 24, 2022
7623741
Store the module name in the test metadata
asmeurer Jun 24, 2022
3f25af0
Revert import change in test_signatures.py
asmeurer Jun 29, 2022
ed4d58e
Some work on adding additional metadata to the json report
asmeurer Aug 1, 2022
7f25cec
Move reporting stuff to its own file, and add parametrize values to t…
asmeurer Aug 2, 2022
1f5284e
Make more types of test parameters JSON serializable
asmeurer Aug 2, 2022
d094951
Include the array_api_tests version in the JSON report metadata
asmeurer Aug 2, 2022
0c94174
Add hypothesis information to the JSON report metadata
asmeurer Aug 2, 2022
befbd80
Add a check that the custom JSON report metadata is always JSON seria…
asmeurer Aug 2, 2022
05c7802
Add array_attributes to stubs.__all__
asmeurer Aug 2, 2022
9497ecd
Don't enable the add_api_name_to_metadata fixture unless --json-repor…
asmeurer Aug 2, 2022
b5234ad
Use a better name for the fixture
asmeurer Aug 2, 2022
f8e562c
Fix undefined name
asmeurer Aug 2, 2022
3dca2ad
Allow classes to be JSON serialized in the JSON report
asmeurer Aug 2, 2022
d62073a
Add pytest-json-report to requirements.txt
asmeurer Aug 2, 2022
1c42d3a
Add a check that pytest-json-report is installed
asmeurer Aug 2, 2022
98db893
Remove attempt to only enable the fixture when --json-report is used
asmeurer Aug 2, 2022
775d25b
Add a repr() fallback for any non-JSON-serializable type
asmeurer Aug 2, 2022
f356ffd
Use shorter tracebacks in the JSON report
asmeurer Aug 3, 2022
a1ccd19
Revert "Use shorter tracebacks in the JSON report"
asmeurer Aug 3, 2022
0841ef3
De-duplicate warnings metadata in the report JSON
asmeurer Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# pytest-json-report
.report.json
4 changes: 4 additions & 0 deletions array_api_tests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
f for n, f in inspect.getmembers(array, predicate=inspect.isfunction)
if n != "__init__" # probably exists for Sphinx
]
array_attributes = [
Copy link
Member

Choose a reason for hiding this comment

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

How about array_properties?

Copy link
Member

Choose a reason for hiding this comment

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

And in any case, if you could add this to __all__. Maybe this is just a weird side product of how I learnt Python, but I like using it to denote the internally-public API of a module.

n for n, f in inspect.getmembers(array, predicate=lambda x: not inspect.isfunction(x))
if n != "__init__" # probably exists for Sphinx
]

category_to_funcs: Dict[str, List[FunctionType]] = {}
for name, mod in name_to_mod.items():
Expand Down
37 changes: 37 additions & 0 deletions array_api_tests/test_has_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
This is a very basic test to see what names are defined in a library. It
does not even require functioning hypothesis array_api support.
"""

import pytest

from ._array_module import mod as xp, mod_name
from .stubs import (array_attributes, array_methods, category_to_funcs,
extension_to_funcs, EXTENSIONS)

has_name_params = []
for ext, stubs in extension_to_funcs.items():
for stub in stubs:
has_name_params.append(pytest.param(ext, stub.__name__))
for cat, stubs in category_to_funcs.items():
for stub in stubs:
has_name_params.append(pytest.param(cat, stub.__name__))
for meth in array_methods:
has_name_params.append(pytest.param('array_method', meth.__name__))
for attr in array_attributes:
has_name_params.append(pytest.param('array_attribute', attr))

@pytest.mark.parametrize("category, name", has_name_params)
def test_has_names(category, name):
if category in EXTENSIONS:
ext_mod = getattr(xp, category)
assert hasattr(ext_mod, name), f"{mod_name} is missing the {category} extension function {name}()"
elif category.startswith('array_'):
# TODO: This would fail if ones() is missing.
arr = xp.ones((1, 1))
if category == 'array_attribute':
assert hasattr(arr, name), f"The {mod_name} array object is missing the attribute {name}"
else:
assert hasattr(arr, name), f"The {mod_name} array object is missing the method {name}()"
else:
assert hasattr(xp, name), f"{mod_name} is missing the {category} function {name}()"
3 changes: 1 addition & 2 deletions array_api_tests/test_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def squeeze(x, /, axis):
from . import dtype_helpers as dh
from . import hypothesis_helpers as hh
from . import xps
from ._array_module import _UndefinedStub
from ._array_module import mod as xp
from ._array_module import _UndefinedStub, mod as xp
honno marked this conversation as resolved.
Show resolved Hide resolved
from .stubs import array_methods, category_to_funcs, extension_to_funcs
from .typing import Array, DataType

Expand Down
9 changes: 8 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ def pytest_collection_modifyitems(config, items):
mark.skip(reason="disabled via --disable-data-dependent-shapes")
)
break
# skip if test not appropiate for CI
# skip if test not appropriate for CI
if ci:
ci_mark = next((m for m in markers if m.name == "ci"), None)
if ci_mark is None:
item.add_marker(mark.skip(reason="disabled via --ci"))

@mark.optionalhook
def pytest_metadata(metadata):
"""
Additional metadata for --json-report.
"""
metadata['array_api_tests_module'] = xp.mod_name