當前位置: 首頁>>代碼示例>>Python>>正文


Python hypothesis.assume方法代碼示例

本文整理匯總了Python中hypothesis.assume方法的典型用法代碼示例。如果您正苦於以下問題:Python hypothesis.assume方法的具體用法?Python hypothesis.assume怎麽用?Python hypothesis.assume使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hypothesis的用法示例。


在下文中一共展示了hypothesis.assume方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_linear_rescale_inner

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_linear_rescale_inner(args):
    X, lb0, ub0, lb1, ub1 = args

    # Use sorted because hypothesis doesn't like using assume too often
    lb0, ub0 = sorted([lb0, ub0])
    lb1, ub1 = sorted([lb1, ub1])

    assume(lb0 < ub0)
    assume(lb1 <= ub1)

    X = np.clip(X, lb0, ub0)

    X = np_util.linear_rescale(X, lb0, ub0, lb1, ub1)

    assert np.all(X <= ub1)
    assert np.all(lb1 <= X) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:18,代碼來源:np_util_test.py

示例2: test_linear_rescale_inverse

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_linear_rescale_inverse(args):
    X, lb0, ub0, lb1, ub1, enforce_bounds = args
    enforce_bounds = enforce_bounds >= 0

    # Use sorted because hypothesis doesn't like using assume too often
    lb0, ub0 = sorted([lb0, ub0])
    lb1, ub1 = sorted([lb1, ub1])

    assume(lb0 < ub0)
    assume(lb1 < ub1)
    # Can't expect numerics to work well in these extreme cases:
    assume((ub0 - lb0) < 1e3 * (ub1 - lb1))

    if enforce_bounds:
        X = np.clip(X, lb0, ub0)

    X_ = np_util.linear_rescale(X, lb0, ub0, lb1, ub1, enforce_bounds=enforce_bounds)
    X_ = np_util.linear_rescale(X_, lb1, ub1, lb0, ub0, enforce_bounds=enforce_bounds)

    assert close_enough(X_, X) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:22,代碼來源:np_util_test.py

示例3: test_no_content_type_is_still_allowed

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_no_content_type_is_still_allowed(create_event):
    # When the content type validation happens in API gateway, it appears
    # to assume a default of application/json, so the chalice handler needs
    # to emulate that behavior.

    demo = app.Chalice('demo-app')

    @demo.route('/', methods=['POST'], content_types=['application/json'])
    def index():
        return {'success': True}

    event = create_event('/', 'POST', {})
    del event['headers']['Content-Type']

    json_response = json_response_body(demo(event, context=None))
    assert json_response == {'success': True} 
開發者ID:aws,項目名稱:chalice,代碼行數:18,代碼來源:test_app.py

示例4: test_http_request_to_dict_is_json_serializable

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_http_request_to_dict_is_json_serializable(http_request_kwargs):
    # We have to do some slight pre-preprocessing here
    # to maintain preconditions.  If the
    # is_base64_encoded arg is True, we'll
    # base64 encode the body.  We assume API Gateway
    # upholds this precondition.
    is_base64_encoded = http_request_kwargs['is_base64_encoded']
    if is_base64_encoded:
        # Confirmed that if you send an empty body,
        # API Gateway will always say the body is *not*
        # base64 encoded.
        assume(http_request_kwargs['body'] is not None)
        body = base64.b64encode(
            http_request_kwargs['body'].encode('utf-8'))
        http_request_kwargs['body'] = body.decode('ascii')

    request = Request(**http_request_kwargs)
    assert isinstance(request.raw_body, bytes)
    request_dict = request.to_dict()
    # We should always be able to dump the request dict
    # to JSON.
    assert json.dumps(request_dict, default=handle_extra_types) 
開發者ID:aws,項目名稱:chalice,代碼行數:24,代碼來源:test_app.py

示例5: test_all_transitions

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_all_transitions(self, desired_state, discovered_state):
        """
        Transitions are defined from all possible desired states towards
        all possible discovered states.
        """
        assume(desired_state != discovered_state)
        verifyObject(
            IDatasetStateChangeFactory,
            DATASET_TRANSITIONS[desired_state][discovered_state],
        ) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:12,代碼來源:test_blockdevice.py

