本文整理匯總了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'})))