本文整理匯總了Python中hypothesis.strategies.from_type方法的典型用法代碼示例。如果您正苦於以下問題:Python strategies.from_type方法的具體用法?Python strategies.from_type怎麽用?Python strategies.from_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類hypothesis.strategies
的用法示例。
在下文中一共展示了strategies.from_type方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tick_classes
# 需要導入模塊: from hypothesis import strategies [as 別名]
# 或者: from hypothesis.strategies import from_type [as 別名]
def tick_classes(request):
"""
Fixture for Tick based datetime offsets available for a time series.
"""
return request.param
# ----------------------------------------------------------------
# Global setup for tests using Hypothesis
# Registering these strategies makes them globally available via st.from_type,
# which is use for offsets in tests/tseries/offsets/test_offsets_properties.py
示例2: test_mean_properties
# 需要導入模塊: from hypothesis import strategies [as 別名]
# 或者: from hypothesis.strategies import from_type [as 別名]
def test_mean_properties(data, type_, strat):
strat = strat or st.from_type(type_)
values = data.draw(st.lists(strat, min_size=1))
result = mean(values) # already testing no exceptions!
# TODO: property assertions, e.g. bounds on result, etc.
if type_ is Fraction:
assert min(values) <= result <= max(values)
# What constraints make sense for an integer mean?
# TODO: metamorphic test assertions. For example, how should result
# change if you add the mean to values? a number above or below result?
# Remove some elements from values?
示例3: everything_except
# 需要導入模塊: from hypothesis import strategies [as 別名]
# 或者: from hypothesis.strategies import from_type [as 別名]
def everything_except(
excluded_types: Union[type, Tuple[type, ...]]
) -> st.SearchStrategy[Any]:
"""Returns hypothesis strategy that generates values of any type other than
those specified in ``excluded_types``."""
return (
st.from_type(type)
.flatmap(st.from_type)
.filter(lambda x: not isinstance(x, excluded_types))
)