-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 31 additions & 5 deletions
36
src/tribler-common/tribler_common/tests/test_rest_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
from tribler_common.rest_utils import from_file_uri, to_file_uri | ||
import pytest | ||
|
||
from tribler_common.rest_utils import from_file_uri, re_fix_win_path, to_file_uri | ||
|
||
def test_to_file_uri(): | ||
assert to_file_uri('/path') == 'file:///path' | ||
PATHS = [ | ||
# nix | ||
('/path/to/file', 'file:///path/to/file'), | ||
('/path/to/%20%21file', 'file:///path/to/%2520%2521file'), # See: https://github.com/Tribler/tribler/issues/6700 | ||
# win | ||
('E:\\path\\to\\file', 'file:///E:%5Cpath%5Cto%5Cfile'), | ||
] | ||
|
||
PATHS_TO_FIX = [ | ||
# correct | ||
('c:\\', 'c:\\'), | ||
('/path', '/path'), | ||
# corrupted: | ||
('/c:\\', 'c:\\'), | ||
('/C:\\', 'C:\\'), | ||
] | ||
|
||
def test_from_file_uri(): | ||
assert from_file_uri('file:///path') == '/path' | ||
|
||
@pytest.mark.parametrize('path,uri', PATHS) | ||
def test_to_file_uri(path, uri): | ||
assert to_file_uri(path) == uri | ||
|
||
|
||
@pytest.mark.parametrize('path,uri', PATHS) | ||
def test_from_file_uri(path, uri): | ||
assert from_file_uri(uri) == path | ||
|
||
|
||
@pytest.mark.parametrize('original,expected', PATHS_TO_FIX) | ||
def test_re_fix_win_path(original, expected): | ||
assert re_fix_win_path.sub(r'\1', original) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters