Exemple #1
0
def use_signature_examples(func):
    for sig in [
        "(),()->()",
        "(i)->()",
        "(i),(i)->()",
        "(m,n),(n,p)->(m,p)",
        "(n),(n,p)->(p)",
        "(m,n),(n)->(m)",
        "(m?,n),(n,p?)->(m?,p?)",
        "(3),(3)->(3)",
    ]:
        func = example(sig)(func)
    return func
assert not reusable.is_empty


@example(st.integers(min_value=1))
@given(reusable)
def test_reusable_strategies_are_all_reusable(s):
    try:
        s.validate()
    except InvalidArgument:
        reject()

    assert s.has_reusable_values


for s in base_reusable_strategies:
    test_reusable_strategies_are_all_reusable = example(s)(
        test_reusable_strategies_are_all_reusable)
    test_reusable_strategies_are_all_reusable = example(
        st.tuples(s))(test_reusable_strategies_are_all_reusable)


def test_composing_breaks_reusability():
    s = st.integers()
    assert s.has_reusable_values
    assert not s.filter(lambda x: True).has_reusable_values
    assert not s.map(lambda x: x).has_reusable_values
    assert not s.flatmap(lambda x: st.just(x)).has_reusable_values


@pytest.mark.parametrize('strat', [
    st.lists(st.booleans()),
    st.sets(st.booleans()),
def test_no_args_and_kwargs():
    with pytest.raises(InvalidArgument):
        example(1, y=2)
def test_no_empty_examples():
    with pytest.raises(InvalidArgument):
        example()
def test_no_args_and_kwargs():
    with pytest.raises(InvalidArgument):
        example(1, y=2)
def test_no_empty_examples():
    with pytest.raises(InvalidArgument):
        example()
@hypothesis.given(shim_zone=SHIM_ZONE_STRATEGY, dt=dt_strategy)
@hypothesis.example(shim_zone=pds.timezone("America/New_York"),
                    dt=datetime(2020, 11, 1, 1, 30))
@hypothesis.example(
    shim_zone=no_cache_timezone("America/New_York"),
    dt=datetime(2020, 11, 1, 1, 30),
)
@hypothesis.example(
    shim_zone=pds.timezone("America/New_York"),
    dt=enfold(datetime(2020, 11, 1, 1, 30), fold=1),
)
@conditional_examples(
    not PY2,
    examples=[
        hypothesis.example(
            shim_zone=no_cache_timezone("America/New_York"),
            dt=datetime(2020, 3, 8, 2, 30),
        ),
        hypothesis.example(
            shim_zone=no_cache_timezone("America/New_York"),
            dt=enfold(datetime(2020, 3, 8, 2, 30), fold=1),
        ),
    ],
)
def test_pickle_round_trip(shim_zone, dt):
    """Test that the results of a pickle round trip are identical to inputs.

    Ideally we would want some metric of equality on the pickled objects
    themselves, but with time zones object equality is usually equivalent to
    object identity, and that is not universally preserved in pickle round
    tripping on all Python versions and for all zones.
    """
Exemple #8
0
)
@hypothesis.example(
    dt=enfold(datetime(2010, 11, 7, 1, 30), fold=1),
    key="America/New_York",
    is_dst=False,
)
@hypothesis.example(dt=datetime(2010, 11, 7, 1, 30),
                    key="America/New_York",
                    is_dst=True)
@hypothesis.example(dt=datetime(2010, 11, 7, 1, 30),
                    key="America/New_York",
                    is_dst=False)
@conditional_examples(
    not PY2,
    [
        hypothesis.example(
            dt=datetime(2009, 3, 29, 2), key="Europe/Amsterdam", is_dst=True),
        hypothesis.example(
            dt=enfold(datetime(1933, 1, 1), fold=0),
            key="Asia/Kuching",
            is_dst=True,
        ),
        hypothesis.example(
            dt=enfold(datetime(1933, 1, 1), fold=1),
            key="Asia/Kuching",
            is_dst=True,
        ),
        hypothesis.example(
            dt=enfold(datetime(1933, 1, 1), fold=0),
            key="Asia/Kuching",
            is_dst=False,
        ),
 def add_examples(func):
     for example in examples:
         func = hypothesis.example(example)(func)
     return func
Exemple #10
0
    ('NFD', 'NFD', 'NFD'),
    ('NFD', 'NFKC', 'NFKC'),
    ('NFD', 'NFKD', 'NFKD'),
    ('NFKC', 'NFC', 'NFKC'),
    ('NFKC', 'NFD', 'NFKD'),
    ('NFKC', 'NFKC', 'NFKC'),
    ('NFKC', 'NFKD', 'NFKD'),
    ('NFKD', 'NFC', 'NFKC'),
    ('NFKD', 'NFD', 'NFKD'),
    ('NFKD', 'NFKC', 'NFKC'),
    ('NFKD', 'NFKD', 'NFKD'),
]


@pytest.mark.parametrize('NF1, NF2, NF3', compositions)
@example(s=u'---\uafb8\u11a7---')  # issue 2289
@settings(max_examples=1000)
@given(s=st.text())
def test_composition(s, space, NF1, NF2, NF3):
    # 'chr(0xfacf) normalizes to chr(0x2284a), which is too big')
    assume(not (s == u'\ufacf' and sys.maxunicode == 65535))
    norm1, norm2, norm3 = [
        make_normalization(space, form) for form in [NF1, NF2, NF3]
    ]
    assert norm2(norm1(s)) == norm3(s)


if sys.maxunicode != 65535:
    # conditionally generate the example via an unwrapped decorator
    test_composition = example(s=u'\ufacf')(test_composition)
Exemple #11
0
 def examples_decorator(f):
     g = f
     for arg in args:
         g = example(arg)(g)
     return g

@example(st.integers(min_value=1))
@given(reusable)
def test_reusable_strategies_are_all_reusable(s):
    try:
        s.validate()
    except InvalidArgument:
        reject()

    assert s.has_reusable_values


for s in base_reusable_strategies:
    test_reusable_strategies_are_all_reusable = example(s)(
        test_reusable_strategies_are_all_reusable
    )
    test_reusable_strategies_are_all_reusable = example(st.tuples(s))(
        test_reusable_strategies_are_all_reusable
    )


def test_composing_breaks_reusability():
    s = st.integers()
    assert s.has_reusable_values
    assert not s.filter(lambda x: True).has_reusable_values
    assert not s.map(lambda x: x).has_reusable_values
    assert not s.flatmap(lambda x: st.just(x)).has_reusable_values


@pytest.mark.parametrize('strat', [
def hypothesis_and_examples(func):
    func = given(strategies.lists(strategies.integers(-2**15,
                                                      2**15 - 1)))(func)
    for ex in examples:
        func = example(ex)(func)
    return func
Exemple #14
0
def test_stop_silently_dropping_examples_when_decorator_is_applied_to_itself():
    def f():
        pass

    test = example("outer")(example("inner"))(f)
    assert len(test.hypothesis_explicit_examples) == 2
Exemple #15
0
 def accept(f):
     for e in examples:
         f = example(e)(f)
     return f