Skip to content

Commit 0e4e270

Browse files
authored
Test against multiple SQLite versions (#654)
* Test against pre-upsert SQLite 3.23.1 Borrowed from simonw/datasette@8f86d2af6 * Try this on Python 3.9 * select ... from pragma_function_list() Refs #654 (comment) * Fix spelling error * Compatible with latest black * Skip plugin test that needs pragma_function_list Refs #654 (comment) * Ran cog
1 parent 88a83f0 commit 0e4e270

File tree

5 files changed

+60
-29
lines changed

5 files changed

+60
-29
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test SQLite versions
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
test:
10+
runs-on: ${{ matrix.platform }}
11+
continue-on-error: true
12+
strategy:
13+
matrix:
14+
platform: [ubuntu-latest]
15+
python-version: ["3.9"]
16+
sqlite-version: [
17+
"3.46",
18+
"3.23.1", # 2018-04-10, before UPSERT
19+
]
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
allow-prereleases: true
27+
cache: pip
28+
cache-dependency-path: setup.py
29+
- name: Set up SQLite ${{ matrix.sqlite-version }}
30+
uses: asg017/sqlite-versions@71ea0de37ae739c33e447af91ba71dda8fcf22e6
31+
with:
32+
version: ${{ matrix.sqlite-version }}
33+
cflags: "-DSQLITE_ENABLE_DESERIALIZE -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_JSON1"
34+
- run: python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
35+
- name: Install dependencies
36+
run: |
37+
pip install -e '.[test]'
38+
pip freeze
39+
- name: Run tests
40+
run: |
41+
python -m pytest

docs/cli-reference.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,23 +1045,6 @@ disable-fts
10451045
-h, --help Show this message and exit.
10461046

10471047

1048-
.. _cli_ref_tui:
1049-
1050-
tui
1051-
===
1052-
1053-
See :ref:`cli_tui`.
1054-
1055-
::
1056-
1057-
Usage: sqlite-utils tui [OPTIONS]
1058-
1059-
Open Textual TUI.
1060-
1061-
Options:
1062-
-h, --help Show this message and exit.
1063-
1064-
10651048
.. _cli_ref_optimize:
10661049

10671050
optimize

sqlite_utils/db.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,37 +237,30 @@ class Default:
237237

238238
class AlterError(Exception):
239239
"Error altering table"
240-
pass
241240

242241

243242
class NoObviousTable(Exception):
244243
"Could not tell which table this operation refers to"
245-
pass
246244

247245

248246
class NoTable(Exception):
249247
"Specified table does not exist"
250-
pass
251248

252249

253250
class BadPrimaryKey(Exception):
254251
"Table does not have a single obvious primary key"
255-
pass
256252

257253

258254
class NotFoundError(Exception):
259255
"Record not found"
260-
pass
261256

262257

263258
class PrimaryKeyRequired(Exception):
264259
"Primary key needs to be specified"
265-
pass
266260

267261

268262
class InvalidColumns(Exception):
269263
"Specified columns do not exist"
270-
pass
271264

272265

273266
class DescIndex(str):
@@ -3203,7 +3196,7 @@ def insert(
32033196
:param not_null: Set of strings specifying columns that should be ``NOT NULL``.
32043197
:param defaults: Dictionary specifying default values for specific columns.
32053198
:param hash_id: Name of a column to create and use as a primary key, where the
3206-
value of thet primary key will be derived as a SHA1 hash of the other column values
3199+
value of that primary key will be derived as a SHA1 hash of the other column values
32073200
in the record. ``hash_id="id"`` is a common column name used for this.
32083201
:param alter: Boolean, should any missing columns be added automatically?
32093202
:param ignore: Boolean, if a record already exists with this primary key, ignore this insert.
@@ -3852,7 +3845,7 @@ def jsonify_if_needed(value):
38523845

38533846

38543847
def resolve_extracts(
3855-
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]]
3848+
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]],
38563849
) -> dict:
38573850
if extracts is None:
38583851
extracts = {}

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ def test_query_json_with_json_cols(db_path):
916916

917917
@pytest.mark.parametrize(
918918
"content,is_binary",
919-
[(b"\x00\x0Fbinary", True), ("this is text", False), (1, False), (1.5, False)],
919+
[(b"\x00\x0fbinary", True), ("this is text", False), (1, False), (1.5, False)],
920920
)
921921
def test_query_raw(db_path, content, is_binary):
922922
Database(db_path)["files"].insert({"content": content})
@@ -931,7 +931,7 @@ def test_query_raw(db_path, content, is_binary):
931931

932932
@pytest.mark.parametrize(
933933
"content,is_binary",
934-
[(b"\x00\x0Fbinary", True), ("this is text", False), (1, False), (1.5, False)],
934+
[(b"\x00\x0fbinary", True), ("this is text", False), (1, False), (1.5, False)],
935935
)
936936
def test_query_raw_lines(db_path, content, is_binary):
937937
Database(db_path)["files"].insert_all({"content": content} for _ in range(3))

tests/test_plugins.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
from click.testing import CliRunner
22
import click
33
import importlib
4+
import pytest
45
from sqlite_utils import cli, Database, hookimpl, plugins
56

67

8+
def _supports_pragma_function_list():
9+
db = Database(memory=True)
10+
try:
11+
db.execute("select * from pragma_function_list()")
12+
except Exception:
13+
return False
14+
return True
15+
16+
717
def test_register_commands():
818
importlib.reload(cli)
919
assert plugins.get_plugins() == []
@@ -37,6 +47,10 @@ def hello_world():
3747
assert plugins.get_plugins() == []
3848

3949

50+
@pytest.mark.skipif(
51+
not _supports_pragma_function_list(),
52+
reason="Needs SQLite version that supports pragma_function_list()",
53+
)
4054
def test_prepare_connection():
4155
importlib.reload(cli)
4256
assert plugins.get_plugins() == []
@@ -54,7 +68,7 @@ def _functions(db):
5468
return [
5569
row[0]
5670
for row in db.execute(
57-
"select distinct name from pragma_function_list order by 1"
71+
"select distinct name from pragma_function_list() order by 1"
5872
).fetchall()
5973
]
6074

0 commit comments

Comments
 (0)