How to use the hypothesis.strategies.none 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 gemalto / pycryptoki / tests / unittests / test_attributes.py View on Github external
            keys=integers(min_value=1, max_value=MAX_INT), values=none(), dict_class=Attributes
        )
    )
    def test_null_dictionary(self, test_dic):
        """
        Test creation of Attributes class.
        :param test_dic: Dictionary of random size, w/ all elements = None
        """
        res = test_dic.get_c_struct()
        for attr in res:
            assert attr.pValue is None
            assert attr.usValueLen == 0

        # Back to python dictionary
        py_dic = c_struct_to_python(res)
        assert test_dic == py_dic
github PromyLOPh / crocoite / crocoite / test_browser.py View on Github external
def chromeResponseReceived (reqid, url):
    mimeTypeSt = st.one_of (st.none (), st.just ('text/html'))
    remoteIpAddressSt = st.one_of (st.none (), st.just ('127.0.0.1'))
    protocolSt = st.one_of (st.none (), st.just ('h2'))
    statusCodeSt = st.integers (min_value=100, max_value=999)
    typeSt = st.sampled_from (['Document', 'Stylesheet', 'Image', 'Media',
            'Font', 'Script', 'TextTrack', 'XHR', 'Fetch', 'EventSource',
            'WebSocket', 'Manifest', 'SignedExchange', 'Ping',
            'CSPViolationReport', 'Other'])
    return st.fixed_dictionaries ({
            'requestId': reqid,
            'timestamp': timestamp,
            'type': typeSt,
            'response': st.fixed_dictionaries ({
                'url': url,
                'requestHeaders': chromeHeaders (), # XXX: make this optional
                'headers': chromeHeaders (),
                'status': statusCodeSt,
                'statusText': asciiText,
github JarryShaw / f2format / vendor / pypy / extra_tests / test_json.py View on Github external
assert is_(json.dumps(u"\u1234", ensure_ascii=False), u'"\u1234"')
    assert is_(json.dumps("\xc0", ensure_ascii=False), '"\xc0"')
    with pytest.raises(UnicodeDecodeError) as excinfo:
        json.dumps((u"\u1234", "\xc0"), ensure_ascii=False)
    assert str(excinfo.value).startswith(
        "'ascii' codec can't decode byte 0xc0 ")
    with pytest.raises(UnicodeDecodeError) as excinfo:
        json.dumps(("\xc0", u"\u1234"), ensure_ascii=False)
    assert str(excinfo.value).startswith(
        "'ascii' codec can't decode byte 0xc0 ")

def test_issue2191():
    assert is_(json.dumps(u"xxx", ensure_ascii=False), u'"xxx"')

jsondata = strategies.recursive(
    strategies.none() |
    strategies.booleans() |
    strategies.floats(allow_nan=False) |
    strategies.text(),
    lambda children: strategies.lists(children) |
        strategies.dictionaries(strategies.text(), children))

@given(jsondata)
def test_roundtrip(d):
    assert json.loads(json.dumps(d)) == d

def test_skipkeys():
    assert json.dumps({Ellipsis: 42}, skipkeys=True) == '{}'
    assert json.dumps({Ellipsis: 42, 3: 4}, skipkeys=True) == '{"3": 4}'
    assert json.dumps({3: 4, Ellipsis: 42}, skipkeys=True) == '{"3": 4}'
    assert json.dumps({Ellipsis: 42, NotImplemented: 43}, skipkeys=True) \
                 == '{}'
github HypothesisWorks / hypothesis / tests / cover / test_numerics.py View on Github external
def test_fuzz_decimals_bounds(data):
    places = data.draw(none() | integers(0, 20), label='places')
    finite_decs = decimals(allow_nan=False, allow_infinity=False,
                           places=places) | none()
    low, high = data.draw(tuples(finite_decs, finite_decs), label='low, high')
    if low is not None and high is not None and low > high:
        low, high = high, low
    ctx = decimal.Context(prec=data.draw(integers(1, 100), label='precision'))
    try:
        with decimal.localcontext(ctx):
            strat = decimals(low, high, allow_nan=False,
                             allow_infinity=False, places=places)
            val = data.draw(strat, label='value')
    except InvalidArgument:
        reject()  # decimals too close for given places
    if low is not None:
        assert low <= val
    if high is not None:
github gemalto / pycryptoki / tests / unittests / test_attributes.py View on Github external
            values=one_of(just(1), none()),
        )
    )
    def test_rand_dictionary(self, test_dic):
        """
        Test creation of Attributes class.
        :param test_dic: Dictionary of random size, elements = 1 or None
        """
        # Iterate through dictionary and store keys w/ value = 1
        l = [key for key in test_dic if test_dic[key] == 1]

        res = test_dic.get_c_struct()
        for attr in res:
            if attr.type in l:
                assert attr.pValue == 1
                assert attr.usValueLen == 1
            else:
github HypothesisWorks / hypothesis / tests / pandas / test_argument_validation.py View on Github external
import hypothesis.extra.pandas as pdst
from tests.common.arguments import e, argument_validation_test

BAD_ARGS = [
    e(pdst.data_frames),
    e(pdst.data_frames, pdst.columns(1, dtype='not a dtype')),
    e(pdst.data_frames, pdst.columns(1, elements='not a strategy')),
    e(pdst.data_frames, pdst.columns([[]])),
    e(pdst.data_frames, [], index=[]),
    e(pdst.data_frames, [], rows=st.fixed_dictionaries({'A': st.just(1)})),
    e(pdst.data_frames, pdst.columns(1)),
    e(pdst.data_frames, pdst.columns(1, dtype=float, fill=1)),
    e(pdst.data_frames, pdst.columns(1, dtype=float, elements=1)),
    e(pdst.data_frames, pdst.columns(1, fill=1, dtype=float)),
    e(pdst.data_frames, pdst.columns(['A', 'A'], dtype=float)),
    e(pdst.data_frames, pdst.columns(1, elements=st.none(), dtype=int)),
    e(pdst.data_frames, 1),
    e(pdst.data_frames, [1]),
    e(pdst.data_frames, pdst.columns(1, dtype='category')),
    e(pdst.data_frames,
        pdst.columns(['A'], dtype=bool),
        rows=st.tuples(st.booleans(), st.booleans())),
    e(pdst.data_frames,
        pdst.columns(1, elements=st.booleans()),
        rows=st.tuples(st.booleans())),
    e(pdst.data_frames, rows=st.integers(), index=pdst.range_indexes(0, 0)),
    e(pdst.data_frames, rows=st.integers(), index=pdst.range_indexes(1, 1)),
    e(pdst.data_frames, pdst.columns(1, dtype=int), rows=st.integers()),
    e(pdst.indexes),
    e(pdst.indexes, dtype='category'),
    e(pdst.indexes, dtype='not a dtype'),
    e(pdst.indexes, elements='not a strategy'),
github suned / pfun / tests / test_monoid.py View on Github external
@given(none(), none())
def test_none(n1, n2):
    assert empty(n1) is None
    assert append(n1, None) is None
    assert append(None, n1) is None
    assert append(n1, n2) is None
    assert append(n2, n1) is None
github lycantropos / hypothesis_sqlalchemy / hypothesis_sqlalchemy / columnar / base.py View on Github external
def factory(dialect: Dialect,
            *,
            names: Optional[Strategy[str]] = None,
            types: Optional[Strategy[_types.TypeOrInstance]] = None,
            are_unique: Strategy[Optional[bool]] = strategies.none(),
            are_primary_keys: Strategy[Optional[bool]] = strategies.none(),
            are_auto_incremented: Strategy[Optional[bool]] = strategies.none(),
            are_nullable: Strategy[Optional[bool]] = strategies.booleans(),
            are_indexed: Strategy[Optional[bool]] = strategies.booleans()
            ) -> Strategy[Column]:
    names = to_sql_identifiers(dialect) if names is None else names
    types = _types.factory(dialect) if types is None else types
    return strategies.builds(Column,
                             name=names,
                             type_=types,
                             autoincrement=are_auto_incremented,
                             unique=are_unique,
                             nullable=are_nullable,
                             primary_key=are_primary_keys,
                             index=are_indexed)
github lycantropos / hypothesis_sqlalchemy / hypothesis_sqlalchemy / columnar / records.py View on Github external
def to_plain_values_strategy(column: Column) -> Strategy[Any]:
        result = values.factory(column)
        if column.nullable:
            # putting simpler strategies first
            # more info at
            # https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.one_of
            result = strategies.none() | result
        return result
github remorses / skema / skema / fake_data / fake_data.py View on Github external
def gen_json_values():
    return (
        gen_string({})
        | hs.booleans()
        | gen_int({})
        | hs.none()
        | hs.floats(allow_nan=False, allow_infinity=False)
    )