本文整理汇总了Python中hypothesis.database.ExampleDatabase.close方法的典型用法代码示例。如果您正苦于以下问题:Python ExampleDatabase.close方法的具体用法?Python ExampleDatabase.close怎么用?Python ExampleDatabase.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.database.ExampleDatabase
的用法示例。
在下文中一共展示了ExampleDatabase.close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_will_handle_a_really_weird_failure
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_will_handle_a_really_weird_failure(self, s):
db = ExampleDatabase()
@given(specifier)
@Settings(
settings,
database=db,
max_examples=max_examples,
min_satisfying_examples=2,
)
@seed(s)
def nope(x):
s = hashlib.sha1(repr(x).encode('utf-8')).digest()
assert Random(s).randint(0, 1) == Random(s).randint(0, 1)
if Random(s).randint(0, 1):
raise Rejected('%r with digest %r' % (
x, s
))
try:
try:
nope()
except Rejected:
pass
try:
nope()
except Rejected:
pass
finally:
db.close()
示例2: test_will_handle_a_really_weird_failure
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_will_handle_a_really_weird_failure(self):
db = ExampleDatabase()
@given(
specifier,
settings=Settings(
database=db,
max_examples=max_examples,
min_satisfying_examples=2,
average_list_length=2.0,
)
)
def nope(x):
s = hashlib.sha1(show(x).encode('utf-8')).digest()
if Random(s).randint(0, 1):
raise Rejected()
try:
try:
nope()
except Rejected:
pass
try:
nope()
except Rejected:
pass
finally:
db.close()
示例3: test_will_handle_a_really_weird_failure
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_will_handle_a_really_weird_failure(self, rnd):
db = ExampleDatabase()
@given(
specifier,
settings=Settings(
database=db,
max_examples=max_examples,
min_satisfying_examples=2,
average_list_length=2.0,
), random=rnd
)
def nope(x):
s = hashlib.sha1(repr(x).encode(u'utf-8')).digest()
assert Random(s).randint(0, 1) == Random(s).randint(0, 1)
if Random(s).randint(0, 1):
raise Rejected(u'%r with digest %r' % (
x, s
))
try:
try:
nope()
except Rejected:
pass
try:
nope()
except Rejected:
pass
finally:
db.close()
示例4: via_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def via_database(spec, strat, template):
db = ExampleDatabase()
try:
s = db.storage_for(strat, strat)
s.save(template)
results = list(s.fetch())
assert len(results) == 1
return results[0]
finally:
db.close()
示例5: test_can_round_trip_through_the_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_can_round_trip_through_the_database(self, template, rnd):
empty_db = ExampleDatabase(backend=SQLiteBackend(":memory:"))
try:
storage = empty_db.storage("round trip")
storage.save(template, strat)
values = list(storage.fetch(strat))
assert len(values) == 1
assert strat.to_basic(template) == strat.to_basic(values[0])
finally:
empty_db.close()
示例6: via_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def via_database(spec, strat, template):
db = ExampleDatabase()
key = u'via_database'
try:
s = db.storage(key)
s.save(template, strat)
results = list(s.fetch(strat))
assert len(results) == 1
return results[0]
finally:
db.close()
示例7: test_will_find_a_failure_from_the_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_will_find_a_failure_from_the_database(self):
db = ExampleDatabase()
@given(specifier, settings=Settings(max_examples=10, database=db))
def nope(x):
raise Rejected()
try:
for i in hrange(3):
self.assertRaises(Rejected, nope) # pragma: no cover
finally:
db.close()
示例8: test_can_round_trip_through_the_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_can_round_trip_through_the_database(self, template):
empty_db = ExampleDatabase(
backend=SQLiteBackend(':memory:'),
)
try:
storage = empty_db.storage_for(specifier)
storage.save(template)
values = list(storage.fetch())
assert len(values) == 1
assert strat.to_basic(template) == strat.to_basic(values[0])
finally:
empty_db.close()
示例9: run_round_trip
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def run_round_trip(specifier, value, format=None, backend=None):
if backend is not None:
backend = backend()
else:
backend = SQLiteBackend()
db = ExampleDatabase(format=format, backend=backend)
try:
storage = db.storage(u'round trip')
storage.save(value, specifier)
saved = list(storage.fetch(specifier))
assert len(saved) == 1
assert specifier.to_basic(saved[0]) == specifier.to_basic(value)
finally:
db.close()
示例10: test_will_find_a_failure_from_the_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_will_find_a_failure_from_the_database():
db = ExampleDatabase()
class Rejected(Exception):
pass
@given(dav_strategy, settings=Settings(max_examples=10, database=db))
def nope(x):
raise Rejected()
try:
with pytest.raises(Rejected):
nope() # pragma: no branch
finally:
db.close()
示例11: test_can_handle_more_than_max_iterations_in_db
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_can_handle_more_than_max_iterations_in_db():
"""This is checking that if we store a large number of examples in the DB
and then subsequently reduce max_examples below that count, we a) don't
error (which is how this bug was found) and b) stop at max_examples rather
than continuing onwards."""
db = ExampleDatabase()
try:
settings = hs.Settings(database=db, max_examples=10, max_iterations=10)
seen = []
first = [True]
for _ in range(10):
first[0] = True
@given(integers(), settings=settings)
def test_seen(x):
if x not in seen:
if first[0]:
first[0] = False
seen.append(x)
if x not in seen:
raise ValueError(u'Weird')
try:
test_seen()
except ValueError:
pass
assert len(seen) >= 3
seen = []
@given(
integers(), settings=hs.Settings(
max_examples=1, max_iterations=2, database=db))
def test_seen(x):
seen.append(x)
assume(False)
with pytest.raises(Unsatisfiable):
test_seen()
assert len(seen) == 2
finally:
db.close()
示例12: test_can_handle_more_than_max_examples_values_in_db
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_can_handle_more_than_max_examples_values_in_db():
"""This is checking that if we store a large number of examples in the DB
and then subsequently reduce max_examples below that count, we a) don't
error (which is how this bug was found) and b) stop at max_examples rather
than continuing onwards."""
db = ExampleDatabase()
try:
settings = hs.settings(database=db, max_examples=10)
seen = []
first = [True]
for _ in range(10):
first[0] = True
@given(integers())
@settings
def test_seen(x):
if x not in seen:
if first[0]:
first[0] = False
seen.append(x)
assert x in seen
try:
test_seen()
except AssertionError:
pass
assert len(seen) >= 2
seen = []
@given(integers())
@hs.settings(max_examples=1, database=db)
def test_seen(x):
seen.append(x)
test_seen()
assert len(seen) == 1
finally:
db.close()
示例13: test_can_time_out_when_reading_from_database
# 需要导入模块: from hypothesis.database import ExampleDatabase [as 别名]
# 或者: from hypothesis.database.ExampleDatabase import close [as 别名]
def test_can_time_out_when_reading_from_database():
should_timeout = False
limit = 0
examples = []
db = ExampleDatabase()
try:
@given(integers(), settings=hs.Settings(timeout=0.1, database=db))
def test_run_test(x):
examples.append(x)
if should_timeout:
time.sleep(0.5)
assert x >= limit
for i in hrange(10):
limit = -i
examples = []
with pytest.raises(AssertionError):
test_run_test()
examples = []
limit = 0
with pytest.raises(AssertionError):
test_run_test()
limit = min(examples) - 1
should_timeout = True
examples = []
with pytest.raises(Timeout):
test_run_test()
assert len(examples) == 1
finally:
db.close()