本文整理汇总了Python中hypothesis.example方法的典型用法代码示例。如果您正苦于以下问题:Python hypothesis.example方法的具体用法?Python hypothesis.example怎么用?Python hypothesis.example使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis
的用法示例。
在下文中一共展示了hypothesis.example方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pattern_to_statements
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def pattern_to_statements(pattern):
if isinstance(pattern, template):
return lists(just(pattern), min_size=1, max_size=1)
rule, value = pattern
if rule == 'sequence':
return tuples(*map(pattern_to_statements, value)).map(unpack_list).map(list)
elif rule == 'alternates':
return one_of(*map(pattern_to_statements, value))
elif rule == 'zeroOrMore':
return lists(pattern_to_statements(value)).map(unpack_list).map(list)
elif rule == 'oneOrMore':
return lists(pattern_to_statements(value), min_size=1).map(unpack_list).map(list)
elif rule == 'optional':
return lists(pattern_to_statements(value), min_size=0, max_size=1).map(unpack_list).map(list)
else:
raise Exception("impossible!", rule)
# this replicates the current scorm pattern, a realistic example of medium
# complexity. Note it has repeated elements, just not in ambiguous ways.
示例2: test_cached_property
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_cached_property():
class A:
call_count = 0
@cached_property
def example(self):
"""Docstring Test"""
A.call_count += 1
return 42
a = A()
b = A()
assert A.call_count == 0
assert a.example == 42
assert A.call_count == 1
assert a.example == 42
assert A.call_count == 1
assert b.example == 42
assert A.call_count == 2
assert b.example == 42
assert A.call_count == 2
assert A.example.__doc__ == "Docstring Test"
示例3: test_slot_cached_property
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_slot_cached_property():
class A:
__slots__ = ('cache', )
call_count = 0
@slot_cached_property('cache')
def example(self):
"""Docstring Test"""
A.call_count += 1
return 42
a = A()
b = A()
assert A.call_count == 0
assert a.example == 42
assert A.call_count == 1
assert a.example == 42
assert A.call_count == 1
assert b.example == 42
assert A.call_count == 2
assert b.example == 42
assert A.call_count == 2
assert A.example.__doc__ == "Docstring Test"
示例4: mocked_schema
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def mocked_schema():
"""Module-level mock for fast hypothesis tests.
We're checking the input validation part, what comes from the network is not important in this context,
the faster run will be, the better.
"""
response = Response()
response._content = b"""openapi: 3.0.0
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
paths: {}
servers:
- url: https://api.example.com/{basePath}
variables:
basePath:
default: v1
"""
response.status_code = 200
with mock.patch("schemathesis.loaders.requests.sessions.Session.send", return_value=response):
yield
示例5: test_registration_email
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_registration_email(self):
"""
If we give our service an email address, that address will be used as a
registration contact.
"""
# First the case with no email given.
with AcmeFixture() as fixture:
fixture.service.startService()
self.assertThat(fixture.service._regr, MatchesStructure(
body=MatchesStructure(
key=Is(None),
contact=Equals(()))))
# Next, we give an email.
with AcmeFixture(email=u'example@example.com') as fixture:
fixture.service.startService()
self.assertThat(fixture.service._regr, MatchesStructure(
body=MatchesStructure(
key=Is(None),
contact=Equals((u'mailto:example@example.com',)))))
示例6: test_to_py_valid
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_to_py_valid(self, klass):
pattern = 'http://*.example.com/'
assert klass().to_py(pattern) == urlmatch.UrlPattern(pattern)
示例7: test_ang2vec
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_ang2vec(lon, lat, lonlat):
if lonlat:
theta, phi = lon, lat
else:
theta, phi = np.pi / 2. - np.radians(lat), np.radians(lon)
xyz1 = hp_compat.ang2vec(theta, phi, lonlat=lonlat)
xyz2 = hp.ang2vec(theta, phi, lonlat=lonlat)
assert_allclose(xyz1, xyz2, atol=1e-10)
# The following fails, need to investigate:
# @example(nside_pow=29, lon=1.0000000028043134e-05, lat=1.000000000805912e-05,
# nest=False, lonlat=False)
#
示例8: add_examples
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def add_examples(test: Callable, endpoint: Endpoint, hook_dispatcher: Optional[HookDispatcher] = None) -> Callable:
"""Add examples to the Hypothesis test, if they are specified in the schema."""
examples: List[Case] = [get_single_example(strategy) for strategy in endpoint.get_strategies_from_examples()]
context = HookContext(endpoint) # context should be passed here instead
GLOBAL_HOOK_DISPATCHER.dispatch("before_add_examples", context, examples)
endpoint.schema.hooks.dispatch("before_add_examples", context, examples)
if hook_dispatcher:
hook_dispatcher.dispatch("before_add_examples", context, examples)
for example in examples:
test = hypothesis.example(case=example)(test)
return test
示例9: csv_strategy
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def csv_strategy(enum):
return st.lists(st.sampled_from([item.name for item in enum]), min_size=1).map(",".join)
# The following strategies generate CLI parameters, for example "--workers=5" or "--exitfirst"
示例10: test_stop_responding_already_stopped
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_stop_responding_already_stopped(self, token):
"""
Calling ``stop_responding`` when we are not responding for a server
name does nothing.
"""
challenge = self._challenge_factory(token=token)
response = challenge.response(RSA_KEY_512)
responder = self._responder_factory()
d = maybeDeferred(
responder.stop_responding,
u'example.com',
challenge,
response)
self._do_one_thing()
self.assertThat(d, succeeded(Always()))
示例11: test_start_responding
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_start_responding(self, token):
"""
Calling ``start_responding`` makes an appropriate entry appear in the
host map.
"""
ckey = RSA_KEY_512_RAW
challenge = challenges.TLSSNI01(token=token)
response = challenge.response(RSA_KEY_512)
server_name = response.z_domain.decode('ascii')
host_map = {}
responder = TLSSNI01Responder()
responder._generate_private_key = lambda key_type: ckey
wrapped_host_map = responder.wrap_host_map(host_map)
self.assertThat(wrapped_host_map, Not(Contains(server_name)))
responder.start_responding(u'example.com', challenge, response)
self.assertThat(
wrapped_host_map.get(server_name.encode('utf-8')).certificate,
MatchesPredicate(response.verify_cert, '%r does not verify'))
# Starting twice before stopping doesn't break things
responder.start_responding(u'example.com', challenge, response)
self.assertThat(
wrapped_host_map.get(server_name.encode('utf-8')).certificate,
MatchesPredicate(response.verify_cert, '%r does not verify'))
responder.stop_responding(u'example.com', challenge, response)
self.assertThat(wrapped_host_map, Not(Contains(server_name)))
示例12: _responder_factory
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def _responder_factory(self, zone_name=u'example.com'):
responder = LibcloudDNSResponder.create(
reactor=SynchronousReactorThreads(),
driver_name='dummy',
username='ignored',
password='ignored',
zone_name=zone_name,
settle_delay=0.0)
if zone_name is not None:
responder._driver.create_zone(zone_name)
responder._thread_pool, self._perform = createMemoryWorker()
return responder
示例13: test_timer_errors
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_timer_errors(self):
"""
If the timed check fails (for example, because registration fails), the
error should be caught and logged.
"""
with AcmeFixture(client=FailingClient()) as fixture:
fixture.service.startService()
self.assertThat(
fixture.service._check_certs(),
succeeded(Always()))
self.assertThat(flush_logged_errors(), HasLength(2))
示例14: test_request_huffman_decoder
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_request_huffman_decoder(self):
assert (
decode_huffman(b'\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\xff') ==
b"www.example.com"
)
assert decode_huffman(b'\xa8\xeb\x10d\x9c\xbf') == b"no-cache"
assert decode_huffman(b'%\xa8I\xe9[\xa9}\x7f') == b"custom-key"
assert (
decode_huffman(b'%\xa8I\xe9[\xb8\xe8\xb4\xbf') == b"custom-value"
)
示例15: test_request_huffman_encode
# 需要导入模块: import hypothesis [as 别名]
# 或者: from hypothesis import example [as 别名]
def test_request_huffman_encode(self):
encoder = HuffmanEncoder(REQUEST_CODES, REQUEST_CODES_LENGTH)
assert (
encoder.encode(b"www.example.com") ==
b'\xf1\xe3\xc2\xe5\xf2:k\xa0\xab\x90\xf4\xff'
)
assert encoder.encode(b"no-cache") == b'\xa8\xeb\x10d\x9c\xbf'
assert encoder.encode(b"custom-key") == b'%\xa8I\xe9[\xa9}\x7f'
assert (
encoder.encode(b"custom-value") == b'%\xa8I\xe9[\xb8\xe8\xb4\xbf'
)