我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用hypothesis.strategies.dictionaries()。
def services( draw, ids=uuids(), names=text(), descriptions=text(), registration_schemas=dictionaries(text(), text()), result_schemas=dictionaries(text(), text()), are_available=booleans(), service_job_lists=job_lists(), timeouts=timedeltas() ) -> ServiceInterface: return Service( draw(ids), draw(names), draw(descriptions), draw(registration_schemas), draw(result_schemas), draw(are_available), draw(service_job_lists), draw(timeouts) )
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 create_dict_and_type(tuple_of_strats): """Map two primitive strategies into a strategy for dict and type.""" (prim_strat_1, type_1), (prim_strat_2, type_2) = tuple_of_strats return st.tuples(st.dictionaries(prim_strat_1, prim_strat_2), create_generic_dict_type(type_1, type_2))
def dict_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields dictionaries for that attribute. The dictionaries map strings to integers. """ default = NOTHING val_strat = st.dictionaries(keys=st.text(), values=st.integers()) if defaults is True or (defaults is None and draw(st.booleans())): default_val = draw(val_strat) default = attr.Factory(lambda: default_val) return ((attr.ib(default=default), val_strat))
def jobs( draw, services=service_generator(), parameters=dictionaries(text(), text()), ) -> Job: return Job.new( draw(services), draw(parameters) )
def services( draw, names=text(), descriptions=text(), registration=dictionaries(text(), text()), results=dictionaries(text(), text()) ) -> Service: return Service.new( name=draw(names), description=draw(descriptions), registration_schema=draw(registration), result_schema=draw(results) )
def _valid_post_requests( draw, names: str=text(), descriptions: str=text(), job_registration_schemas: dict=dictionaries(text(), text()), job_result_schemas: dict=dictionaries(text(), text()) ) -> dict: return { 'name': draw(names), 'description': draw(descriptions), 'job_registration_schema': draw(job_registration_schemas), 'job_result_schema': draw(job_result_schemas) }
def jobs( draw, ids=uuids(), statuses=sampled_from(JobInterface.JobStatus), parameters=dictionaries(text(), text()), results=dictionaries(text(), text()), dates_submitted=datetimes(), registration_schemas=dictionaries(text(), text()), result_schemas=dictionaries(text(), text()) ) -> JobInterface: """ :param draw: A function that can take a strategy and draw a datum from it :param ids: A hypothesis strategy (statisticians should read "random variable"), that represents the set of all valid job IDs :param statuses: A hypothesis strategy that samples from the set of all allowed job statuses :param parameters: A hypothesis strategy that samples from all job parameters :param results: A hypothesis strategy that represents the possible results :param dates_submitted: A hypothesis strategy that represents the possible dates that can be submitted :param registration_schemas: The possible job registration schemas :param result_schemas: The possible job result schemas :return: A randomly-generated implementation of :class:`JobInterface` """ return Job( draw(ids), draw(statuses), draw(parameters), draw(results), draw(dates_submitted), draw(registration_schemas), draw(result_schemas) )
def homogeneous_dictionary(**kwargs): """Return a strategy which generates a dictionary of uniform key:value type.""" return index_types.flatmap(lambda s: hs.dictionaries(s(), s(), **kwargs))
def random_dictionary(**kwargs): """Return a strategy which generates a random list.""" return hs.dictionaries(primitive_values, primitive_values, **kwargs)
def random_dict_variable_homogeneous_value(**kwargs): """Return a strategy which generates a random dictionary of variable name and value""" return primitive_types.flatmap(lambda s: hs.dictionaries(valid_identifier(), s(), **kwargs))
def dict_node(draw, key=const_node(), value=const_node(), **kwargs): items = draw(hs.dictionaries(key, value, **kwargs)).items() node = astroid.Dict() node.postinit(items) return node