How to use the icontract._checkers 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 / icontract / _decorators.py View on Github external
def __call__(self, func: CallableT) -> CallableT:
        """
        Add the snapshot to the list of snapshots of the function ``func``.

        The function ``func`` is expected to be decorated with at least one postcondition before the snapshot.

        :param func: function whose arguments we need to snapshot
        :return: ``func`` as given in the input
        """
        if not self.enabled:
            return func

        # Find a contract checker
        contract_checker = icontract._checkers.find_checker(func=func)

        if contract_checker is None:
            raise ValueError("You are decorating a function with a snapshot, but no postcondition was defined "
                             "on the function before.")

        assert self._snapshot is not None, "Expected the enabled snapshot to have the property ``snapshot`` set."

        # Add the snapshot to the list of snapshots stored at the checker
        assert hasattr(contract_checker, "__postcondition_snapshots__")

        snapshots = getattr(contract_checker, "__postcondition_snapshots__")
        assert isinstance(snapshots, list)

        for snap in snapshots:
            assert isinstance(snap, Snapshot)
            if snap.name == self._snapshot.name:
github Parquery / icontract / icontract / _metaclass.py View on Github external
def __new__(mlcs, name, bases, namespace):  # type: ignore
            """Create a class with inherited preconditions, postconditions and invariants."""
            _dbc_decorate_namespace(bases, namespace)

            cls = super().__new__(mlcs, name, bases, namespace)

            if hasattr(cls, "__invariants__"):
                icontract._checkers.add_invariant_checks(cls=cls)

            return cls
    else: