Skip to content

Commit c6b720b

Browse files
authored
Use sqlite3.Row (#189)
1 parent e62d74d commit c6b720b

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

sqlite_export_for_ynab/_main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def sync(token: str, db: Path, full_refresh: bool) -> None:
106106
db.parent.mkdir(parents=True, exist_ok=True)
107107

108108
with sqlite3.connect(db) as con:
109-
con.row_factory = _row_factory
109+
con.row_factory = sqlite3.Row
110110
cur = con.cursor()
111111

112112
if full_refresh:
@@ -185,10 +185,6 @@ async def sync(token: str, db: Path, full_refresh: bool) -> None:
185185
print("Done")
186186

187187

188-
def _row_factory(c: sqlite3.Cursor, row: tuple[Any, ...]) -> dict[str, Any]:
189-
return {d[0]: r for d, r in zip(c.description, row, strict=True)}
190-
191-
192188
def contents(filename: str) -> str:
193189
return (resources.files(ddl) / filename).read_text()
194190

testing/fixtures.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99
from aioresponses import aioresponses
1010

11-
from sqlite_export_for_ynab._main import _row_factory
1211
from sqlite_export_for_ynab._main import contents
1312

1413
PLAN_ID_1 = str(uuid4())
@@ -326,7 +325,7 @@
326325
@pytest.fixture
327326
def cur():
328327
with sqlite3.connect(":memory:") as con:
329-
con.row_factory = _row_factory
328+
con.row_factory = sqlite3.Row
330329
cursor = con.cursor()
331330
cursor.executescript(contents("create-relations.sql"))
332331
yield cursor
@@ -338,8 +337,8 @@ def mock_aioresponses():
338337
yield m
339338

340339

341-
def strip_nones(d: dict[str, Any]) -> dict[str, Any]:
342-
return {k: v for k, v in d.items() if v is not None}
340+
def strip_nones(d: sqlite3.Row) -> dict[str, Any]:
341+
return {k: v for k, v in dict(d).items() if v is not None}
343342

344343

345344
TOKEN = f"token-{uuid4()}"

tests/_main_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_get_last_knowledge_of_server(cur):
106106
def test_insert_plans(cur):
107107
insert_plans(cur, PLANS, LKOS)
108108
cur.execute("SELECT * FROM plans ORDER BY name")
109-
assert cur.fetchall() == [
109+
assert [strip_nones(d) for d in cur.fetchall()] == [
110110
{
111111
"id": PLAN_ID_1,
112112
"name": PLANS[0]["name"],
@@ -170,7 +170,7 @@ def test_insert_accounts(cur):
170170
]
171171

172172
cur.execute("SELECT * FROM account_periodic_values ORDER BY name")
173-
assert cur.fetchall() == [
173+
assert [strip_nones(d) for d in cur.fetchall()] == [
174174
{
175175
"account_id": ACCOUNT_ID_1,
176176
"plan_id": PLAN_ID_1,

0 commit comments

Comments
 (0)