File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -362,7 +362,10 @@ def netloc(self) -> typing.Optional[str]:
362
362
363
363
@property
364
364
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
366
369
367
370
@property
368
371
def options (self ) -> dict :
Original file line number Diff line number Diff line change @@ -51,3 +51,9 @@ def test_replace_database_url_components():
51
51
new = u .replace (database = "test_" + u .database )
52
52
assert new .database == "test_mydatabase"
53
53
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"
Original file line number Diff line number Diff line change 4
4
5
5
6
6
def test_invalid_format ():
7
- with pytest .raises (ImportFromStringError ) as exc :
7
+ with pytest .raises (ImportFromStringError ) as exc_info :
8
8
import_from_string ("example:" )
9
9
expected = 'Import string "example:" must be in format "<module>:<attribute>".'
10
- assert expected in str (exc )
10
+ assert expected in str (exc_info . value )
11
11
12
12
13
13
def test_invalid_module ():
14
- with pytest .raises (ImportFromStringError ) as exc :
14
+ with pytest .raises (ImportFromStringError ) as exc_info :
15
15
import_from_string ("module_does_not_exist:myattr" )
16
16
expected = 'Could not import module "module_does_not_exist".'
17
- assert expected in str (exc )
17
+ assert expected in str (exc_info . value )
18
18
19
19
20
20
def test_invalid_attr ():
21
- with pytest .raises (ImportFromStringError ) as exc :
21
+ with pytest .raises (ImportFromStringError ) as exc_info :
22
22
import_from_string ("tempfile:attr_does_not_exist" )
23
23
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 )
25
25
26
26
27
27
def test_internal_import_error ():
28
- with pytest .raises (ImportError ) as exc :
28
+ with pytest .raises (ImportError ):
29
29
import_from_string ("tests.importer.raise_import_error:myattr" )
30
30
31
31
You can’t perform that action at this time.
0 commit comments