How to use the testslide.lib 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 / testslide / strict_mock.py View on Github external
async def awaitable_return_validation_wrapper(
                                *args, **kwargs
                            ):
                                result_awaitable = signature_validation_wrapper(
                                    *args, **kwargs
                                )
                                if not inspect.isawaitable(result_awaitable):
                                    raise NonAwaitableReturn(self, name)

                                return_value = await result_awaitable
                                if not isinstance(
                                    value, testslide.mock_callable._CallableMock
                                ):
                                    testslide.lib._validate_return_type(
                                        template_value,
                                        return_value,
                                        self.__dict__["_caller_frame_info"],
                                    )
                                return return_value
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
def return_validation_wrapper(*args, **kwargs):
                                return_value = signature_validation_wrapper(
                                    *args, **kwargs
                                )
                                if self.__dict__["_type_validation"] and not isinstance(
                                    value, testslide.mock_callable._CallableMock
                                ):
                                    testslide.lib._validate_return_type(
                                        template_value,
                                        return_value,
                                        self.__dict__["_caller_frame_info"],
                                    )
                                return return_value
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def assert_passes(self, value):
        testslide.lib._validate_return_type(
            self.callable_template, value, self.caller_frame_info
        )
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
def _validate_and_wrap_mock_value(self, name, value):
        if self._template:
            if not self._template_has_attr(name):
                raise NonExistentAttribute(self, name)

            self._validate_attribute_type(name, value)

            if hasattr(self._template, name):
                template_value = getattr(self._template, name)
                if callable(template_value):
                    if not callable(value):
                        raise NonCallableValue(self, name)
                    if self.__dict__["_type_validation"]:
                        signature_validation_wrapper = testslide.lib._wrap_signature_and_type_validation(
                            value,
                            self._template,
                            name,
                            self.__dict__["_type_validation"],
                        )

                        if inspect.iscoroutinefunction(template_value):

                            async def awaitable_return_validation_wrapper(
                                *args, **kwargs
                            ):
                                result_awaitable = signature_validation_wrapper(
                                    *args, **kwargs
                                )
                                if not inspect.isawaitable(result_awaitable):
                                    raise NonAwaitableReturn(self, name)
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
memo[id(self)] = self_copy

        for name in self._get_copyable_attrs(self_copy):
            value = copy.deepcopy(type(self).__dict__[name], memo)
            setattr(type(self_copy), name, value)
        return self_copy


def _extract_StrictMock_template(mock_obj) -> Optional[Any]:
    if "_template" in mock_obj.__dict__ and mock_obj._template is not None:
        return mock_obj._template

    return None


testslide.lib.MOCK_TEMPLATE_EXTRACTORS[StrictMock] = _extract_StrictMock_template
github facebookincubator / TestSlide / testslide / strict_mock.py View on Github external
def _validate_attribute_type(self, name, value):
        if not self.__dict__["_type_validation"]:
            return

        if hasattr(self._template, "__annotations__"):
            annotations = self._template.__annotations__
            if name in annotations:
                testslide.lib._validate_argument_type(annotations[name], name, value)