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

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

项目:hypothesis-regex    作者:maximkulkin    | 项目源码 | 文件源码
def strategy(self):
        'Returns resulting strategy that generates configured char set'
        max_codepoint = None if self._unicode else 127

        strategies = []
        if self._negate:
            if self._categories or self._whitelist_chars:
                strategies.append(
                    hs.characters(
                        blacklist_categories=self._categories | set(['Cc', 'Cs']),
                        blacklist_characters=self._whitelist_chars,
                        max_codepoint=max_codepoint,
                    )
                )
            if self._blacklist_chars:
                strategies.append(
                    hs.sampled_from(
                        list(self._blacklist_chars - self._whitelist_chars)
                    )
                )
        else:
            if self._categories or self._blacklist_chars:
                strategies.append(
                    hs.characters(
                        whitelist_categories=self._categories,
                        blacklist_characters=self._blacklist_chars,
                        max_codepoint=max_codepoint,
                    )
                )
            if self._whitelist_chars:
                strategies.append(
                    hs.sampled_from(
                        list(self._whitelist_chars - self._blacklist_chars)
                    )
                )

        return hs.one_of(*strategies) if strategies else hs.just(u'')
项目:client    作者:syncrypt    | 项目源码 | 文件源码
def file(draw, filename=st.lists(
        st.characters(blacklist_categories=('Cc',),
            blacklist_characters=('\0\n\r/\\|><')),
            min_size=1, average_size=20, max_size=80),
            content=st.binary(max_size=10000, average_size=100)):
    return {'filename': ''.join(draw(filename)),
            'content': draw(content)}
项目: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))
项目:chandere2    作者:TsarFox    | 项目源码 | 文件源码
def test_no_filters(self, field, value):
        posts = [{field: value}]
        posts = filter_posts(posts, [])
        assert posts == [{field: value}]

    # Asserts that the post is properly filtered.
    # Regex characters are blacklisted to prevent false negatives.
项目:chandere2    作者:TsarFox    | 项目源码 | 文件源码
def test_ignore_expicit_regex(self, pattern):
        parsed = convert_to_regexp("/%s/" % pattern)
        assert parsed == pattern

        parsed = convert_to_regexp("%s/%s/" % (pattern, pattern))
        assert parsed == "%s%s" % (pattern, pattern)

        parsed = convert_to_regexp("/%s/%s" % (pattern, pattern))
        assert parsed == "%s%s" % (pattern, pattern)

    # Asserts that regex special characters are escaped.