本文整理汇总了Python中hypothesis.strategies.characters方法的典型用法代码示例。如果您正苦于以下问题:Python strategies.characters方法的具体用法?Python strategies.characters怎么用?Python strategies.characters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.strategies
的用法示例。
在下文中一共展示了strategies.characters方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: urls
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def urls():
"""
Strategy for generating urls.
"""
return st.builds(
parsed_url,
scheme=st.sampled_from(uri_schemes),
netloc=dns_names(),
path=st.lists(
st.text(
max_size=64,
alphabet=st.characters(
blacklist_characters="/?#", blacklist_categories=("Cs",)
),
),
min_size=1,
max_size=10,
)
.map(to_text)
.map("".join),
)
示例2: legal_path_chars
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def legal_path_chars():
# Control characters
blacklist = ["/"]
if os.name == "nt":
blacklist.extend(["<", ">", ":", '"', "\\", "|", "?", "*"])
return (
st.text(
st.characters(
blacklist_characters=blacklist,
blacklist_categories=("Cs",),
min_codepoint=32,
),
min_size=0,
max_size=64,
)
.filter(lambda s: not any(s.endswith(c) for c in [".", "/", "./", "/.", " "]))
.filter(lambda s: not s.startswith("/"))
.filter(lambda s: s not in ["", ".", "./", ".."])
)
示例3: test_pre_run_hook_valid
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def test_pre_run_hook_valid(testdir, cli, schema_url, app):
# When `--pre-run` hook is passed to the CLI call
module = testdir.make_importable_pyfile(
hook="""
import string
import schemathesis
from hypothesis import strategies as st
schemathesis.register_string_format(
"digits",
st.text(
min_size=1,
alphabet=st.characters(
whitelist_characters=string.digits,
whitelist_categories=()
)
)
)
"""
)
result = cli.main(
"--pre-run", module.purebasename, "run", "--hypothesis-suppress-health-check=filter_too_much", schema_url
)
# Then CLI should run successfully
assert result.exit_code == ExitCode.OK, result.stdout
# And all registered new string format should produce digits as expected
assert all(request.query["id"].isdigit() for request in app["incoming_requests"])
示例4: urls
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
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))
示例5: legal_path_chars
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def legal_path_chars():
# Control characters
blacklist = ["/"]
if os.name == "nt":
blacklist.extend(["<", ">", ":", '"', "\\", "|", "?", "*"])
return st.text(
st.characters(
blacklist_characters=blacklist, blacklist_categories=("C",), min_codepoint=32,
),
min_size=1,
max_size=10,
)
示例6: strategy
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def strategy(self):
if self._enum is not None:
return hy_st.sampled_from(self._enum)
alphabet = None
if self._blacklist_chars:
alphabet = hy_st.characters(
blacklist_characters=self._blacklist_chars)
strategy = hy_st.text(alphabet=alphabet,
min_size=self._min_length,
max_size=self._max_length)
return strategy
示例7: urls
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def urls():
"""
Strategy for generating urls.
"""
def url_encode(s):
return "".join(c if c in URL_SAFE_CHARACTERS else "%%%02X" % ord(c) for c in s)
return st.builds(
URI,
scheme=st.sampled_from(uri_schemes),
host=domains(),
port=st.integers(min_value=1, max_value=65535),
path=st.lists(st.text(string.printable).map(url_encode)).map("/".join),
query=st.lists(
st.text(
max_size=10,
alphabet=st.characters(
blacklist_characters="/?#", blacklist_categories=("Cs",)
),
),
min_size=2,
max_size=2,
)
.map("=".join)
.map(vistir.misc.to_text),
ref=st.text(max_size=64, alphabet="abcdefghijklmnopqrstuvwxyz0123456789"),
subdirectory=st.text(
max_size=64, alphabet="abcdefghijklmnopqrstuvwxyz0123456789"
),
extras=st.lists(
st.text(max_size=20, alphabet="abcdefghijklmnopqrstuvwxyz0123456789_-."),
min_size=0,
max_size=10,
),
)
示例8: axiomText
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def axiomText(*a, **kw):
"""
Strategy for generating Axiom-compatible text values.
"""
return st.text(
alphabet=st.characters(
blacklist_categories={'Cs'},
blacklist_characters={u'\x00'}),
*a, **kw)
示例9: textlists
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import characters [as 别名]
def textlists():
"""
Strategy for generating lists storable with L{axiom.attributes.textlist}.
"""
return st.lists(st.text(
alphabet=st.characters(
blacklist_categories={'Cs'},
blacklist_characters={u'\x00', u'\x02', u'\x1f'})))