mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-14 05:14:22 +02:00
Use db.table() and db.view() in tests, closes #838
This commit is contained in:
parent
43d5d3331f
commit
38fe466700
43 changed files with 1321 additions and 1254 deletions
|
|
@ -18,7 +18,7 @@ def test_enable_disable_wal(db_path_tmpdir):
|
|||
assert "test.db-wal" not in [f.basename for f in tmpdir.listdir()]
|
||||
db.enable_wal()
|
||||
assert "wal" == db.journal_mode
|
||||
db["test"].insert({"foo": "bar"})
|
||||
db.table("test").insert({"foo": "bar"})
|
||||
assert "test.db-wal" in [f.basename for f in tmpdir.listdir()]
|
||||
db.disable_wal()
|
||||
assert "delete" == db.journal_mode
|
||||
|
|
@ -27,25 +27,25 @@ def test_enable_disable_wal(db_path_tmpdir):
|
|||
|
||||
def test_enable_wal_inside_transaction_raises(db_path_tmpdir):
|
||||
db, _path, _tmpdir = db_path_tmpdir
|
||||
db["test"].insert({"id": 1}, pk="id")
|
||||
db.table("test").insert({"id": 1}, pk="id")
|
||||
with pytest.raises(TransactionError), db.atomic():
|
||||
db["test"].insert({"id": 2}, pk="id")
|
||||
db.table("test").insert({"id": 2}, pk="id")
|
||||
db.enable_wal()
|
||||
# The atomic() block must have rolled back cleanly and the
|
||||
# journal mode must be unchanged
|
||||
assert db.journal_mode == "delete"
|
||||
assert [r["id"] for r in db["test"].rows] == [1]
|
||||
assert [r["id"] for r in db.table("test").rows] == [1]
|
||||
|
||||
|
||||
def test_disable_wal_inside_transaction_raises(db_path_tmpdir):
|
||||
db, _path, _tmpdir = db_path_tmpdir
|
||||
db.enable_wal()
|
||||
db["test"].insert({"id": 1}, pk="id")
|
||||
db.table("test").insert({"id": 1}, pk="id")
|
||||
with pytest.raises(TransactionError), db.atomic():
|
||||
db["test"].insert({"id": 2}, pk="id")
|
||||
db.table("test").insert({"id": 2}, pk="id")
|
||||
db.disable_wal()
|
||||
assert db.journal_mode == "wal"
|
||||
assert [r["id"] for r in db["test"].rows] == [1]
|
||||
assert [r["id"] for r in db.table("test").rows] == [1]
|
||||
|
||||
|
||||
def test_ensure_autocommit_on(db_path_tmpdir):
|
||||
|
|
@ -65,9 +65,9 @@ def test_enable_wal_noop_inside_transaction_is_allowed(db_path_tmpdir):
|
|||
db, _path, _tmpdir = db_path_tmpdir
|
||||
db.enable_wal()
|
||||
with db.atomic():
|
||||
db["test"].insert({"id": 1}, pk="id")
|
||||
db.table("test").insert({"id": 1}, pk="id")
|
||||
db.enable_wal()
|
||||
assert [r["id"] for r in db["test"].rows] == [1]
|
||||
assert [r["id"] for r in db.table("test").rows] == [1]
|
||||
|
||||
|
||||
def test_ensure_autocommit_on_inside_transaction_raises(db_path_tmpdir):
|
||||
|
|
@ -75,7 +75,7 @@ def test_ensure_autocommit_on_inside_transaction_raises(db_path_tmpdir):
|
|||
# effect, silently breaking the caller's rollback guarantee - so
|
||||
# entering autocommit mode with a transaction open is an error
|
||||
db, _path, _tmpdir = db_path_tmpdir
|
||||
db["test"].insert({"id": 1}, pk="id")
|
||||
db.table("test").insert({"id": 1}, pk="id")
|
||||
db.begin()
|
||||
db.execute("insert into test (id) values (2)")
|
||||
with pytest.raises(TransactionError), db.ensure_autocommit_on():
|
||||
|
|
@ -83,4 +83,4 @@ def test_ensure_autocommit_on_inside_transaction_raises(db_path_tmpdir):
|
|||
# The transaction is still open and can still be rolled back
|
||||
assert db.conn.in_transaction
|
||||
db.rollback()
|
||||
assert [r["id"] for r in db["test"].rows] == [1]
|
||||
assert [r["id"] for r in db.table("test").rows] == [1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue