Skip to content

Commit

Permalink
Merge pull request #41 from AnswerDotAI/test-fixit
Browse files Browse the repository at this point in the history
Fix remaining failing tests
  • Loading branch information
jph00 authored Nov 14, 2024
2 parents 482b375 + 48667fa commit 96ac87d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion sqlite_minutils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3652,10 +3652,13 @@ def jsonify_if_needed(value):


def resolve_extracts(
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str]]]
extracts: Optional[Union[Dict[str, str], List[str], Tuple[str], Tuple[Tuple[str]]]]
) -> dict:
if extracts is None:
extracts = {}
if isinstance(extracts, (list, tuple)) and len(extracts) and any(isinstance(x, (list, tuple)) for x in extracts):
# Handles nested lists/tuples
extracts = dict(extracts)
if isinstance(extracts, (list, tuple)):
extracts = {item: item for item in extracts}
return extracts
Expand Down
2 changes: 0 additions & 2 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ def test_create_table_column_order(fresh_db, use_table_factory):
((("one_id", "one", "id", "five"), ("two_id", "two", "id")), AssertionError),
# Likewise a bad column:
((("one_id", "one", "id2"),), AlterError),
# Or a list of dicts
(({"one_id": "one"},), AssertionError),
),
)
@pytest.mark.parametrize("use_table_factory", [True, False])
Expand Down
13 changes: 10 additions & 3 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sqlite_minutils.db import ForeignKey
from sqlite_minutils.utils import OperationalError
from sqlite3 import IntegrityError
import pytest


Expand Down Expand Up @@ -384,10 +385,16 @@ def test_transform_verify_foreign_keys(fresh_db):
fresh_db["books"].insert(
{"id": 1, "title": "Book", "author_id": 3}, pk="id", foreign_keys={"author_id"}
)
# Renaming the id column on authors should break everything
with pytest.raises(OperationalError) as e:
# Renaming the id column on authors should break everything with an IntegrityError
# The old error didn't match the Sqlite docs.
# We use a transaction to constrain and rollback the error.
fresh_db.begin()
try:
fresh_db["authors"].transform(rename={"id": "id2"})
assert e.value.args[0] == 'foreign key mismatch - "books" referencing "authors"'
fresh_db.commit()
except IntegrityError:
fresh_db.rollback()

# This should have rolled us back
assert (
fresh_db["authors"].schema
Expand Down

0 comments on commit 96ac87d

Please sign in to comment.