Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assert_passes(self, *args, **kwargs):
testslide.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, args, kwargs
)
def assert_fails(self, *args, **kwargs):
with self.assertRaisesRegex(
testslide.lib.TypeCheckError,
"Call to "
+ self.callable_template.__name__
+ " has incompatible argument types",
):
testslide.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, args, kwargs
)
def callable_mock_with_type_validation(*args, **kwargs):
for callable_template in callable_templates:
if _validate_callable_signature(
False,
callable_template,
template,
callable_template.__name__,
args,
kwargs,
):
_validate_callable_arg_types(False, callable_template, args, kwargs)
return callable_mock(*args, **kwargs)
def gives_correct_error_message_for_invalid_types(self):
with self.assertRaises(
testslide.lib.TypeCheckError,
msg=(
"Call to test_function has incompatible argument types:\n"
" 'arg1': type of arg1 must be str; got int instead\n"
" 'arg2': type of arg2 must be str; got int instead\n"
" 'kwarg1': type of kwarg1 must be str; got int instead\n"
" 'kwarg2': type of kwarg2 must be str; got int instead"
),
):
testslide.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, (1, 2, 3, 4), {}
)