Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions sqlite_export_for_ynab/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def sync(token: str, db: Path, full_refresh: bool) -> None:
db.parent.mkdir(parents=True, exist_ok=True)

with sqlite3.connect(db) as con:
con.row_factory = _row_factory
con.row_factory = sqlite3.Row
cur = con.cursor()

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


def _row_factory(c: sqlite3.Cursor, row: tuple[Any, ...]) -> dict[str, Any]:
return {d[0]: r for d, r in zip(c.description, row, strict=True)}


def contents(filename: str) -> str:
return (resources.files(ddl) / filename).read_text()

Expand Down
7 changes: 3 additions & 4 deletions testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest
from aioresponses import aioresponses

from sqlite_export_for_ynab._main import _row_factory
from sqlite_export_for_ynab._main import contents

PLAN_ID_1 = str(uuid4())
Expand Down Expand Up @@ -326,7 +325,7 @@
@pytest.fixture
def cur():
with sqlite3.connect(":memory:") as con:
con.row_factory = _row_factory
con.row_factory = sqlite3.Row
cursor = con.cursor()
cursor.executescript(contents("create-relations.sql"))
yield cursor
Expand All @@ -338,8 +337,8 @@ def mock_aioresponses():
yield m


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


TOKEN = f"token-{uuid4()}"
Expand Down
4 changes: 2 additions & 2 deletions tests/_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_get_last_knowledge_of_server(cur):
def test_insert_plans(cur):
insert_plans(cur, PLANS, LKOS)
cur.execute("SELECT * FROM plans ORDER BY name")
assert cur.fetchall() == [
assert [strip_nones(d) for d in cur.fetchall()] == [
{
"id": PLAN_ID_1,
"name": PLANS[0]["name"],
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_insert_accounts(cur):
]

cur.execute("SELECT * FROM account_periodic_values ORDER BY name")
assert cur.fetchall() == [
assert [strip_nones(d) for d in cur.fetchall()] == [
{
"account_id": ACCOUNT_ID_1,
"plan_id": PLAN_ID_1,
Expand Down
Loading