sqlite-utils/tests/test_recreate.py
Simon Willison 69a1c0d960
Fixes for Ruff>=0.16.0 (#814)
* Automated upgrades by Ruff

    uvx --with 'ruff>=0.16.0' ruff check . --fix --unsafe-fixes

* Fix remaining Ruff errors with GPT-5.6 Sol high

https://gist.github.com/simonw/6da7906a9fea6e90da131c21a9055199

* Fix flake E501 long lines
* New Protocol for migrations to make ty happy
2026-07-25 14:53:12 -07:00

40 lines
1.1 KiB
Python

import pathlib
import sqlite3
import pytest
from sqlite_utils import Database
def test_recreate_ignored_for_in_memory():
# None of these should raise an exception:
Database(memory=True, recreate=False)
Database(memory=True, recreate=True)
Database(":memory:", recreate=False)
Database(":memory:", recreate=True)
def test_recreate_not_allowed_for_connection():
conn = sqlite3.connect(":memory:")
try:
with pytest.raises(ValueError):
Database(conn, recreate=True)
finally:
conn.close()
@pytest.mark.parametrize(
"use_path,create_file_first",
[(True, True), (True, False), (False, True), (False, False)],
)
def test_recreate(tmp_path, use_path, create_file_first):
filepath = str(tmp_path / "data.db")
if use_path:
filepath = pathlib.Path(filepath)
if create_file_first:
db = Database(filepath)
db["t1"].insert({"foo": "bar"})
assert ["t1"] == db.table_names()
db.close()
Database(filepath, recreate=True)["t2"].insert({"foo": "bar"})
assert ["t2"] == Database(filepath).table_names()