Python hypothesis.strategies 模块,builds() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用hypothesis.strategies.builds()

项目:hypothesis-protobuf    作者:CurataEng    | 项目源码 | 文件源码
def buildable(message_obj):
    """Return a "buildable" callable for st.builds which will handle optionals."""
    def builder(**kwargs):
        return message_obj(**{
            k: v
            for k, v in kwargs.items()
            if v is not None  # filter out unpopulated optional param
        })
    builder.__name__ = message_obj.DESCRIPTOR.full_name
    return builder
项目:hypothesis-protobuf    作者:CurataEng    | 项目源码 | 文件源码
def message_to_strategy(message_obj, env, overrides=None):
    """Generate strategy from message."""
    # TODO: nested enums are not supported
    # TODO: nested messages are not supported

    return st.builds(
        buildable(message_obj),
        **{
            field_name: field_to_strategy(field, env, overrides=overrides)
            for field_name, field in message_obj.DESCRIPTOR.fields_by_name.items()
        }
    )
项目:specktre    作者:alexwlchan    | 项目源码 | 文件源码
def color_strategy():
    """Hypothesis strategy for generating instances of `RGBColor`."""
    return st.builds(
        RGBColor,
        st.integers(min_value=0, max_value=255),
        st.integers(min_value=0, max_value=255),
        st.integers(min_value=0, max_value=255),
    )
项目:txacme    作者:twisted    | 项目源码 | 文件源码
def urls():
    """
    Strategy for generating ``twisted.python.url.URL``\s.
    """
    return s.builds(
        URL,
        scheme=s.just(u'https'),
        host=dns_names(),
        path=s.lists(s.text(
            max_size=64,
            alphabet=s.characters(blacklist_characters=u'/?#',
                                  blacklist_categories=('Cs',))
        ), min_size=1, max_size=10))