Skip to content

Commit

Permalink
Make utility accept Path-like objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Nov 5, 2024
1 parent 0b1181a commit 2aed6f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tiled/_tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from ..utils import ensure_specified_sql_driver


Expand Down Expand Up @@ -62,6 +64,8 @@ def test_ensure_specified_sql_driver():
# Filepaths are implicitly SQLite databases.
# Relative path
assert ensure_specified_sql_driver("test.db") == "sqlite+aiosqlite:///test.db"
# Path object
assert ensure_specified_sql_driver(Path("test.db")) == "sqlite+aiosqlite:///test.db"
# Relative path anchored to .
assert ensure_specified_sql_driver("./test.db") == "sqlite+aiosqlite:///test.db"
# Absolute path
Expand Down
2 changes: 1 addition & 1 deletion tiled/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def ensure_specified_sql_driver(uri: str) -> str:
'postgresql+my_custom_driver://...' -> 'postgresql+my_custom_driver://...'
'/path/to/file.db' -> 'sqlite+aiosqlite:////path/to/file.db'
"""
if not SCHEME_PATTERN.match(uri):
if not SCHEME_PATTERN.match(str(uri)):
# Interpret URI as filepath.
uri = f"sqlite+aiosqlite:///{Path(uri)}"
scheme, rest = uri.split(":", 1)
Expand Down

0 comments on commit 2aed6f4

Please sign in to comment.