How to use the hypothesis.strategies.integers 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 lordmauve / chopsticks / tests / test_pencode.py View on Github external
def is_ascii(s):
    try:
        s.decode('ascii')
    except UnicodeDecodeError:
        return False
    return True

ascii_text = strategies.characters(max_codepoint=127)
ascii_binary = strategies.builds(lambda s: s.encode('ascii'), ascii_text)

immutables = strategies.recursive(
    ascii_binary |
    strategies.booleans() |
    strategies.floats(allow_nan=False) |
    strategies.integers() |
    strategies.none() |
    strategies.text() |
    strategies.tuples(),
    lambda children: (
        strategies.frozensets(children) |
        strategies.tuples(children)
    ),
)

mutables = strategies.recursive(
    strategies.dictionaries(immutables, immutables) |
    strategies.lists(immutables) |
    strategies.sets(immutables),
    lambda children: (
        strategies.dictionaries(immutables, children) |
        strategies.lists(children)
github pytorch / pytorch / test / test_quantized_conv.py View on Github external
           dH=st.integers(1, 2), dW=st.integers(1, 2))
    def test_conv_api(self, X, padH, padW, sH, sW, dH, dW):
        """Tests the correctness of the conv functional.

        The correctness is defined by the behavior being similar to the
        `quantized._ops` implementation.
        """
        # Random inputs
        # X, (scale, zero_point, torch_type) = X
        (inputs, filters, bias, groups) = X
        inputs, (inputs_scale, inputs_zero_point, inputs_qtype) = inputs
        filters, (filters_scale, filters_zero_point, filters_qtype) = filters
        bias, (bias_scale, bias_zero_point, bias_qtype) = bias

        scale, zero_point = inputs_scale, inputs_zero_point
        torch_type = inputs_qtype
github HypothesisWorks / hypothesis / tests / cover / test_find.py View on Github external
def test_can_find_list():
    x = find(lists(integers()), lambda x: sum(x) >= 10)
    assert sum(x) == 10
github ethereum / eth-utils / tests / currency-utils / test_currency_tools.py View on Github external
    amount_in_wei=st.integers(min_value=MIN_WEI, max_value=MAX_WEI),
    intermediate_unit=st.sampled_from(tuple(units.keys())),
)
def test_conversion_round_trip(amount_in_wei, intermediate_unit):
    intermediate_amount = from_wei(amount_in_wei, intermediate_unit)
    result_amount = to_wei(intermediate_amount, intermediate_unit)
    assert result_amount == amount_in_wei
github HypothesisWorks / hypothesis / tests / quality / test_poisoned_lists.py View on Github external
def __init__(self, elements, size):
        SearchStrategy.__init__(self)
        self.__length = st.integers(0, ceil(size ** 0.5))
        self.__elements = elements
github ethereum / web3.py / tests / core / filtering / test_contract_data_filters.py View on Github external
def fixed_values(draw):
    matching_values = draw(st.lists(elements=st.integers(min_value=0), min_size=4, max_size=4))
    non_matching_1 = draw(st.integers(min_value=0).filter(lambda x: x not in matching_values))
    non_matching_2 = draw(st.integers(min_value=0).filter(lambda x: x not in matching_values))
    non_matching_3 = draw(st.integers(min_value=0).filter(lambda x: x not in matching_values))
    non_matching_4 = draw(st.integers(min_value=0).filter(lambda x: x not in matching_values))
    return {
        "matching": matching_values,
        "non_matching": [
            non_matching_1,
            non_matching_2,
            non_matching_3,
            non_matching_4
        ]
github LeastAuthority / txkube / src / txkube / testing / strategies.py View on Github external
def port_numbers(min_value=1, max_value=65535):
    """
    Builds integers in the range of TCP/UDP port numbers.
    """
    return integers(min_value, max_value)
github ericmjl / pyjanitor / janitor / testing_utils / strategies.py View on Github external
def df_strategy():
    """
    A convenience function for generating a dataframe as a hypothesis strategy.

    Should be treated like a fixture, but should not be passed as a fixture
    into a test function. Instead::

        @given(df=dataframe())
        def test_function(df):
            # test goes here
    """
    return data_frames(
        columns=[
            column("a", elements=st.integers()),
            column("Bell__Chart", elements=st.floats()),
            column("decorated-elephant", elements=st.integers()),
            column("animals@#$%^", elements=st.text()),
            column("cities", st.text()),
        ],
        index=range_indexes(min_size=1, max_size=20),
    )
github HypothesisWorks / hypothesis / tests / py2 / test_destructuring.py View on Github external
    @given(integers())
    def foo(a, (b, c)):
        pass
    with pytest.raises(InvalidArgument):
github burningmantech / ranger-ims-server / src / ims / model / strategies.py View on Github external
def timeZones(draw: Callable) -> TimeZone:
    offset = draw(integers(min_value=-(60 * 24) + 1, max_value=(60 * 24) - 1))
    timeDelta = TimeDelta(minutes=offset)
    timeZone = TimeZone(offset=timeDelta, name="{}s".format(offset))
    return timeZone