11import os
22import sys
3- import urllib .request
3+ import urllib .parse
44
55import pytest
66
1111def test_path_to_url_unix () -> None :
1212 assert path_to_url ("/tmp/file" ) == "file:///tmp/file"
1313 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 )
1515
1616
1717@pytest .mark .skipif ("sys.platform != 'win32'" )
1818@pytest .mark .parametrize (
1919 "path, url" ,
2020 [
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" ),
2323 ],
2424)
2525def test_path_to_url_win (path : str , url : str ) -> None :
@@ -38,21 +38,21 @@ def test_unc_path_to_url_win() -> None:
3838
3939@pytest .mark .skipif ("sys.platform != 'win32'" )
4040def 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 = "/:" )
4343
4444
4545@pytest .mark .parametrize (
4646 "url,win_expected,non_win_expected" ,
4747 [
4848 ("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" ),
5050 ("file:/path/to/file" , r"\path\to\file" , "/path/to/file" ),
5151 ("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" ),
5353 ("file://somehost/tmp/file" , r"\\somehost\tmp\file" , None ),
5454 ("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" ),
5656 ],
5757)
5858def test_url_to_path (url : str , win_expected : str , non_win_expected : str ) -> None :
0 commit comments