-
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
13 changed files
with
65 additions
and
56 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
50 changes: 29 additions & 21 deletions
50
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,35 +1,43 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from tribler_common.rest_utils import from_file_uri, re_fix_win_path, to_file_uri | ||
from tribler_common.rest_utils import path_to_uri, uri_to_path | ||
|
||
PATHS = [ | ||
# nix | ||
NIX_PATHS = [ | ||
('/path/to/file', 'file:///path/to/file'), | ||
('/path/to/file with space', 'file:///path/to/file%20with%20space'), | ||
('/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:\\'), | ||
WIN_PATHS = [ | ||
('C:\\path\\to\\file', 'file:///C:%5Cpath%5Cto%5Cfile'), | ||
('C:\\path\\to\\file with space', 'file:///C:%5Cpath%5Cto%5Cfile%20with%20space'), | ||
('C:\\path\\to\\%20%21file', 'file:///C:%5Cpath%5Cto%5C%2520%2521file'), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('path,uri', PATHS) | ||
def test_to_file_uri(path, uri): | ||
assert to_file_uri(path) == uri | ||
# posix | ||
@pytest.mark.parametrize('path,uri', NIX_PATHS) | ||
@patch('os.name', 'posix') | ||
def test_path_to_uri(path, uri): | ||
assert path_to_uri(path) == uri | ||
|
||
|
||
@pytest.mark.parametrize('path,uri', NIX_PATHS) | ||
@patch('os.name', 'posix') | ||
def test_uri_to_path(path, uri): | ||
assert uri_to_path(uri) == path | ||
|
||
|
||
@pytest.mark.parametrize('path,uri', PATHS) | ||
def test_from_file_uri(path, uri): | ||
assert from_file_uri(uri) == path | ||
# win | ||
@pytest.mark.parametrize('path,uri', WIN_PATHS) | ||
@patch('os.name', 'nt') | ||
def test_path_to_uri_win(path, uri): | ||
assert path_to_uri(path) == uri | ||
|
||
|
||
@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 | ||
@pytest.mark.parametrize('path,uri', WIN_PATHS) | ||
@patch('os.name', 'nt') | ||
def test_uri_to_path_win(path, uri): | ||
assert uri_to_path(uri) == path |
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
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
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
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
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
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
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
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
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
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
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