当前位置: 首页>>代码示例>>Python>>正文


Python model.Model类代码示例

本文整理汇总了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
开发者ID:nilp0inter,项目名称:binlog,代码行数:26,代码来源:test_10_model.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:9,代码来源:test_30_connection_with_manager.py

示例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))
开发者ID:nilp0inter,项目名称:binlog,代码行数:13,代码来源:test_10_model.py

示例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])
开发者ID:nilp0inter,项目名称:binlog,代码行数:7,代码来源:test_50_ack.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:7,代码来源:test_60_remove_entry.py

示例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]
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_44_reader_get_index.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_30_model_create.py

示例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]
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_45_reader_slicing.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_40_reader.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_50_ack.py

示例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()
开发者ID:nilp0inter,项目名称:binlog,代码行数:8,代码来源:test_20_connection.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:9,代码来源:test_50_list_readers.py

示例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']]
开发者ID:nilp0inter,项目名称:binlog,代码行数:9,代码来源:test_44_reader_get_index.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:9,代码来源:test_45_reader_slicing.py

示例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
开发者ID:nilp0inter,项目名称:binlog,代码行数:9,代码来源:test_60_remove_entry.py


注:本文中的binlog.model.Model类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。