Skip to content

Commit

Permalink
fix: update tests for latest dependencies (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Nov 26, 2024
1 parent 33c1f06 commit 9aeefdb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
13 changes: 7 additions & 6 deletions src/shillelagh/backends/apsw/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
int(number) for number in apsw.sqlitelibversion().split(".")
)

NO_SUCH_TABLE = "SQLError: no such table: "
NO_SUCH_TABLE = re.compile("(?:SQLError: )?no such table: (?P<uri>.*)")
DEFAULT_SCHEMA = "main"

CURSOR_METHOD = TypeVar("CURSOR_METHOD", bound=Callable[..., Any])
Expand Down Expand Up @@ -250,12 +250,13 @@ def execute(
break
except apsw.SQLError as ex:
message = ex.args[0]
if not message.startswith(NO_SUCH_TABLE):
raise ProgrammingError(message) from ex
if match := NO_SUCH_TABLE.match(message):
# create the virtual table
uri = match.groupdict()["uri"]
self._create_table(uri)
continue

# create the virtual table
uri = message[len(NO_SUCH_TABLE) :]
self._create_table(uri)
raise ProgrammingError(message) from ex

if uri := self._drop_table_uri(operation):
adapter, args, kwargs = find_adapter(
Expand Down
36 changes: 5 additions & 31 deletions tests/adapters/memory/holidays_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test the holidays in-memory adapter.
"""

import datetime
from holidays import country_holidays

from shillelagh.backends.apsw.db import connect

Expand All @@ -19,38 +19,12 @@ def test_holidays() -> None:
FROM holidays
WHERE
country='US' AND
"date" > '2020-01-01' AND
"date" >= '2020-01-01' AND
"date" < '2022-01-01';
"""
cursor.execute(sql)

holidays = country_holidays("US", years=[2020, 2021])
assert cursor.fetchall() == [
("US", datetime.date(2020, 1, 20), "Martin Luther King Jr. Day"),
("US", datetime.date(2020, 2, 17), "Washington's Birthday"),
("US", datetime.date(2020, 5, 25), "Memorial Day"),
("US", datetime.date(2020, 7, 3), "Independence Day (observed)"),
("US", datetime.date(2020, 7, 4), "Independence Day"),
("US", datetime.date(2020, 9, 7), "Labor Day"),
("US", datetime.date(2020, 10, 12), "Columbus Day"),
("US", datetime.date(2020, 11, 11), "Veterans Day"),
("US", datetime.date(2020, 11, 26), "Thanksgiving"),
("US", datetime.date(2020, 12, 25), "Christmas Day"),
("US", datetime.date(2021, 1, 1), "New Year's Day"),
("US", datetime.date(2021, 1, 18), "Martin Luther King Jr. Day"),
("US", datetime.date(2021, 2, 15), "Washington's Birthday"),
("US", datetime.date(2021, 5, 31), "Memorial Day"),
(
"US",
datetime.date(2021, 6, 18),
"Juneteenth National Independence Day (observed)",
),
("US", datetime.date(2021, 6, 19), "Juneteenth National Independence Day"),
("US", datetime.date(2021, 7, 4), "Independence Day"),
("US", datetime.date(2021, 7, 5), "Independence Day (observed)"),
("US", datetime.date(2021, 9, 6), "Labor Day"),
("US", datetime.date(2021, 10, 11), "Columbus Day"),
("US", datetime.date(2021, 11, 11), "Veterans Day"),
("US", datetime.date(2021, 11, 25), "Thanksgiving"),
("US", datetime.date(2021, 12, 24), "Christmas Day (observed)"),
("US", datetime.date(2021, 12, 25), "Christmas Day"),
("US", datetime.date(2021, 12, 31), "New Year's Day (observed)"),
("US", date, name) for date, name in sorted(holidays.items())
]
5 changes: 4 additions & 1 deletion tests/backends/apsw/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ def test_check_invalid_syntax() -> None:
connection = connect(":memory:", isolation_level="IMMEDIATE")
with pytest.raises(ProgrammingError) as excinfo:
connection.execute("SELLLLECT 1")
assert str(excinfo.value) == 'SQLError: near "SELLLLECT": syntax error'
assert (
str(excinfo.value) == 'SQLError: near "SELLLLECT": syntax error'
or str(excinfo.value) == 'near "SELLLLECT": syntax error'
)


def test_unsupported_table(registry: AdapterLoader) -> None:
Expand Down
12 changes: 7 additions & 5 deletions tests/console_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ def test_exception(mocker: MockerFixture) -> None:
PromptSession.return_value.prompt.side_effect = ["SSELECT 1;", EOFError()]
console.main()
result = stdout.getvalue()
assert (
result
== """SQLError: near "SSELECT": syntax error
assert result in {
"""SQLError: near "SSELECT": syntax error
GoodBye!
"""
)
""",
"""near "SSELECT": syntax error
GoodBye!
""",
}


def test_ctrl_c(mocker: MockerFixture) -> None:
Expand Down

0 comments on commit 9aeefdb

Please sign in to comment.