How to use the hypothesis.strategies.booleans 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 stephen-bunn / bethesda-structs / tests / test_subrecord_collection.py View on Github external
    booleans(),
    booleans(),
)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_invalid_items(name, items, optional, multiple):
    if isinstance(items, list) and len(items) <= 0:
        with pytest.raises(ValueError):
            SubrecordCollection(name, items, optional, multiple)
    else:
        with pytest.raises(TypeError):
            SubrecordCollection(name, items, optional, multiple)
github HypothesisWorks / hypothesis / tests / cover / test_example.py View on Github external
def test_example_inside_strategy():
    st.booleans().map(lambda x: st.integers().example()).example()
github FuelRats / pipsqueak3 / tests / strategies.py View on Github external
"""
_irc_nick_letters = strategies.characters(
    whitelist_characters=f"{string.ascii_letters}{string.digits}" + r"\`_[]{}",
    whitelist_categories=())
valid_irc_name = strategies.text(alphabet=_irc_nick_letters, min_size=3).filter(
    lambda word: not word[0].isnumeric())
platform = strategies.sampled_from([_Platforms.PS, _Platforms.PC, _Platforms.XB])
""" Some platform """
rescue = strategies.builds(
    _Rescue,
    uuid=strategies.uuids(version=4),  # generate some valid uuid4
    client=valid_irc_name,  # client should always be defined
    # irc nickname may be any valid word, or None.
    irc_nickname=strategies.one_of(valid_irc_name, strategies.none()),
    platform=platform,
    active=strategies.booleans(),
    code_red=strategies.booleans(),
    board_index=strategies.one_of(strategies.integers(min_value=1), strategies.none())
)
""" Strategy for generating a rescue. Shrinks towards smaller arguments """


def rescues(min_size: int, max_size: int):
    """ builds a list of rescues, shrinks towards smaller lists and smaller rescues """
    return strategies.lists(rescue, min_size=min_size, max_size=max_size,
                            unique_by=(
                                lambda case: case.irc_nickname, lambda case: case.board_index,
                                lambda case: case.client))

rat = strategies.builds(
    _Rat,
    uuid=strategies.uuids(version=4),
github pytorch / pytorch / test / test_qat.py View on Github external
           freeze_bn=st.booleans())
    def test_conv_bn_relu(
            self,
            batch_size,
            input_channels_per_group,
            height,
            width,
            output_channels_per_group,
            groups,
            kernel_h,
            kernel_w,
            stride_h,
            stride_w,
            pad_h,
            pad_w,
            dilation,
            padding_mode,
github aws / chalice / tests / unit / test_app.py View on Github external
STR_TO_LIST_MAP = st.dictionaries(
    st.text(),
    st.lists(elements=st.text(), min_size=1, max_size=5)
)
HTTP_METHOD = st.sampled_from(['GET', 'POST', 'PUT', 'PATCH',
                               'OPTIONS', 'HEAD', 'DELETE'])
HTTP_BODY = st.none() | st.text()
HTTP_REQUEST = st.fixed_dictionaries({
    'query_params': STR_TO_LIST_MAP,
    'headers': STR_MAP,
    'uri_params': STR_MAP,
    'method': HTTP_METHOD,
    'body': HTTP_BODY,
    'context': STR_MAP,
    'stage_vars': STR_MAP,
    'is_base64_encoded': st.booleans(),
})
BINARY_TYPES = APIGateway().binary_types


class FakeLambdaContextIdentity(object):
    def __init__(self, cognito_identity_id, cognito_identity_pool_id):
        self.cognito_identity_id = cognito_identity_id
        self.cognito_identity_pool_id = cognito_identity_pool_id


class FakeLambdaContext(object):
    def __init__(self):
        self.function_name = 'test_name'
        self.function_version = 'version'
        self.invoked_function_arn = 'arn'
        self.memory_limit_in_mb = 256
github pycco-docs / pycco / tests / test_pycco.py View on Github external
@given(booleans(), booleans(), data())
def test_process(preserve_paths, index, data):
    lang_name = data.draw(sampled_from([l["name"] for l in supported_languages.values()]))
    p.process([PYCCO_SOURCE], preserve_paths=preserve_paths,
              index=index,
              outdir=tempfile.gettempdir(),
              language=lang_name)
github python-attrs / attrs / tests / test_funcs.py View on Github external
    @given(slots=st.booleans(), frozen=st.booleans())
    def test_empty(self, slots, frozen):
        """
        Empty classes without changes get copied.
        """

        @attr.s(slots=slots, frozen=frozen)
        class C(object):
            pass

        i1 = C()
        i2 = evolve(i1)

        assert i1 is not i2
        assert i1 == i2
github telepresenceio / telepresence / tests / local / test_output_mask.py View on Github external
def generate_dictionary_with_fixed_tokens(draw):
    """
    Builds random nested dictionary structure which is then used as JSON to
    mask two fixed "token" keys.

    Structure is based on TEST_JSON sample fixture defined above.
    """
    base = draw(
        st.fixed_dictionaries({'token': st.text(printable, min_size=10)})
    )

    optional = draw(
        st.nothing() | st.dictionaries(
            st.text(ascii_letters, min_size=1),
            st.floats() | st.integers() | st.text(printable) | st.booleans()
            | st.nothing(),
            min_size=10,
            max_size=50
        )
    )

    return {**base, **optional}
github olipratt / swagger-conformance / swaggerconformance / strategies / basestrategies.py View on Github external
def json(value_limit=5):
    """Hypothesis strategy for generating values that can be passed to
    `json.dumps` to produce valid JSON data.

    :param value_limit: A limit on the number of values in the JSON data -
                        setting this too high can cause value generation to
                        time out.
    :type value_limit: int
    """
    return hy_st.recursive(
        hy_st.floats() | hy_st.booleans() | hy_st.text() | hy_st.none(),
        lambda children: hy_st.dictionaries(hy_st.text(), children),
        max_leaves=value_limit)
github burningmantech / ranger-ims-server / src / ims / model / strategies.py View on Github external
def reportEntries(
    draw: Callable,
    author: Optional[str] = None,
    automatic: Optional[bool] = None,
    beforeNow: bool = False,
    fromNow: bool = False,
) -> ReportEntry:
    """
    Strategy that generates :class:`ReportEntry` values.
    """
    if author is None:
        author = draw(text(min_size=1))

    if automatic is None:
        automatic = draw(booleans())

    return ReportEntry(
        created=draw(dateTimes(beforeNow=beforeNow, fromNow=fromNow)),
        author=cast(str, author),
        automatic=cast(bool, automatic),
        text=draw(text(min_size=1)),
    )