Skip to content

Commit 4d0fc19

Browse files
authored
Merge pull request #122 from encode/blueyed-abs
Support absolute database paths in sqlite URLs
2 parents 9cb2202 + 00b6a29 commit 4d0fc19

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

databases/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,10 @@ def netloc(self) -> typing.Optional[str]:
362362

363363
@property
364364
def database(self) -> str:
365-
return self.components.path.lstrip("/")
365+
path = self.components.path
366+
if path.startswith("/"):
367+
path = path[1:]
368+
return path
366369

367370
@property
368371
def options(self) -> dict:

tests/test_database_url.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ def test_replace_database_url_components():
5151
new = u.replace(database="test_" + u.database)
5252
assert new.database == "test_mydatabase"
5353
assert str(new) == "sqlite:///test_mydatabase"
54+
55+
u = DatabaseURL("sqlite:////absolute/path")
56+
assert u.database == "/absolute/path"
57+
new = u.replace(database=u.database + "_test")
58+
assert new.database == "/absolute/path_test"
59+
assert str(new) == "sqlite:////absolute/path_test"

tests/test_importer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55

66
def test_invalid_format():
7-
with pytest.raises(ImportFromStringError) as exc:
7+
with pytest.raises(ImportFromStringError) as exc_info:
88
import_from_string("example:")
99
expected = 'Import string "example:" must be in format "<module>:<attribute>".'
10-
assert expected in str(exc)
10+
assert expected in str(exc_info.value)
1111

1212

1313
def test_invalid_module():
14-
with pytest.raises(ImportFromStringError) as exc:
14+
with pytest.raises(ImportFromStringError) as exc_info:
1515
import_from_string("module_does_not_exist:myattr")
1616
expected = 'Could not import module "module_does_not_exist".'
17-
assert expected in str(exc)
17+
assert expected in str(exc_info.value)
1818

1919

2020
def test_invalid_attr():
21-
with pytest.raises(ImportFromStringError) as exc:
21+
with pytest.raises(ImportFromStringError) as exc_info:
2222
import_from_string("tempfile:attr_does_not_exist")
2323
expected = 'Attribute "attr_does_not_exist" not found in module "tempfile".'
24-
assert expected in str(exc)
24+
assert expected in str(exc_info.value)
2525

2626

2727
def test_internal_import_error():
28-
with pytest.raises(ImportError) as exc:
28+
with pytest.raises(ImportError):
2929
import_from_string("tests.importer.raise_import_error:myattr")
3030

3131

0 commit comments

Comments
 (0)