本文整理汇总了Python中binlog.model.Model.open方法的典型用法代码示例。如果您正苦于以下问题:Python Model.open方法的具体用法?Python Model.open怎么用?Python Model.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类binlog.model.Model
的用法示例。
在下文中一共展示了Model.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_not_nested_inside_nested_connection
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_not_nested_inside_nested_connection(tmpdir):
with Model.open(tmpdir) as conn1:
with Model.open(tmpdir) as conn2_a:
assert conn1 is conn2_a
with Model.open(tmpdir) as conn2_b:
assert conn1 is conn2_b
示例2: test_cant_remove_if_is_not_acked
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_cant_remove_if_is_not_acked(tmpdir):
with Model.open(tmpdir) as db:
e0 = db.create(test='data0')
db.register_reader('reader1')
assert db.remove(e0) is False
示例3: test_ack_on_anonymous_reader
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_ack_on_anonymous_reader(tmpdir):
with Model.open(tmpdir) as db:
entry = db.create(test='data')
with db.reader() as reader:
with pytest.raises(RuntimeError):
reader.ack(reader[0])
示例4: test_create_is_incremental
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_create_is_incremental(tmpdir):
with Model.open(tmpdir) as db:
entry0 = db.create()
entry1 = db.create()
assert entry0.pk == 0
assert entry1.pk == 1
示例5: test_slice_step_cannot_be_zero
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_slice_step_cannot_be_zero(tmpdir):
with Model.open(tmpdir) as db:
entries = [Model(idx=i) for i in range(4)]
db.bulk_create(entries)
with db.reader() as reader:
with pytest.raises(ValueError):
reader[::0]
示例6: test_reader_filter_exact
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_reader_filter_exact(tmpdir):
with Model.open(tmpdir) as db:
entries = [Model(idx=i, even=(i % 2 == 0)) for i in range(100)]
db.bulk_create(entries)
with db.reader() as r:
for a, b in zip_longest(r.filter(even=True), range(0, 100, 2)):
assert a.pk == b
示例7: test_can_ack_with_pk
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_can_ack_with_pk(tmpdir):
with Model.open(tmpdir) as db:
entry = db.create(test='data')
db.register_reader('myreader')
with db.reader('myreader') as reader:
reader.ack(0)
assert 0 in reader.registry
示例8: test_reader_unknown_negative_index
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_reader_unknown_negative_index(tmpdir):
with Model.open(tmpdir) as db:
db.create(test='test')
db.register_reader('myreader')
with db.reader('myreader') as reader:
with pytest.raises(IndexError):
reader[-2]
示例9: test_cannot_use_same_connection_from_multiple_threads
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_cannot_use_same_connection_from_multiple_threads(tmpdir, io_method):
conn = Model.open(tmpdir)
with ThreadPoolExecutor(max_workers=1) as pool:
res = pool.submit(getattr(conn, io_method))
with pytest.raises(BadUsageError):
res.result()
示例10: test_list_readers
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_list_readers(readers):
assume(len(readers & RESERVED_READER_NAMES) == 0)
with TemporaryDirectory() as tmpdir:
with Model.open(tmpdir) as db:
for name in readers:
db.register_reader(name)
assert set(db.list_readers()) == readers
示例11: test_ack_is_not_effective_before_commit
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_ack_is_not_effective_before_commit(tmpdir):
with Model.open(tmpdir) as db:
e0 = db.create(test='data0')
db.register_reader('myreader')
with db.reader('myreader') as reader1:
reader1.ack(e0)
with db.reader('myreader') as reader2:
assert list(reader2)
示例12: test_slice_negative_start_stop_step
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_slice_negative_start_stop_step(tmpdir, start, stop, step):
with Model.open(tmpdir) as db:
entries = [Model(idx=i) for i in range(4)]
db.bulk_create(entries)
with db.reader() as reader:
expected = list(entries[start:stop:step])
current = list(reader[start:stop:step])
assert expected == current
示例13: test_reader_reads_bulk_create
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_reader_reads_bulk_create(tmpdir):
with Model.open(tmpdir) as db:
entries = [Model(idx=i) for i in range(10)]
db.bulk_create(entries)
db.register_reader('myreader')
with db.reader('myreader') as reader:
for current, expected in zip_longest(reader, entries):
assert current == expected
示例14: test_can_remove_if_is_acked
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_can_remove_if_is_acked(tmpdir):
with Model.open(tmpdir) as db:
e0 = db.create(test='data0')
db.register_reader('reader1')
with db.reader('reader1') as reader:
reader.ack(e0)
assert db.remove(e0) is True
示例15: test_reader_index
# 需要导入模块: from binlog.model import Model [as 别名]
# 或者: from binlog.model.Model import open [as 别名]
def test_reader_index(tmpdir):
with Model.open(tmpdir) as db:
entries = [Model(idx=i) for i in range(10)]
db.bulk_create(entries)
db.register_reader('myreader')
with db.reader('myreader') as reader:
for e in entries:
assert e == reader[e['idx']]