1
1
import os
2
2
import sys
3
- import urllib .request
3
+ import urllib .parse
4
4
5
5
import pytest
6
6
11
11
def test_path_to_url_unix () -> None :
12
12
assert path_to_url ("/tmp/file" ) == "file:///tmp/file"
13
13
path = os .path .join (os .getcwd (), "file" )
14
- assert path_to_url ("file" ) == "file://" + path
14
+ assert path_to_url ("file" ) == "file://" + urllib . parse . quote ( path )
15
15
16
16
17
17
@pytest .mark .skipif ("sys.platform != 'win32'" )
18
18
@pytest .mark .parametrize (
19
19
"path, url" ,
20
20
[
21
- pytest .param ("c :/tmp/file" , "file:///C:/tmp/file" , id = "posix-path" ),
22
- pytest .param ("c :\\ tmp\\ file" , "file:///C:/tmp/file" , id = "nt-path" ),
21
+ pytest .param ("C :/tmp/file" , "file:///C:/tmp/file" , id = "posix-path" ),
22
+ pytest .param ("C :\\ tmp\\ file" , "file:///C:/tmp/file" , id = "nt-path" ),
23
23
],
24
24
)
25
25
def test_path_to_url_win (path : str , url : str ) -> None :
@@ -38,21 +38,21 @@ def test_unc_path_to_url_win() -> None:
38
38
39
39
@pytest .mark .skipif ("sys.platform != 'win32'" )
40
40
def test_relative_path_to_url_win () -> None :
41
- resolved_path = os .path .join (os .getcwd (), "file" )
42
- assert path_to_url ("file" ) == "file:" + urllib .request . pathname2url ( resolved_path )
41
+ path = os .path .join (os .getcwd (), "file" ). replace ( " \\ " , "/ " )
42
+ assert path_to_url ("file" ) == "file:/// " + urllib .parse . quote ( path , safe = "/:" )
43
43
44
44
45
45
@pytest .mark .parametrize (
46
46
"url,win_expected,non_win_expected" ,
47
47
[
48
48
("file:tmp" , "tmp" , "tmp" ),
49
- ("file:c :/path/to/file" , r"C:\path\to\file" , "c :/path/to/file" ),
49
+ ("file:C :/path/to/file" , r"C:\path\to\file" , "C :/path/to/file" ),
50
50
("file:/path/to/file" , r"\path\to\file" , "/path/to/file" ),
51
51
("file://localhost/tmp/file" , r"\tmp\file" , "/tmp/file" ),
52
- ("file://localhost/c :/tmp/file" , r"C:\tmp\file" , "/c :/tmp/file" ),
52
+ ("file://localhost/C :/tmp/file" , r"C:\tmp\file" , "/C :/tmp/file" ),
53
53
("file://somehost/tmp/file" , r"\\somehost\tmp\file" , None ),
54
54
("file:///tmp/file" , r"\tmp\file" , "/tmp/file" ),
55
- ("file:///c :/tmp/file" , r"C:\tmp\file" , "/c :/tmp/file" ),
55
+ ("file:///C :/tmp/file" , r"C:\tmp\file" , "/C :/tmp/file" ),
56
56
],
57
57
)
58
58
def test_url_to_path (url : str , win_expected : str , non_win_expected : str ) -> None :
0 commit comments