Python hypothesis.strategies.characters() Examples
The following are 9
code examples of hypothesis.strategies.characters().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hypothesis.strategies
, or try the search function
.
Example #1
Source File: strategies.py From vistir with ISC License | 6 votes |
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), )
Example #2
Source File: strategies.py From requirementslib with MIT License | 6 votes |
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 ["", ".", "./", ".."]) )
Example #3
Source File: test_commands.py From schemathesis with MIT License | 5 votes |
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"])
Example #4
Source File: strategies.py From txacme with MIT License | 5 votes |
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))
Example #5
Source File: strategies.py From vistir with ISC License | 5 votes |
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, )
Example #6
Source File: primitivestrategies.py From swagger-conformance with MIT License | 5 votes |
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
Example #7
Source File: strategies.py From requirementslib with MIT License | 5 votes |
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, ), )
Example #8
Source File: strategies.py From axiom with MIT License | 5 votes |
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)
Example #9
Source File: strategies.py From axiom with MIT License | 5 votes |
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'})))