|
6 | 6 | from unittest.mock import patch |
7 | 7 |
|
8 | 8 | import click |
| 9 | +import pytest |
9 | 10 | from click.testing import CliRunner |
10 | 11 |
|
11 | 12 | from litecli.main import cli, LiteCli |
12 | 13 | from litecli.packages.special.main import COMMANDS as SPECIAL_COMMANDS |
13 | | -from utils import dbtest, run |
| 14 | +from utils import dbtest, run, create_db, db_connection |
14 | 15 |
|
15 | 16 | test_dir = os.path.abspath(os.path.dirname(__file__)) |
16 | 17 | project_dir = os.path.dirname(test_dir) |
@@ -330,3 +331,30 @@ def test_get_prompt(mock_datetime): |
330 | 331 | # 12. Windows path |
331 | 332 | lc.connect("C:\\Users\\litecli\\litecli_test.db") |
332 | 333 | assert lc.get_prompt(r"\d") == "C:\\Users\\litecli\\litecli_test.db" |
| 334 | + |
| 335 | + |
| 336 | +@pytest.mark.parametrize( |
| 337 | + "uri, expected_dbname", |
| 338 | + [ |
| 339 | + ("file:{tmp_path}/test.db", "{tmp_path}/test.db"), |
| 340 | + ("file:{tmp_path}/test.db?mode=ro", "{tmp_path}/test.db"), |
| 341 | + ("file:{tmp_path}/test.db?mode=ro&cache=shared", "{tmp_path}/test.db"), |
| 342 | + ], |
| 343 | +) |
| 344 | +def test_file_uri(tmp_path, uri, expected_dbname): |
| 345 | + """ |
| 346 | + Test that `file:` URIs are correctly handled |
| 347 | + ref: |
| 348 | + https://docs.python.org/3/library/sqlite3.html#sqlite3-uri-tricks |
| 349 | + https://www.sqlite.org/c3ref/open.html#urifilenameexamples |
| 350 | + """ |
| 351 | + # - ensure db exists |
| 352 | + db_path = tmp_path / "test.db" |
| 353 | + create_db(db_path) |
| 354 | + db_connection(db_path) |
| 355 | + uri = uri.format(tmp_path=tmp_path) |
| 356 | + |
| 357 | + lc = LiteCli() |
| 358 | + lc.connect(uri) |
| 359 | + |
| 360 | + assert lc.get_prompt(r"\d") == expected_dbname.format(tmp_path=tmp_path) |
0 commit comments