コード例 #1
0
ファイル: test_db_intro.py プロジェクト: dcribb19/bitesofpy
def test_wrong_pk():
    with pytest.raises(SchemaError) as e:
        with DB() as db:
            db.create("ninjas", DB_SCHEMA, "ID")

    assert str(
        e.value) == "The provided primary key must be part of the schema."
コード例 #2
0
ファイル: test_db_intro.py プロジェクト: dcribb19/bitesofpy
def test_create(table, schema, pk):
    with DB() as db:
        assert db.num_transactions == 0
        db.create(table, schema, pk)
        query = (
            f"SELECT name FROM sqlite_master WHERE type= 'table' AND name='{table}';"
        )
        output = db.cursor.execute(query).fetchall()
        assert len(output) == 1
        assert db.num_transactions == 0
コード例 #3
0
ファイル: test_db_intro.py プロジェクト: dcribb19/bitesofpy
def test_empty_db():
    db = DB()
    assert db.location == ":memory:"
    assert db.cursor is None
    assert db.connection is None
    assert db.table_schemas == {}
コード例 #4
0
ファイル: test_db_intro.py プロジェクト: dcribb19/bitesofpy
def db():
    with DB() as db:
        db.create("ninjas", DB_SCHEMA, "ninja")
        db.insert("ninjas", NINJAS)

        yield db