python类dictionaries()的实例源码

service.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
    )
module_conversion.py 文件源码 项目:hypothesis-protobuf 作者: CurataEng 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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))
__init__.py 文件源码 项目:cattrs 作者: Tinche 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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))
__init__.py 文件源码 项目:cattrs 作者: Tinche 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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))
job.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def jobs(
        draw,
        services=service_generator(),
        parameters=dictionaries(text(), text()),
) -> Job:
    return Job.new(
        draw(services),
        draw(parameters)
    )
service.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
    )
test_services_list.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
    }
job.py 文件源码 项目:TopChef 作者: TopChef 项目源码 文件源码 阅读 91 收藏 0 点赞 0 评论 0
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)
    )
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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))
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 13 收藏 0 点赞 0 评论 0
def random_dictionary(**kwargs):
    """Return a strategy which generates a random list."""
    return hs.dictionaries(primitive_values, primitive_values, **kwargs)
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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))
custom_hypothesis_support.py 文件源码 项目:pyta 作者: pyta-uoft 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号