示例6: make_iblockdeviceasyncapi_tests

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def make_iblockdeviceasyncapi_tests(blockdeviceasync_api_factory):
    """
    :return: A ``TestCase`` with tests that will be performed on the supplied
        ``IBlockDeviceAsyncAPI`` provider.  These tests are not exhaustive
        because we currently assume ``make_iblockdeviceapi_tests`` will be used
        on the wrapped object.
    """
    class Tests(IBlockDeviceAsyncAPITestsMixin, TestCase):
        def setUp(self):
            super(Tests, self).setUp()
            self.api = blockdeviceasync_api_factory(test_case=self)

    return Tests 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:15,代碼來源:test_blockdevice.py

示例7: test_clip_chk_pass

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_clip_chk_pass(args):
    x, lb, ub = args

    assume(lb <= ub)

    x = np.clip(x, lb - 1e-10, ub + 1e-10)
    x_clip = np_util.clip_chk(x, lb=lb, ub=ub)
    assert np.all(x_clip == np.clip(x_clip, lb, ub)) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:10,代碼來源:np_util_test.py

示例8: test_clip_chk_pass_nan

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_clip_chk_pass_nan(args):
    x, lb, ub = args

    assume(lb <= ub)

    x = np.clip(x, lb - 1e-10, ub + 1e-10)
    x_clip = np_util.clip_chk(x, lb=lb, ub=ub, allow_nan=True)
    assert np.all((np.isnan(x) & np.isnan(x_clip)) | (x_clip == np.clip(x_clip, lb, ub))) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:10,代碼來源:np_util_test.py

示例9: test_linear_rescale_bounds

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_linear_rescale_bounds(args):
    lb0, ub0, lb1, ub1 = args

    # Use sorted because hypothesis doesn't like using assume too often
    lb0, ub0 = sorted([lb0, ub0])
    lb1, ub1 = sorted([lb1, ub1])

    assume(lb0 < ub0)
    assume(lb1 <= ub1)

    lb1_ = np_util.linear_rescale(lb0, lb0, ub0, lb1, ub1)
    assert close_enough(lb1, lb1_)

    ub1_ = np_util.linear_rescale(ub0, lb0, ub0, lb1, ub1)
    assert close_enough(ub1, ub1_) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:17,代碼來源:np_util_test.py

示例10: test_linear_rescale_broadcast

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_linear_rescale_broadcast():
    def clean_up(args):
        X, lb0, ub0, lb1, ub1, enforce_bounds = args

        enforce_bounds = enforce_bounds >= 0

        # Ideally, hypothesis should be able to handle constraints like this
        lb0, ub0 = pair_sort(lb0, ub0)
        lb1, ub1 = pair_sort(lb1, ub1)

        assume(np.all(lb0 < ub0))
        assume(np.all(lb1 <= ub1))

        if enforce_bounds:
            X = np.clip(X, lb0, ub0)

        return X, lb0, ub0, lb1, ub1, enforce_bounds

    broadcast_tester(
        np_util.linear_rescale,
        "(),(),(),(),(),()->()",
        "float64",
        excluded=(5,),
        map_=clean_up,
        min_value=-1000,
        max_value=1000,
    ) 
開發者ID:uber,項目名稱:bayesmark,代碼行數:29,代碼來源:np_util_test.py

示例11: _easy_text

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def _easy_text():
    # The NULL_PLUG confuses numpy arrays, so assume that is not in
    S = text().filter(lambda ss: NULL_PLUG not in ss)
    return S 
開發者ID:uber,項目名稱:bayesmark,代碼行數:6,代碼來源:util.py

示例12: tst_expression_behavior

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def tst_expression_behavior(v64, mem):
    # assume(s != 0)
    # print('code', v64, v32)

    source = ('module',
        # ('func', '$func3', ('result', 'i32'),
        #     v64,
        #     ('i32.wrap_i64',)
        # ),
        # ('func', '$func2', ('result', 'i64'),
        #     expr32,
        #     ('i64.extend_i32_s',),
        # ),
        ('func', ('export', 'my_func'), ('result', 'i64'),
            v64
            # ('i64.const', s),
            # ('i64.const', s),
            # ('i64.add'),
            # ('i64.const', s),
            # ('i64.mul'),
            # ('i64.const', s),
            # ('i64.sub'),
            # ('i64.const', s),
            # ('i64.rem_u'),
        ),
        ('memory', 2),
        ('data', ('i32.const', 0), mem)
    )

    # Create wasm module
    m = Module(source)
    assert_equal_behavior(m) 
