当前位置: 首页>>代码示例>>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;未经允许,请勿转载。