-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add test case to check if all ops are being verified #169
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f53ce01
Add test case to check if all non-method ops are being verified
Mgluhovskoi 864a830
Update tripy/tests/spec_verification/test_dtype_constraints.py
Mgluhovskoi 35fafd2
Add checking for all other ops
Mgluhovskoi 8bf5f76
Amendment
Mgluhovskoi 91a98bb
Pushed what I finished, might have to revert to previous commit since…
Mgluhovskoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,14 @@ | |
|
||
|
||
import inspect | ||
from typing import List | ||
from typing import List, Union, Optional, get_origin, get_args, ForwardRef, get_type_hints | ||
from tripy.common.datatype import DATA_TYPES | ||
import itertools | ||
import pytest | ||
from tests.spec_verification.object_builders import create_obj | ||
from tripy.constraints import TYPE_VERIFICATION, RETURN_VALUE | ||
from tripy.constraints import TYPE_VERIFICATION, RETURN_VALUE, FUNC_W_DOC_VERIF | ||
import tripy as tp | ||
from contextlib import ExitStack | ||
import tests.helper | ||
|
||
|
||
def _method_handler(func_name, kwargs, func_obj, api_call_locals): | ||
|
@@ -181,3 +181,77 @@ def test_neg_dtype_constraints(test_data): | |
api_call_locals, namespace = _run_dtype_constraints_subtest(test_data) | ||
if isinstance(api_call_locals[RETURN_VALUE], tp.Tensor): | ||
assert api_call_locals[RETURN_VALUE].dtype == namespace[return_dtype] | ||
|
||
|
||
def get_all_possible_verif_ops(): | ||
qualnames = set() | ||
tripy_interfaces = tests.helper.get_all_tripy_interfaces() | ||
for obj in tripy_interfaces: | ||
if not obj.__doc__: | ||
continue | ||
|
||
blocks = [ | ||
(block.code()) | ||
for block in tests.helper.consolidate_code_blocks(obj.__doc__) | ||
if isinstance(block, tests.helper.DocstringCodeBlock) | ||
] | ||
if blocks is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this ever happen? Even if nothing is found, |
||
continue | ||
|
||
if isinstance(obj, property): | ||
continue | ||
|
||
func_sig = inspect.signature(func_obj) | ||
param_dict = func_sig.parameters | ||
contains_tensor_input = False | ||
for type_hint in param_dict.values(): | ||
type_hint = type_hint.annotation | ||
while get_origin(type_hint) in [Union, Optional, list] and not contains_tensor_input: | ||
type_hint = get_args(type_hint)[0] | ||
# ForwardRef refers to any case where type hint is a string. | ||
if isinstance(type_hint, ForwardRef): | ||
type_hint = type_hint.__forward_arg__ | ||
if type_hint == "tripy.Tensor": | ||
print(type_hint) | ||
contains_tensor_input = True | ||
|
||
if not contains_tensor_input: | ||
continue | ||
|
||
qualnames.add(obj.__qualname__) | ||
|
||
return qualnames | ||
|
||
|
||
print(get_all_possible_verif_ops()) | ||
print(len(get_all_possible_verif_ops())) | ||
|
||
operations = get_all_possible_verif_ops() | ||
# add any function that you do not want to be verified: | ||
func_exceptions = [ | ||
"plugin", | ||
"dequantize", | ||
"default", | ||
"dtype", | ||
"function", | ||
"type", | ||
"tolist", | ||
"md5", | ||
"integer", | ||
"volume", | ||
"save", | ||
"floating", | ||
"load", | ||
"device", | ||
] | ||
|
||
|
||
# Check if there are any operations that are not included (Currently does not test any __<op>__ functions) | ||
@pytest.mark.parametrize("func_qualname", operations, ids=lambda val: f"is_{val}_verified") | ||
def test_all_ops_verified(func_qualname): | ||
if func_qualname not in func_exceptions: | ||
assert ( | ||
func_qualname in FUNC_W_DOC_VERIF | ||
), f"function {func_qualname}'s data types have not been verified. Please add data type verification by following the guide within tripy/tests/spec_verification or exclude it from this test." | ||
else: | ||
pytest.skip("Data type constraints are not required for this API") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach could be to check all public APIs, and then for classes, check their methods. We can then filter those on whether any of the type annotations include
tp.Tensor
.