Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Path.fix_win_long_file #7775

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def on_save_resume_data_alert(self, alert: lt.save_resume_data_alert):
filename = self.download_manager.get_checkpoint_dir() / basename
self.config.config['download_defaults']['name'] = self.tdef.get_name_as_unicode() # store name (for debugging)
try:
self.config.write(str(filename))
self.config.write(filename)
except OSError as e:
self._logger.warning(f'{e.__class__.__name__}: {e}')
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def copy(self):
return DownloadConfig(ConfigObj(self.config, configspec=str(CONFIG_SPEC_PATH), default_encoding='utf-8'),
state_dir=self.state_dir)

def write(self, filename):
def write(self, filename: Path):
self.config.filename = Path.fix_win_long_file(filename)
self.config.write()

Expand Down
17 changes: 17 additions & 0 deletions src/tribler/core/utilities/tests/test_path_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys
from unittest.mock import patch

import pytest

from tribler.core.utilities.path_util import Path, tail
Expand Down Expand Up @@ -101,3 +104,17 @@ def test_size_folder(tribler_tmp_path: Path):

assert tribler_tmp_path.size(include_dir_sizes=False) == 300
assert tribler_tmp_path.size() >= 300


@patch.object(sys, 'platform', 'win32')
def test_fix_win_long_file_win():
""" Test that fix_win_long_file works correct on Windows"""
path = Path(r'C:\Users\User\AppData\Roaming\.Tribler\7.7')
assert Path.fix_win_long_file(path) == r'\\?\C:\Users\User\AppData\Roaming\.Tribler\7.7'


@patch.object(sys, 'platform', 'linux')
def test_fix_win_long_file_linux():
""" Test that fix_win_long_file works correct on Linux"""
path = Path('/home/user/.Tribler/7.7')
assert Path.fix_win_long_file(path) == '/home/user/.Tribler/7.7'
Loading