How to use the testslide.lib.TypeCheckError function in TestSlide

To help you get started, we’ve selected a few TestSlide examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def raises_TypeCheckError(self):
                                        with self.assertRaises(TypeCheckError):
                                            self.callable_target(
                                                *self.call_args, **self.call_kwargs
                                            )
github facebookincubator / TestSlide / testslide / lib.py View on Github external
inner_expected_type,
            *args,
            globals=globals,
            locals=locals,
            **kwargs,
        )

    with unittest.mock.patch.object(
        typeguard, "check_type", new=wrapped_check_type
    ), unittest.mock.patch.object(
        typeguard, "qualified_name", new=wrapped_qualified_name
    ):
        try:
            typeguard.check_type(name, value, expected_type)
        except TypeError as type_error:
            raise TypeCheckError(str(type_error))
github facebookincubator / TestSlide / tests / mock_constructor_testslide.py View on Github external
def it_fails_with_invalid_types(self):
            with self.assertRaises(TypeCheckError):
                self.target(message=1234)
github facebookincubator / TestSlide / tests / mock_callable_testslide.py View on Github external
def raises_TypeCheckError_for_invalid_types(self):
                                bad_signature_args = (1234 for arg in self.call_args)
                                bad_signature_kargs = {
                                    k: 1234 for k, v in self.call_kwargs.items()
                                }
                                with self.assertRaises(TypeCheckError):
                                    self.callable_target(
                                        *bad_signature_args, **bad_signature_kargs
                                    )
github facebookincubator / TestSlide / testslide / lib.py View on Github external
_validate_argument_type(expected_type, argname, args[idx])
            except TypeCheckError as type_error:
                type_errors.append(f"{repr(argname)}: {type_error}")

    for argname, value in kwargs.items():
        try:
            expected_type = argspec.annotations.get(argname)
            if not expected_type:
                continue

            _validate_argument_type(expected_type, argname, value)
        except TypeCheckError as type_error:
            type_errors.append(f"{repr(argname)}: {type_error}")

    if type_errors:
        raise TypeCheckError(
            "Call to "
            + callable_template.__name__
            + " has incompatible argument types:\n  "
            + "\n  ".join(type_errors)
        )
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def assert_fails(self, value):
        assert_regex = (
            r"(?s)type of return must be .+; got .+ instead: .+Defined at .+:\d+"
        )
        with self.assertRaisesRegex(testslide.lib.TypeCheckError, assert_regex):
            testslide.lib._validate_return_type(
                self.callable_template, value, self.caller_frame_info
            )
github facebookincubator / TestSlide / tests / strict_mock_testslide.py View on Github external
def raises_TypeCheckError_when_setting_with_mock_with_invalid_type_template(
                            self,
                        ):
                            with self.assertRaises(TypeCheckError):
                                self.strict_mock.non_callable = unittest.mock.Mock(
                                    spec=int
                                )
                            with self.assertRaises(TypeCheckError):
                                self.strict_mock.non_callable = StrictMock(template=int)