How to use the testslide.StrictMock 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 / lib_testslide.py View on Github external
def passes_without_template(self):
            strict_mock = StrictMock()
            self.assert_passes(strict_mock, "arg2", kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_passes("arg1", strict_mock, kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_passes("arg1", "arg2", kwarg1=strict_mock, kwarg2="kwarg2")
            self.assert_passes("arg1", "arg2", kwarg1="kwarg1", kwarg2=strict_mock)
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def fails_for_mock_with_wrong_template(self):
        self.assert_fails(StrictMock(template=int))
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def passes_with_StritMock_without_template(self):
                self.assert_passes({"StrictMock": StrictMock()})
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def fails_with_StritMock_with_invalid_template(self):
                self.assert_fails(
                    {"StrictMock(template=dict)": ("str", StrictMock(template=dict),)}
                )
github facebookincubator / TestSlide / testslide / patch_attribute.py View on Github external
the attribute name and new_value.. is the value to be patched.

    patch_attribute() has special mechanics so it "just works" for all cases.

    For example, patching a @property at an instance requires changes in the
    class, which may affect other instances. patch_attribute() takes care of
    what's needed, so only the target instance is affected.
    """
    _bail_if_private(attribute, allow_private)

    if isinstance(target, str):
        target = testslide._importer(target)

    key = (id(target), attribute)

    if isinstance(target, testslide.StrictMock):
        template_class = target._template
        if template_class:
            value = getattr(template_class, attribute)
            if not isinstance(value, type) and callable(value):
                raise ValueError(
                    "Attribute can not be callable!\n"
                    "You can either use mock_callable() / mock_async_callable() instead."
                )

        def strict_mock_hasattr(obj, name):
            try:
                return hasattr(obj, name)
            except UndefinedAttribute:
                return False

        if strict_mock_hasattr(target, attribute) and key not in _unpatchers:
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def passes_with_valid_template(self):
            strict_mock = StrictMock(template=str)
            self.assert_passes(strict_mock, "arg2", kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_passes("arg1", strict_mock, kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_passes("arg1", "arg2", kwarg1=strict_mock, kwarg2="kwarg2")
            self.assert_passes("arg1", "arg2", kwarg1="kwarg1", kwarg2=strict_mock)
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def passes_with_StritMock_without_template(self):
                self.assert_passes({"StrictMock": ("str", StrictMock(),)})
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def passes_with_StritMock_with_valid_template(self):
                self.assert_passes(
                    {"StrictMock(template=int)": ("str", StrictMock(template=int),)}
                )
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def fails_with_invalid_template(self):
            strict_mock = StrictMock(template=int)
            self.assert_fails(strict_mock, "arg2", kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_fails("arg1", strict_mock, kwarg1="kwarg1", kwarg2="kwarg2")
            self.assert_fails("arg1", "arg2", kwarg1=strict_mock, kwarg2="kwarg2")
            self.assert_fails("arg1", "arg2", kwarg1="kwarg1", kwarg2=strict_mock)
github facebookincubator / TestSlide / tests / lib_testslide.py View on Github external
def passes_for_mock_without_template(self):
        self.assert_passes(StrictMock())