開發者ID:windelbouwman,項目名稱:ppci,代碼行數:34,代碼來源:wasm.py

示例13: test_replace_string_literal_roundtrip

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def test_replace_string_literal_roundtrip(self, t, raw, quote):
        if raw:
            hypothesis.assume(expecttest.ok_for_raw_triple_quoted_string(t, quote=quote))
        prog = """\
        r = {r}{quote}placeholder{quote}
        r2 = {r}{quote}placeholder2{quote}
        r3 = {r}{quote}placeholder3{quote}
        """.format(r='r' if raw else '', quote=quote*3)
        new_prog = expecttest.replace_string_literal(textwrap.dedent(prog), 2, t)[0]
        ns = {}
        exec(new_prog, ns)
        msg = "program was:\n{}".format(new_prog)
        self.assertEqual(ns['r'], 'placeholder', msg=msg)  # noqa: F821
        self.assertEqual(ns['r2'], expecttest.normalize_nl(t), msg=msg)  # noqa: F821
        self.assertEqual(ns['r3'], 'placeholder3', msg=msg)  # noqa: F821 
開發者ID:ezyang,項目名稱:ghstack,代碼行數:17,代碼來源:test_expecttest.py

示例14: _json_schemata

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def _json_schemata(draw: Any, recur: bool = True) -> Any:
    # Current version of jsonschema does not support boolean schemata,
    # but 3.0 will.  See https://github.com/Julian/jsonschema/issues/337
    options = [
        st.builds(dict),
        st.just({"type": "null"}),
        st.just({"type": "boolean"}),
        gen_number("integer"),
        gen_number("number"),
        gen_string(),
        st.builds(dict, const=JSON_STRATEGY),
        gen_enum(),
        st.booleans(),
    ]
    if recur:
        options += [
            gen_array(),
            gen_object(),
            # Conditional subschemata
            gen_if_then_else(),
            json_schemata().map(lambda v: assume(v and v is not True) and {"not": v}),
            st.builds(dict, anyOf=st.lists(json_schemata(), min_size=1)),
            st.builds(dict, oneOf=st.lists(json_schemata(), min_size=1, max_size=2)),
            st.builds(dict, allOf=st.lists(json_schemata(), min_size=1, max_size=2)),
        ]

    return draw(st.one_of(options)) 
開發者ID:Zac-HD,項目名稱:hypothesis-jsonschema,代碼行數:29,代碼來源:gen_schemas.py

示例15: gen_number

# 需要導入模塊: import hypothesis [as 別名]
# 或者: from hypothesis import assume [as 別名]
def gen_number(draw: Any, kind: str) -> Dict[str, Union[str, float]]:
    """Draw a numeric schema."""
    max_int_float = 2 ** 53
    lower = draw(st.none() | st.integers(-max_int_float, max_int_float))
    upper = draw(st.none() | st.integers(-max_int_float, max_int_float))
    if lower is not None and upper is not None and lower > upper:
        lower, upper = upper, lower
    multiple_of = draw(
        st.none() | st.integers(2, 100) | st.floats(1 / 1024, 100, exclude_min=True)
    )
    assume(None in (multiple_of, lower, upper) or multiple_of <= (upper - lower))
    assert kind in ("integer", "number")
    out: Dict[str, Union[str, float]] = {"type": kind}
    # Generate the latest draft supported by jsonschema.
    assert hasattr(jsonschema, "Draft7Validator")
    if lower is not None:
        if draw(st.booleans(), label="exclusiveMinimum"):
            out["exclusiveMinimum"] = lower - 1
        else:
            out["minimum"] = lower
    if upper is not None:
        if draw(st.booleans(), label="exclusiveMaximum"):
            out["exclusiveMaximum"] = upper + 1
        else:
            out["maximum"] = upper
    if multiple_of is not None:
        out["multipleOf"] = multiple_of
    return out 
開發者ID:Zac-HD,項目名稱:hypothesis-jsonschema,代碼行數:30,代碼來源:gen_schemas.py


注:本文中的hypothesis.assume方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。