Skip to content

Commit

Permalink
Cover better make_assume_preconditions (#59)
Browse files Browse the repository at this point in the history
This patch adds additional tests to increate the test coverage of
`make_assume_preconditions` function.
  • Loading branch information
mristin authored Jul 8, 2021
1 parent a69f6f5 commit f5974a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion icontract_hypothesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def make_assume_preconditions(func: CallableT) -> Callable[..., None]:
return _assume_preconditions_always_satisfied

preconditions = getattr(checker, "__preconditions__", None)
if preconditions is None:
if preconditions is None or len(preconditions) == 0:
return _assume_preconditions_always_satisfied

sign = inspect.signature(func)
Expand Down
21 changes: 20 additions & 1 deletion tests/test_assume.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def some_func(x: int) -> None:

self.assertIsNotNone(unsatisfied_assumption)

def test_without_preconditions(self) -> None:
def test_without_contracts(self) -> None:
recorded_inputs = [] # type: List[Any]

def some_func(x: int) -> None:
Expand Down Expand Up @@ -103,6 +103,25 @@ def execute(x: int) -> None:

self.assertSetEqual({3}, set(recorded_inputs))

def test_with_only_postconditions(self) -> None:
recorded_inputs = [] # type: List[Any]

@icontract.ensure(lambda result: result > 0)
def some_func(x: int) -> int:
recorded_inputs.append(x)
return 1

assume_preconditions = icontract_hypothesis.make_assume_preconditions(some_func)

@hypothesis.given(x=hypothesis.strategies.integers())
def execute(x: int) -> None:
assume_preconditions(x)
some_func(x)

execute()

self.assertGreater(len(recorded_inputs), 10)


class TestAssumeWeakenedPreconditions(unittest.TestCase):
def test_with_a_single_precondition(self) -> None:
Expand Down

0 comments on commit f5974a5

Please sign in to comment.