def test_two_incompatible_unreified_templates(): r = Random(1) strat = strategy(Bitfields).flatmap(lambda x: integers_in_range(0, x)) x = some_template(strat, r) y = some_template(strat, r) assert x.source_template != y.source_template assert not strat.strictly_simpler(x, y) assert not strat.strictly_simpler(y, x)
def test_two_incompatible_unreified_templates(): r = Random(1) strat = basic(Bitfields).flatmap(lambda x: integers(0, x)) x = some_template(strat, r) y = some_template(strat, r) assert x.source_template != y.source_template assert not strat.strictly_simpler(x, y) assert not strat.strictly_simpler(y, x)
def test_lists_of_incompatible_sizes_are_checked(): s10 = lists(booleans(), min_size=10) s2 = lists(booleans(), max_size=9) x10 = s10.to_basic(some_template(s10)) x2 = s2.to_basic(some_template(s2)) with pytest.raises(BadData): s2.from_basic(x10) with pytest.raises(BadData): s10.from_basic(x2)
def test_validates_timezone_name_from_db(): s = datetimes(allow_naive=False) template = some_template(s) basic = s.to_basic(template) basic[-1] = u"Cabbage" with pytest.raises(BadData): s.from_basic(basic)
def test_can_safely_mix_simplifiers(): from hypothesis.searchstrategy.strings import OneCharStringStrategy from hypothesis.internal.debug import some_template s = OneCharStringStrategy() r = Random(1) t1 = some_template(s, r) while True: t2 = some_template(s, r) if t1 != t2: break for u in (t1, t2): for v in (t1, t2): for simplify in s.simplifiers(r, u): for w in simplify(r, v): assert not s.strictly_simpler(v, w)
def test_round_tripping_lists_via_the_database(spec): random = Random(hashlib.md5( (show(spec) + ':test_round_tripping_via_the_database').encode('utf-8') ).digest()) strat = lists(spec) template = some_template(strat, random) template_via_db = via_database(spec, strat, template) assert show(strat.reify(template)) == show(strat.reify(template_via_db))
def test_can_save_minimized_in_database(): spec = streaming(bool) t = some_template(spec) assert isinstance(t.stream[10], bool) s = t.with_value(10, not t.stream[10]) assert s != t sd = via_database(spec, s) assert s == sd
def test_can_still_simplify_if_not_reified(): strat = strategy(ConstantLists) random = Random(u'test_constant_lists_are_constant') template = some_template(strat, random) try: while True: template = next(strat.full_simplify(random, template)) except StopIteration: pass
def test_round_tripping_lists_via_the_database(spec): random = Random( hashlib.md5(( show(spec) + ':test_round_tripping_via_the_database').encode('utf-8')).digest()) strat = lists(spec) template = some_template(strat, random) template_via_db = via_database(spec, strat, template) assert show(strat.reify(template)) == show(strat.reify(template_via_db))
def test_can_recalculate_shrinks_without_reify_cache(): random = Random(u'test_can_recalculate_shrinks_without_reify_cache') strat = basic(Bitfields) template = some_template(strat, random) for shrunk_template in strat.full_simplify(random, template): strat.wrapped_strategy.reify_cache.pop(shrunk_template, None) strat.wrapped_strategy.reify_cache.pop(template, None) assert not (~strat.reify(template) & strat.reify(shrunk_template)) new_template = strat.from_basic(strat.to_basic(template)) assert strat.reify(template) == strat.reify(new_template)
def test_round_tripping_lists_via_the_database(spec): random = Random(hashlib.md5(( repr(spec) + u':test_round_tripping_via_the_database' ).encode(u'utf-8')).digest()) strat = lists(spec) template = some_template(strat, random) template_via_db = via_database(spec, strat, template) with BuildContext(): assert repr(strat.reify(template)) == repr( strat.reify(template_via_db))
def test_can_recalculate_shrinks_without_reify_cache(): random = Random('test_can_recalculate_shrinks_without_reify_cache') strat = basic(Bitfields) template = some_template(strat, random) for shrunk_template in strat.full_simplify(random, template): strat.reify_cache.pop(shrunk_template, None) strat.reify_cache.pop(template, None) assert not (~strat.reify(template) & strat.reify(shrunk_template)) new_template = strat.from_basic(strat.to_basic(template)) assert strat.reify(template) == strat.reify(new_template)
def test_template_equality(): t = some_template(streaming(booleans())) t2 = StreamTemplate(t.seed, t.parameter_seed, Stream(t.stream)) while True: t3 = some_template(streaming(booleans())) if t3.seed != t.seed: break assert t == t2 assert t != t3 assert t != 1 v = t.stream[11] t4 = t2.with_value(11, not v) assert t4 != t t5 = StreamTemplate(t.seed, t.parameter_seed + 1, Stream(t.stream)) assert t2 != t5 assert len(set((t, t2, t3, t4, t5))) == 4
def test_round_tripping_via_the_database(spec): random = Random( hashlib.md5((show(spec) + u':test_round_tripping_via_the_database' ).encode(u'utf-8')).digest()) strat = spec template = some_template(strat, random) strat.from_basic(strat.to_basic(template)) template_via_db = via_database(spec, strat, template) with BuildContext(): assert show(strat.reify(template)) == show( strat.reify(template_via_db))
def test_round_tripping_via_the_database(spec): random = Random(hashlib.md5(( show(spec) + u':test_round_tripping_via_the_database' ).encode(u'utf-8')).digest()) strat = strategy(spec) template = some_template(strat, random) strat.from_basic(strat.to_basic(template)) template_via_db = via_database(spec, strat, template) with BuildContext(): assert show(strat.reify(template)) == show( strat.reify(template_via_db))
def test_simplifying_results_in_strictly_simpler(): random = Random(u'test_simplifying_results_in_strictly_simpler') strat = basic(Bitfields) template = some_template(strat, random) for shrunk_template in strat.full_simplify(random, template): assert strat.strictly_simpler(shrunk_template, template)
def test_simplifying_results_in_strictly_simpler(): random = Random('test_simplifying_results_in_strictly_simpler') strat = basic(Bitfields) template = some_template(strat, random) for shrunk_template in strat.full_simplify(random, template): assert strat.strictly_simpler(shrunk_template, template)