Testing helpers#
- ivy_tests.test_ivy.helpers.testing_helpers.handle_example(*, test_example=False, test_frontend_example=False, test_method_example=False, test_frontend_method_example=False, **given_kwargs)[source]#
- ivy_tests.test_ivy.helpers.testing_helpers.handle_frontend_method(*, class_tree, init_tree, method_name, init_num_positional_args=None, init_native_arrays=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), init_as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), test_trace=DynamicFlag(strategy=just(False)), test_trace_each=DynamicFlag(strategy=just(False)), precision_mode=DynamicFlag(strategy=booleans()), method_num_positional_args=None, method_native_arrays=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), method_as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), test_inplace=DynamicFlag(strategy=just(False)), generate_frontend_arrays=DynamicFlag(strategy=booleans()), **_given_kwargs)[source]#
Test wrapper for Ivy frontends methods.
The wrapper sets the required test globals and creates test flags strategies.
- Parameters:
class_tree (
str
) – Full class import pathinit_tree (
str
) – Full import path for the function used to create the classmethod_name (
str
) – Name of the methodinit_num_positional_args (default:
None
) – A search strategy that generates a number of positional arguments to be passed during instantiation of the classinit_native_arrays (default:
DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1))
) – A search strategy that generates a boolean to test the method with native arraysinit_as_variable_flags (default:
DynamicFlag(strategy=_as_varaible_strategy())
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a Variable arraytest_compile – A search strategy that generates a boolean to graph compile and test the function
precision_mode (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to switch between two different precision modes supported by numpy and (torch, jax) and test the functionmethod_num_positional_args (default:
None
) – A search strategy that generates a number of positional arguments to be passed during call of the class methodmethod_native_arrays (default:
DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1))
) – A search strategy that generates a boolean to test the method with native arraysmethod_as_variable_flags (default:
DynamicFlag(strategy=_as_varaible_strategy())
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a Variable arraytest_inplace (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to test the method with inplace update
- ivy_tests.test_ivy.helpers.testing_helpers.handle_frontend_test(*, fn_tree, gt_fn_tree=None, aliases=None, number_positional_args=None, test_with_out=DynamicFlag(strategy=booleans()), test_with_copy=DynamicFlag(strategy=just(False)), test_inplace=DynamicFlag(strategy=just(False)), as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), native_array_flags=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), test_trace=DynamicFlag(strategy=just(False)), test_trace_each=DynamicFlag(strategy=just(False)), generate_frontend_arrays=DynamicFlag(strategy=booleans()), transpile=DynamicFlag(strategy=just(False)), precision_mode=DynamicFlag(strategy=booleans()), **_given_kwargs)[source]#
Test wrapper for Ivy frontend functions.
The wrapper sets the required test globals and creates test flags strategies.
- Parameters:
fn_tree (
str
) – Full function import pathgt_fn_tree (
Optional
[str
], default:None
) – Full function import path for the ground truth function, by default will be the same as fn_treenumber_positional_args (default:
None
) – A search strategy for determining the number of positional arguments to be passed to the functiontest_inplace (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to test the method with inplace updatetest_with_out (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to test the function with an out parametertest_with_copy (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to test the function with an copy parameterprecision_mode (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to switch between two different precision modes supported by numpy and (torch, jax) and test the functionas_variable_flags (default:
DynamicFlag(strategy=_as_varaible_strategy())
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a Variable arraynative_array_flags (default:
DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1))
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a native arraytest_trace (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to trace and test the functiontest_trace_each (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to trace and test the function (trace each example separately)generate_frontend_arrays (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a list of boolean flags for array inputs to be frontend array
- ivy_tests.test_ivy.helpers.testing_helpers.handle_method(*, init_tree='', method_tree=None, ground_truth_backend='tensorflow', test_gradients=DynamicFlag(strategy=_gradient_strategy()), test_trace=DynamicFlag(strategy=just(False)), test_trace_each=DynamicFlag(strategy=just(False)), precision_mode=DynamicFlag(strategy=booleans()), init_num_positional_args=None, init_native_arrays=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), init_as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), method_num_positional_args=None, method_native_arrays=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), method_as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), method_container_flags=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), **_given_kwargs)[source]#
Test wrapper for Ivy methods.
The wrapper sets the required test globals and creates test flags strategies.
- Parameters:
method_tree (
Optional
[str
], default:None
) – Full method import pathground_truth_backend (
str
, default:'tensorflow'
) – The framework to assert test results are equal to
- ivy_tests.test_ivy.helpers.testing_helpers.handle_test(*, fn_tree=None, ground_truth_backend='tensorflow', number_positional_args=None, test_instance_method=DynamicFlag(strategy=booleans()), test_with_out=DynamicFlag(strategy=booleans()), test_with_copy=DynamicFlag(strategy=just(False)), test_gradients=DynamicFlag(strategy=_gradient_strategy()), test_trace=DynamicFlag(strategy=just(False)), test_trace_each=DynamicFlag(strategy=just(False)), transpile=DynamicFlag(strategy=just(False)), precision_mode=DynamicFlag(strategy=booleans()), as_variable_flags=DynamicFlag(strategy=_as_varaible_strategy()), native_array_flags=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), container_flags=DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1)), test_cython_wrapper=DynamicFlag(strategy=just(False)), **_given_kwargs)[source]#
Test wrapper for Ivy functions.
The wrapper sets the required test globals and creates test flags strategies.
- Parameters:
fn_tree (
Optional
[str
], default:None
) – Full function import pathground_truth_backend (
str
, default:'tensorflow'
) – The framework to assert test results are equal tonumber_positional_args (default:
None
) – A search strategy for determining the number of positional arguments to be passed to the functiontest_instance_method (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to test instance methodstest_with_out (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to test the function with an out parametertest_with_copy (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to test the function with an copy parametertest_gradients (default:
DynamicFlag(strategy=_gradient_strategy())
) – A search strategy that generates a boolean to test the function with arrays as gradientstest_trace (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to trace and test the functiontest_trace_each (default:
DynamicFlag(strategy=just(False))
) – A search strategy that generates a boolean to trace and test the function (trace each example separately)precision_mode (default:
DynamicFlag(strategy=booleans())
) – A search strategy that generates a boolean to switch between two different precision modes supported by numpy and (torch, jax) and test the functionas_variable_flags (default:
DynamicFlag(strategy=_as_varaible_strategy())
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a Variable arraynative_array_flags (default:
DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1))
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a native arraycontainer_flags (default:
DynamicFlag(strategy=lists(booleans(), min_size=1, max_size=1))
) – A search strategy that generates a list of boolean flags for array inputs to be passed as a Container
- ivy_tests.test_ivy.helpers.testing_helpers.num_positional_args(*, fn_name=None)#
Draws an integers randomly from the minimum and maximum number of positional arguments a given function can take.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
fn_name (
Optional
[str
], default:None
) – name of the function.
- Return type:
SearchStrategy
- Returns:
A strategy that can be used in the @given hypothesis decorator.
Examples
- @given(
num_positional_args=num_positional_args(fn_name=”floor_divide”)
) @given(
num_positional_args=num_positional_args(fn_name=”add”)
)
- ivy_tests.test_ivy.helpers.testing_helpers.num_positional_args_method(*, method)#
Draws an integers randomly from the minimum and maximum number of positional arguments a given method can take.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
method – callable method
- Return type:
SearchStrategy
- Returns:
A strategy that can be used in the @given hypothesis decorator.
- ivy_tests.test_ivy.helpers.testing_helpers.seed()#
- Return type:
SearchStrategy
This should have hopefully given you an overview of the testing_helpers submodule, if you have any questions, please feel free to reach out on our discord!