本文整理汇总了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))
)