本文整理汇总了Python中hypothesis.strategies.none方法的典型用法代码示例。如果您正苦于以下问题:Python strategies.none方法的具体用法?Python strategies.none怎么用?Python strategies.none使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.strategies
的用法示例。
在下文中一共展示了strategies.none方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_schema
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def from_schema(schema):
"""Returns a strategy for objects that match the given schema."""
check_schema(schema)
# TODO: actually handle constraints on number/string/array schemas
return dict(
null=st.none(),
bool=st.booleans(),
number=st.floats(allow_nan=False),
string=st.text(),
array=st.lists(st.nothing()),
)[schema["type"]]
# `@st.composite` is one way to write this - another would be to define a
# bare function, and `return st.one_of(st.none(), st.booleans(), ...)` so
# each strategy can be defined individually. Use whichever seems more
# natural to you - the important thing in tests is usually readability!
示例2: chromeResponseReceived
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
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,
'mimeType': mimeTypeSt,
'remoteIPAddress': remoteIpAddressSt,
'protocol': protocolSt,
})
})
示例3: requestResponsePair
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def requestResponsePair ():
def f (creq, cresp, hasPostData, reqBody, respBody):
i = RequestResponsePair ()
i.fromRequestWillBeSent (creq)
i.request.hasPostData = hasPostData
if hasPostData:
i.request.body = reqBody
if cresp is not None:
i.fromResponseReceived (cresp)
if respBody is not None:
i.response.body = respBody
return i
bodySt = st.one_of (
st.none (),
st.builds (UnicodeBody, st.text ()),
st.builds (Base64Body.fromBytes, st.binary ())
)
return st.builds (lambda reqresp, hasPostData, reqBody, respBody:
f (reqresp[0], reqresp[1], hasPostData, reqBody, respBody),
chromeReqResp (), st.booleans (), bodySt, bodySt)
示例4: gen_roll_args
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def gen_roll_args(draw, arr):
shift = draw(st.integers() | st.tuples(*(st.integers() for i in arr.shape)))
if arr.ndim:
ax_strat = hnp.valid_tuple_axes(
arr.ndim,
**(
dict(min_size=len(shift), max_size=len(shift))
if isinstance(shift, tuple)
else {}
)
)
axis = draw(st.none() | st.integers(-arr.ndim, arr.ndim - 1) | ax_strat)
else:
axis = None
return dict(shift=shift, axis=axis)
示例5: gen_string
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def gen_string(draw: Any) -> Dict[str, Union[str, int]]:
"""Draw a string schema."""
min_size = draw(st.none() | st.integers(0, 10))
max_size = draw(st.none() | st.integers(0, 1000))
if min_size is not None and max_size is not None and min_size > max_size:
min_size, max_size = max_size, min_size
pattern = draw(st.none() | REGEX_PATTERNS)
format_ = draw(st.none() | st.sampled_from(sorted(STRING_FORMATS)))
out: Dict[str, Union[str, int]] = {"type": "string"}
if pattern is not None:
out["pattern"] = pattern
elif format_ is not None:
out["format"] = format_
if min_size is not None:
out["minLength"] = min_size
if max_size is not None:
out["maxLength"] = max_size
return out
示例6: slice_node
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def slice_node(draw):
lower = draw(hs.one_of(const_node(hs.integers()), hs.none()))
upper = draw(hs.one_of(const_node(hs.integers()), hs.none()))
step = draw(hs.one_of(const_node(hs.integers()), hs.none()))
node = astroid.Slice()
node.postinit(lower, upper, step)
return node
示例7: urls
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def urls ():
""" Build http/https URL """
scheme = st.sampled_from (['http', 'https'])
# Path must start with a slash
pathSt = st.builds (lambda x: '/' + x, st.text ())
args = st.fixed_dictionaries ({
'scheme': scheme,
'host': domains (),
'port': st.one_of (st.none (), st.integers (min_value=1, max_value=2**16-1)),
'path': pathSt,
'query_string': st.text (),
'fragment': st.text (),
})
return st.builds (lambda x: URL.build (**x), args)
示例8: field_to_strategy
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def field_to_strategy(field, env):
"""Generate strategy for field."""
if SCALAR_MAPPINGS.get(field.type) is not None:
return apply_modifier(
strategy=SCALAR_MAPPINGS[field.type],
field=field
)
if field.type is FieldDescriptor.TYPE_ENUM:
return apply_modifier(
strategy=find_strategy_in_env(field.enum_type, env),
field=field
)
if field.type is FieldDescriptor.TYPE_MESSAGE:
field_options = field.message_type.GetOptions()
if field_options.deprecated:
return st.none()
if field_options.map_entry:
k, v = field.message_type.fields
return st.dictionaries(
field_to_strategy(k, env).filter(non_null),
field_to_strategy(v, env).filter(non_null)
)
return apply_modifier(
strategy=find_strategy_in_env(field.message_type, env),
field=field
)
raise Exception("Unhandled field {}.".format(field))
示例9: single_axis_arg
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def single_axis_arg(*arrs):
""" Wrapper for passing valid-axis (single-value only)
search strategy to test factory"""
if arrs[0].ndim:
return valid_axes(arrs[0].ndim, single_axis_only=True)
else:
return st.none()
示例10: test_sliding_window
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def test_sliding_window(data, x):
""" Test variations of window-shape, step, and dilation for sliding window
view of N-dimensional array."""
win_dim = data.draw(st.integers(1, x.ndim), label="win_dim")
win_shape = data.draw(
st.tuples(*(st.integers(1, s) for s in x.shape[-win_dim:])), label="win_shape"
)
step = data.draw(
st.tuples(*(st.integers(1, s) for s in x.shape[-win_dim:])), label="step"
)
max_dilation = np.array(x.shape[-win_dim:]) // win_shape
dilation = data.draw(
st.one_of(
st.none()
| st.integers(1, min(max_dilation))
| st.tuples(*(st.integers(1, s) for s in max_dilation))
),
label="dilation",
)
y = sliding_window_view(x, window_shape=win_shape, step=step, dilation=dilation)
if dilation is None:
dilation = np.ones((len(win_shape),), dtype=int)
if isinstance(dilation, int):
dilation = np.full((len(win_shape),), fill_value=dilation, dtype=int)
for ind in np.ndindex(*y.shape[:win_dim]):
slices = tuple(
slice(i * s, i * s + w * d, d)
for i, w, s, d in zip(ind, win_shape, step, dilation)
)
assert_allclose(actual=y[tuple([*ind])], desired=x[(..., *slices)])
示例11: gen_int_repeat_args
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def gen_int_repeat_args(arr: Tensor) -> st.SearchStrategy[dict]:
valid_axis = st.none()
valid_axis |= st.integers(-arr.ndim, arr.ndim - 1) if arr.ndim else st.just(0)
return st.fixed_dictionaries(
dict(repeats=st.integers(min_value=0, max_value=5), axis=valid_axis,)
)
示例12: gen_tuple_repeat_args
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def gen_tuple_repeat_args(draw: st.DataObject.draw, arr: Tensor):
valid_axis = draw(
st.none() | (st.integers(-arr.ndim, arr.ndim - 1) if arr.ndim else st.just(0))
)
num_repeats = (
arr.shape[valid_axis] if valid_axis is not None and arr.ndim else arr.size
)
repeats = draw(st.tuples(*[st.integers(0, 5)] * num_repeats))
return dict(repeats=repeats, axis=valid_axis,)
示例13: optionals
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def optionals(strategy):
return one_of(strategy, none())
示例14: primitives
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
def primitives():
return (
st.integers() |
st.floats(allow_nan=False) |
st.text() |
st.binary() |
st.datetimes(timezones=timezones() | st.none()) |
st.dates() |
st.times(timezones=timezones() | st.none()) |
st.timedeltas() |
st.booleans() |
st.none()
)
示例15: json
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import none [as 别名]
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)