コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
ファイル: test_datetime.py プロジェクト: tokenrove/hypothesis
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)
コード例 #6
0
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)
コード例 #7
0
ファイル: test_datetime.py プロジェクト: GMadorell/hypothesis
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)
コード例 #8
0
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)
コード例 #9
0
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))
コード例 #10
0
ファイル: test_streams.py プロジェクト: itkovian/hypothesis
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
コード例 #11
0
ファイル: test_flatmap.py プロジェクト: trowt/hypothesis
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
コード例 #12
0
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))
コード例 #13
0
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
コード例 #14
0
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)
コード例 #15
0
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))
コード例 #16
0
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)
コード例 #17
0
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
コード例 #18
0
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
コード例 #19
0
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))
コード例 #20
0
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))
コード例 #21
0
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)
コード例 #22
0
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)