Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_additional_invariant_violated_in_childs_init(self) -> None:
@icontract.invariant(lambda self: self.x > 0)
class A(icontract.DBC):
def __init__(self) -> None:
self.x = 10
def __repr__(self) -> str:
return "instance of A"
@icontract.invariant(lambda self: self.x > 100)
class B(A):
def __repr__(self) -> str:
return "instance of B"
violation_error = None # type: Optional[icontract.ViolationError]
try:
_ = B()
except icontract.ViolationError as err:
violation_error = err
@icontract.require(lambda x: x % 2 == 0)
def func(self, x: int) -> None:
pass
@icontract.ensure(lambda result: all(single_res[1].is_absolute() for single_res in result))
def some_func() -> List[Tuple[pathlib.Path, pathlib.Path]]:
return [(pathlib.Path("/home/file1"), pathlib.Path("home/file2"))]
@icontract.ensure(lambda result: result < 100)
def func(self) -> int:
return 1000
@icontract.ensure(lambda self: self.some_prop > 0)
def some_prop(self) -> None:
pass
@icontract.ensure(lambda result: result > 0)
def some_method(self) -> int:
self.x = -1
return 10
@icontract.ensure(lambda OLD, val, lst: OLD.len_lst + 1 == len(lst))
def some_func(lst: List[int], val: int) -> None:
lst.append(val)
lst.append(1984)
@icontract.ensure(lambda OLD, self, val: OLD.lst + [val] == self.lst)
def some_func(self, val: int) -> None:
self.lst.append(val)
self.lst.append(1984)
@icontract.ensure(lambda result, x: result > x, "expected summation")
def some_func(x: int, y: int = 5) -> int:
return x - y
@icontract.ensure(lambda result: result % 3 == 0)
def func(self) -> int:
return 2