Exemple #1
0
def test_filepath_db():
    from db import DemoDB

    # 测试指定路径
    filepath_db = DemoDB().with_context("test_filepath").with_db_filepath("card_secrets/_local_test.txt")
    filepath_db.load()
    print(filepath_db.int_val)
    filepath_db.int_val = 666
    filepath_db.save()
    print(filepath_db.prepare_env_and_get_db_filepath())
Exemple #2
0
    def _test(db: DemoDB, save_inc: int, update_inc: int):
        # init
        db.int_val = 1

        # save
        db.int_val += save_inc
        db.save()

        assert_load_same(db, 1 + save_inc)

        def _cb(val: DemoDB) -> Any:
            val.int_val += update_inc
            return val.int_val

        db.update(_cb)

        assert_load_same(db, 1 + save_inc + update_inc)