def test_slow_failing_test_1(x): time.sleep(0.05) assert not calls[0] calls[0] = 1 @fails @given(int, verifier_settings=timeout_settings) def test_slow_failing_test_2(x): time.sleep(0.05) assert not calls[1] calls[1] = 1 @fails @given(int, verifier=Verifier(settings=timeout_settings)) def test_slow_failing_test_3(x): time.sleep(0.05) assert not calls[2] calls[2] = 1 @fails @given(int, verifier=Verifier(settings=timeout_settings)) def test_slow_failing_test_4(x): time.sleep(0.05) assert not calls[3] calls[3] = 1 @fails
from hypothesis import Verifier import hypothesis.settings as hs from hypothesis.strategytable import StrategyTable import hypothesis.searchstrategy as strat settings = hs.Settings(max_examples=100, timeout=4) small_table = StrategyTable() small_table.define_specification_for_instances( list, lambda strategies, descriptor: strat.ListStrategy( list(map(strategies.strategy, descriptor)), average_length=2.0 ) ) small_verifier = Verifier( settings=settings, strategy_table=small_table, )
def test_can_verify_a_non_serializale_type(): verifier = Verifier(settings=hs.Settings(database=ExampleDatabase())) verifier.falsify(lambda x: len(x) > 0, Awkward)
def test_a_verifier_can_still_do_its_thing_if_a_saved_example_fails(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database)) verifier.falsify(lambda x: x < 11, int) verifier2 = Verifier(settings=hs.Settings(database=database)) verifier2.falsify(lambda x: x < 100, int)
def test_a_verifier_saves_any_failing_examples_in_its_database(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database)) counterexample = verifier.falsify(lambda x: x > 0, int) saved = list(database.storage_for((int,)).fetch()) assert saved == [counterexample]
(SQLiteBackend, None), (InMemoryBackend, ObjectFormat()), ) @pytest.mark.parametrize(('descriptor', 'value', 'backend', 'format'), [ dv + bf for dv in data_examples for bf in backend_format_pairs ]) def test_simple_example_set(descriptor, value, backend, format): run_round_trip(descriptor, value, backend=backend, format=format) @given(DescriptorWithValue, verifier=Verifier( strategy_table=small_table, settings=hs.Settings(max_examples=500), )) def test_can_round_trip_a_single_value_through_the_database(dav): run_round_trip(dav.descriptor, dav.value) def test_errors_if_given_incompatible_format_and_backend(): with pytest.raises(ValueError): ExampleDatabase( backend=InMemoryBackend() ) def test_a_verifier_saves_any_failing_examples_in_its_database(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database))
False: set() }), ((int, int), (1, )), (Just(value=set()), frozenset()), (SampledFrom((-30, 1)), True), ]) def test_simple_conversions(descriptor, value): converter = ConverterTable.default().specification_for(descriptor) with pytest.raises(WrongFormat): converter.to_basic(value) @given(DescriptorWithValue, DescriptorWithValue, verifier=Verifier( strategy_table=small_table, settings=hs.Settings(max_examples=500), )) def test_can_not_save_as_incompatible_examples(dav, dav2): strategy = small_table.strategy(dav.descriptor) assume(not strategy.could_have_produced(dav2.value)) ft = ConverterTable.default() try: converter = ft.specification_for(dav.descriptor) except NotSerializeable: assume(False) with pytest.raises(WrongFormat): converter.to_basic(dav2.value) @pytest.mark.parametrize(('descriptor', 'data'), [