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 path

  • init_tree (str) – Full import path for the function used to create the class

  • method_name (str) – Name of the method

  • init_num_positional_args (default: None) – A search strategy that generates a number of positional arguments to be passed during instantiation of the class

  • init_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 arrays

  • init_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 array

  • test_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 function

  • method_num_positional_args (default: None) – A search strategy that generates a number of positional arguments to be passed during call of the class method

  • method_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 arrays

  • method_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 array

  • test_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 path

  • gt_fn_tree (Optional[str], default: None) – Full function import path for the ground truth function, by default will be the same as fn_tree

  • number_positional_args (default: None) – A search strategy for determining the number of positional arguments to be passed to the function

  • test_inplace (default: DynamicFlag(strategy=just(False))) – A search strategy that generates a boolean to test the method with inplace update

  • test_with_out (default: DynamicFlag(strategy=booleans())) – A search strategy that generates a boolean to test the function with an out parameter

  • test_with_copy (default: DynamicFlag(strategy=just(False))) – A search strategy that generates a boolean to test the function with an copy parameter

  • 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 function

  • 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 array

  • native_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 array

  • test_trace (default: DynamicFlag(strategy=just(False))) – A search strategy that generates a boolean to trace and test the function

  • test_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 path

  • ground_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 path

  • ground_truth_backend (str, default: 'tensorflow') – The framework to assert test results are equal to

  • number_positional_args (default: None) – A search strategy for determining the number of positional arguments to be passed to the function

  • test_instance_method (default: DynamicFlag(strategy=booleans())) – A search strategy that generates a boolean to test instance methods

  • test_with_out (default: DynamicFlag(strategy=booleans())) – A search strategy that generates a boolean to test the function with an out parameter

  • test_with_copy (default: DynamicFlag(strategy=just(False))) – A search strategy that generates a boolean to test the function with an copy parameter

  • test_gradients (default: DynamicFlag(strategy=_gradient_strategy())) – A search strategy that generates a boolean to test the function with arrays as gradients

  • test_trace (default: DynamicFlag(strategy=just(False))) – A search strategy that generates a boolean to trace and test the function

  • test_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 function

  • 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 array

  • native_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 array

  • container_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_helper(fn_name, backend)[source]#
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!