Although we stress that easycheck check functions are designed to be used within code, it does not mean that they cannot be used in testing. In fact, they can be quite helpful. The easycheck package offers several assert functions. They have very similar signatures to the corresponding check functions, but they work like the assert expression, meaning they are run only in the debug mode (that is, when __debug__ is True). These functions are
assert_if(forcheck_if)assert_if_not(forcheck_if_not)assert_if_in_limits(forcheck_if_in_limits)assert_length(forcheck_length)assert_type(forcheck_type)assert_paths(forcheck_if_paths_exist)assert_if_isclose(forcheck_if_isclose)
They use the same syntax and arguments as their easycheck counterparts, the only differences is that they work only for __debug__ = True, which is always true for tests. See:
>>> from easycheck import assert_if, assert_type, assert_length
>>> def multiply_string(string, k):
... """Make a list consisting of string k times.
... >>> single_string = 'aka'
... >>> string_multiplied = multiply_string(single_string, 3)
... >>> assert_type(string_multiplied, list)
... >>> for i, item in enumerate(string_multiplied):
... assert_type(item, str)
... assert_if(item == single_string)
... >>> assert_length(string_multiplied, 3)
... """
... return [string] * kWhen you run doctests, all tests will run without error, as in the below simulation of the corresponding doctests from the above docstring:
>>> single_string = 'aka'
>>> string_multiplied = multiply_string(single_string, 3)
>>> assert_type(string_multiplied, list)
>>> for i, item in enumerate(string_multiplied):
... assert_type(item, str)
... assert_if(item == single_string)
>>> assert_length(string_multiplied, 3)Do remember, however, that the testing functions use only AssertionError! They do not have the handle_with argument, as they are designed to work in a similar way to regular assertions, the only difference being specificity of each function.
>>> from easycheck import check_if
>>> check_if(2 < 1)
Traceback (most recent call last):
...
AssertionError