本文整理汇总了Python中binlog.model.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save_do_not_replace
def test_save_do_not_replace(tmpdir):
from binlog.model import Model
env = lmdb.open(str(tmpdir), max_dbs=1)
with env.begin(write=True) as txn:
db = env.open_db(b'test', txn=txn)
m = Model(data=0)
assert m.save(0, db, txn)
with env.begin(write=False) as txn:
db = env.open_db(b'test', txn=txn)
with txn.cursor(db) as cursor:
first = cursor.get(struct.pack("!Q", 0))
with env.begin(write=True) as txn:
db = env.open_db(b'test', txn=txn)
m = Model(data=1)
assert not m.save(0, db, txn)
with env.begin(write=False) as txn:
db = env.open_db(b'test', txn=txn)
with txn.cursor(db) as cursor:
second = cursor.get(struct.pack("!Q", 0))
assert first == second
示例2: test_not_nested_inside_nested_connection
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
示例3: test_save_store_data
def test_save_store_data(tmpdir):
from binlog.model import Model
env = lmdb.open(str(tmpdir), max_dbs=1)
with env.begin(write=True) as txn:
db = env.open_db(b'test', txn=txn)
m = Model(data=0)
assert m.save(0, db, txn)
with env.begin(write=False) as txn:
db = env.open_db(b'test', txn=txn)
with txn.cursor(db) as cursor:
assert cursor.get(struct.pack("!Q", 0))
示例4: test_ack_on_anonymous_reader
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])
示例5: test_cant_remove_if_is_not_acked
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
示例6: test_reader_unknown_negative_index
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]
示例7: test_create_is_incremental
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
示例8: test_slice_step_cannot_be_zero
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]
示例9: test_reader_filter_exact
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
示例10: test_can_ack_with_pk
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
示例11: test_cannot_use_same_connection_from_multiple_threads
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()
示例12: test_list_readers
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
示例13: test_reader_index
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']]
示例14: test_slice_negative_start_stop_step
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
示例15: test_can_remove_if_is_acked
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