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