我有以下方法在我的一项测试中生成随机数据:
import random
data_categories = {
'a': [1, 2, 3],
'b': [4, 5],
'c': [6, 7, 8]
}
def make_record():
return [random.choice(vals) for vals in data_categories.values()]
如何将其转换为假设策略?
这是我使用的尝试hypothesis.strategies.composite
,但很难知道我是否正确使用它:
import hypothesis.strategies as hs
@hs.composite
def make_record(draw):
return [draw(hs.sampled_from(vals)) for vals in data_categories.values()]