我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用hypothesis.strategies.none()。
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))
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