my eye

test_sqlyte.py

Raw

import pathlib
import shutil

import sqlyte


def setup_module(module):
    shutil.rmtree("_test_data", ignore_errors=True)
    pathlib.Path("_test_data").mkdir()


def test_simple_usage():
    db = sqlyte.db("_test_data/1.db", sqlyte.Model("TestDB", testing={"name": "TEXT"}))
    assert len(db.columns("testing")) == 1
    db.insert("testing", name="foo")
    db.insert("testing", name="bar")
    assert len(db.select("testing")) == 2
    db.update("testing", name="bat", where="name = ?", vals=["bar"])
    db.delete("testing", where="name = ?", vals=["bat"])
    assert len(db.select("testing")) == 1


def test_transactions():
    db = sqlyte.db("_test_data/2.db", sqlyte.Model("test", testing={"name": "TEXT"}))
    with db.conn:
        cursor = sqlyte.Cursor(db.conn.cursor())
        cursor.insert("testing", name="bar")