From fe6c12a7395807d78880c2bbead48580fe8a1cff Mon Sep 17 00:00:00 2001 From: Marko Ristin Date: Fri, 9 Jul 2021 02:06:21 +0200 Subject: [PATCH] Test strategy inference with only post-conditions (#62) This patch adds a test case which tests that the strategy is correctly inferred if only the post-conditions are specified. --- tests/strategy_inference/test_strategy_inference.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/strategy_inference/test_strategy_inference.py b/tests/strategy_inference/test_strategy_inference.py index 9aba61a..fd2edd9 100644 --- a/tests/strategy_inference/test_strategy_inference.py +++ b/tests/strategy_inference/test_strategy_inference.py @@ -50,7 +50,7 @@ def some_func(x) -> None: # type: ignore str(type_error), ) - def test_without_preconditions(self) -> None: + def test_without_contracts(self) -> None: def some_func(x: int) -> None: pass @@ -59,6 +59,16 @@ def some_func(x: int) -> None: icontract_hypothesis.test_with_inferred_strategy(some_func) + def test_with_only_preconditions(self) -> None: + @icontract.ensure(lambda result: result > 0) + def some_func(x: int) -> int: + return 1 + + strategy = icontract_hypothesis.infer_strategy(some_func) + self.assertEqual("fixed_dictionaries({'x': integers()})", str(strategy)) + + icontract_hypothesis.test_with_inferred_strategy(some_func) + def test_unmatched_pattern(self) -> None: @icontract.require(lambda x: x > 0 and x > math.sqrt(x)) def some_func(x: float) -> None: