How to use the hypothesis.assume function in hypothesis

To help you get started, we’ve selected a few hypothesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rocky / python-decompile3 / pytest / test_fstring.py View on Github external
def run_test(text):
    hypothesis.assume(len(text))
    hypothesis.assume("f'{" in text)
    expr = text + "\n"
    code = compile(expr, "", "single")
    deparsed = code_deparse(code, sys.stdout, PYTHON_VERSION, compile_mode="single")
    recompiled = compile(deparsed.text, "", "single")
    if recompiled != code:
        print(recompiled)
        print("================")
        print(code)
        print("----------------")
        assert (
            "dis(" + deparsed.text.strip("\n") + ")" == "dis(" + expr.strip("\n") + ")"
        )
github cog-imperial / suspect / tests / test_monotonicity_propagation.py View on Github external
def nonnegative_sin_bounds(draw):
    start = draw(st.floats(
        min_value=0.1*pi,
        max_value=0.9*pi,
        allow_nan=False,
        allow_infinity=False,
    ))
    end = draw(st.floats(
        min_value=0,
        max_value=0.9*pi-start,
        allow_nan=False,
        allow_infinity=False,
    ))
    mul = draw(st.integers(min_value=-100, max_value=100)) * 2 * pi
    b = Interval(start + mul, start + end + mul)
    assume(b.size() > 0)
    return b
github Zac-HD / hypothesis-jsonschema / tests / test_canonicalise.py View on Github external
def test_canonicalises_to_equivalent_fixpoint(schema_strategy, data):
    """Check that an object drawn from an arbitrary schema is valid."""
    schema = data.draw(schema_strategy, label="schema")
    cc = canonicalish(schema)
    assert cc == canonicalish(cc)
    try:
        strat = from_schema(cc)
    except InvalidArgument:
        # e.g. array of unique {type: integers}, with too few allowed integers
        assume(False)
    instance = data.draw(JSON_STRATEGY | strat, label="instance")
    assert is_valid(instance, schema) == is_valid(instance, cc)
    jsonschema.validators.validator_for(schema).check_schema(schema)
github PTB-PSt1 / PyDynamic / test / test_interpolation.py View on Github external
else:
        # In case we want to extrapolate, draw some fill values for the
        # out-of-bounds range. Those will be either single floats or a 2-tuple of
        # floats or the special value "extrapolate".
        fill_value = draw_fill_values(restrict_fill_value)
        fill_unc = draw_fill_values(restrict_fill_unc)
        bounds_error = False

    # Draw interpolation timestamps (or frequencies).
    t_new = draw(hnp.arrays(**strategy_params))

    if extrapolate:
        # In case we want to extrapolate, make sure we actually do after having drawn
        # the timestamps (or frequencies) not to randomly have drawn values inside
        # original bounds and if even more constraints are given ensure those.
        assume(np.min(t_new) < np.min(t) or np.max(t_new) > np.max(t))
        if extrapolate == "above":
            assume(np.max(t_new) > np.max(t))
        else:
            assume(np.min(t_new) < np.min(t))

    kind = draw(st.sampled_from(kind_tuple))
    assume_sorted = sorted_timestamps
    return {
        "t_new": t_new,
        "t": t,
        "y": y,
        "uy": uy,
        "kind": kind,
        "fill_value": fill_value,
        "fill_unc": fill_unc,
        "bounds_error": bounds_error,
github buguroo / pyknow / tests / unit / test_fact_matching.py View on Github external
def test_match_with_FactState_DEFINED_False(kwargs):
    assume('something' not in kwargs)

    from pyknow.fact import Fact, W

    f0 = Fact(**{a: L(b) for a, b in kwargs.items()})
    f1 = Fact(something=W(True))

    assert f0 not in f1
github bankroll-py / bankroll / tests / test_model.py View on Github external
def test_quoteEquality(self, currency: Currency, bid: Optional[Decimal],
                           ask: Optional[Decimal], last: Optional[Decimal],
                           close: Optional[Decimal]) -> None:
        assume((not bid) or (not ask) or (ask > bid))

        cashBid = Cash(currency=currency, quantity=bid) if bid else None
        cashAsk = Cash(currency=currency, quantity=ask) if ask else None
        cashLast = Cash(currency=currency, quantity=last) if last else None
        cashClose = Cash(currency=currency, quantity=close) if close else None

        a = Quote(cashBid, cashAsk, cashLast, cashClose)
        b = Quote(cashBid, cashAsk, cashLast, cashClose)
        self.assertEqual(a, b)
        self.assertEqual(hash(a), hash(b))
github ericmjl / nxviz / tests / test_polcart.py View on Github external
def test_to_proper_degrees(theta):
    assume(np.isfinite(theta))
    theta = to_proper_degrees(theta)
    assert theta <= 180 and theta >= -180
github HypothesisWorks / hypothesis / tests / nocover / test_floating.py View on Github external
def test_negation_is_self_inverse(x):
    assume(not math.isnan(x))
    y = -x
    assert -y == x
github nanograv / PINT / tests / test_precision.py View on Github external
def test_time_from_mjd_string_accuracy_vs_longdouble(format, i_f):
    i, f = i_f
    mjd = np.longdouble(i) + np.longdouble(f)
    assume(
        not (format == "pulsar_mjd" and i in leap_sec_days and (1 - f) * 86400 < 1e-9)
    )
    s = str(mjd)
    t = Time(val=i, val2=f, format=format, scale="utc")
    assert (
        abs(time_from_mjd_string(s, format=format, scale="utc") - t).to(u.us) < 1 * u.us
    )
    if 40000 <= i <= 60000:
        assert (
            abs(time_from_mjd_string(s, format=format, scale="utc") - t).to(u.us)
            < 1 * u.ns
        )
github lejar / traitlite / tests / test_traits.py View on Github external
def test_typechecking_same_types(self, type_1):
        """Test that the type checking works correctly with subclasses."""
        # Booleans are the only non-subclassable objects in python.
        hypothesis.assume(type_1 != bool)

        class Foo:
            a = traits.TypeChecked(type_1)
        foo = Foo()

        # The same type as specified is okay.
        foo.a = type_1()

        # Create a subclass of the type, which should be okay.
        NewType = type('NewType', (type_1,), {})
        foo.a = NewType()

        # A sub-subclass should also be okay.
        NewestType = type('NewestType', (NewType,), {})
        foo.a = NewestType()