-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not require SQL URIs to be prefixed with SQLAlchemy driver (#810)
* Automatically set SQL driver if unset. * Handle special SQLite URIs * Consistently use database URI with schema. * Interpret filepaths as SQLite URIs. * Parse uri earlier. * Update CHANGELOG * Fix missing arg in refactor. * Make utility accept Path-like objects. * Deal with Windows paths in test case
- Loading branch information
1 parent
0ad610f
commit e52bab3
Showing
10 changed files
with
136 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from pathlib import Path | ||
|
||
from ..utils import ensure_specified_sql_driver | ||
|
||
|
||
def test_ensure_specified_sql_driver(): | ||
# Postgres | ||
# Default driver is added if missing. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
# Default driver passes through if specified. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+asyncpg://user:password@localhost:5432/database" | ||
) | ||
# Do not override user-provided. | ||
assert ( | ||
ensure_specified_sql_driver( | ||
"postgresql+custom://user:password@localhost:5432/database" | ||
) | ||
== "postgresql+custom://user:password@localhost:5432/database" | ||
) | ||
|
||
# SQLite | ||
# Default driver is added if missing. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite:////test.db") | ||
== "sqlite+aiosqlite:////test.db" | ||
) | ||
# Default driver passes through if specified. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite:////test.db") | ||
== "sqlite+aiosqlite:////test.db" | ||
) | ||
# Do not override user-provided. | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+custom:////test.db") | ||
== "sqlite+custom:////test.db" | ||
) | ||
# Handle SQLite :memory: URIs | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite://:memory:") | ||
== "sqlite+aiosqlite://:memory:" | ||
) | ||
assert ( | ||
ensure_specified_sql_driver("sqlite://:memory:") | ||
== "sqlite+aiosqlite://:memory:" | ||
) | ||
# Handle SQLite relative URIs | ||
assert ( | ||
ensure_specified_sql_driver("sqlite+aiosqlite:///test.db") | ||
== "sqlite+aiosqlite:///test.db" | ||
) | ||
assert ( | ||
ensure_specified_sql_driver("sqlite:///test.db") | ||
== "sqlite+aiosqlite:///test.db" | ||
) | ||
# 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 | ||
assert ( | ||
ensure_specified_sql_driver(Path("/tmp/test.db")) | ||
== f"sqlite+aiosqlite:///{Path('/tmp/test.db')}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters