How to use the icontract.pre function in icontract

To help you get started, we’ve selected a few icontract 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 Parquery / icontract / tests / test_icontract.py View on Github external
        @icontract.pre(lambda b: b > 3)
        def some_function(a: int) -> None:  # pylint: disable=unused-variable
            pass
github Parquery / icontract / tests / test_icontract.py View on Github external
        @icontract.pre(lambda x: x > 3, enabled=False)
        def pow_with_pre(x: int, y: int) -> int:
            return x**y
github Parquery / icontract / tests / test_icontract.py View on Github external
            @icontract.pre(lambda self: self._some_prop > 0)
            def some_prop(self) -> int:
                return self._some_prop
github Parquery / icontract / tests / test_icontract.py View on Github external
            @icontract.pre(lambda x: x > 3, repr_args=lambda z: "z was {:X}".format(z))
            def some_func(x: int, y: int = 5) -> None:
                pass
        except ValueError as err:
github Parquery / icontract / tests / test_icontract.py View on Github external
            @icontract.pre(lambda x: x > 3)
            def some_method(self, x: int) -> int:
                return self.y
github Parquery / icontract / tests / test_icontract.py View on Github external
            @icontract.pre(lambda self: self.y > 10, repr_args=lambda self: "self.y was {}".format(self.y))
            def some_method_with_self(self) -> None:
                pass
github Parquery / icontract / tests / test_icontract.py View on Github external
        @icontract.pre(lambda x: x > 3, "x must not be small")
        def some_func(x: int, y: int = 5) -> None:
            pass
github Parquery / icontract / tests / test_icontract.py View on Github external
        @icontract.pre(lambda x: x > 3)
        def pow_with_pre(x: int, y: int) -> int:
            return x**y
github Parquery / icontract / tests / test_icontract.py View on Github external
            @icontract.pre(lambda x: x % 2 == 0)
            def func(self, x: int) -> None:
                pass
github Parquery / icontract / tests / test_icontract.py View on Github external
        @icontract.pre(lambda x: x > 0, error=lambda x, y: ValueError("x is {}, y is {}".format(x, y)))
        def some_func(x: int, y: int) -> int:
            return 0