Skip to content

Commit

Permalink
Merge pull request #7775 from drew2a/fix/5926
Browse files Browse the repository at this point in the history
Add tests for `Path.fix_win_long_file`
  • Loading branch information
drew2a committed Dec 13, 2023
2 parents 1f57226 + fba5966 commit 822f354
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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'

0 comments on commit 822f354

Please sign in to comment.