mirror of
https://github.com/logos-storage/deluge.git
synced 2026-08-01 07:53:26 +00:00
- Move baseargparser out of deluge/ui since it is also used by the
Daemon and could cause packaging issues if UI code is not available.
- Renamed baseargparser to argparserbase to follow existing Deluge
naming.
- Renamed get_version to distinguish from deluge.common.get_version.
- Translation code is usable by more than just the UIs so also move it
to Deluge namespace and re-use i18n directory and make it a package.
- Renamed setup_translations to singular as it felt more correct.
- Renamed set_dummy_trans to be more descriptive.
Closes: #3081
177 lines
6.1 KiB
Python
177 lines
6.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
|
# the additional special exception to link portions of this program with the OpenSSL library.
|
|
# See LICENSE for more details.
|
|
#
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
import pytest
|
|
from twisted.trial import unittest
|
|
|
|
import deluge.component as component
|
|
from deluge.common import windows_check
|
|
from deluge.configmanager import ConfigManager
|
|
from deluge.i18n import setup_translation
|
|
|
|
from . import common
|
|
from .basetest import BaseTestCase
|
|
|
|
libs_available = True
|
|
# Allow running other tests without GTKUI dependencies available
|
|
try:
|
|
from deluge.ui.gtk3.files_tab import FilesTab
|
|
from deluge.ui.gtk3.gtkui import DEFAULT_PREFS
|
|
from deluge.ui.gtk3.mainwindow import MainWindow
|
|
except ImportError:
|
|
libs_available = False
|
|
|
|
setup_translation()
|
|
|
|
|
|
@pytest.mark.gtkui
|
|
class FilesTabTestCase(BaseTestCase):
|
|
def set_up(self):
|
|
if libs_available is False:
|
|
raise unittest.SkipTest('GTKUI dependencies not available')
|
|
|
|
common.set_tmp_config_dir()
|
|
ConfigManager('gtk3ui.conf', defaults=DEFAULT_PREFS)
|
|
self.mainwindow = MainWindow()
|
|
self.filestab = FilesTab()
|
|
self.t_id = '1'
|
|
self.filestab.torrent_id = self.t_id
|
|
self.index = 1
|
|
|
|
def tear_down(self):
|
|
return component.shutdown()
|
|
|
|
def print_treestore(self, title, treestore):
|
|
root = treestore.get_iter_first()
|
|
level = 1
|
|
|
|
def p_level(s, l):
|
|
print('%s%s' % (' ' * l, s))
|
|
|
|
def _print_treestore_children(i, lvl):
|
|
while i:
|
|
p_level(treestore[i][0], lvl)
|
|
if treestore.iter_children(i):
|
|
_print_treestore_children(treestore.iter_children(i), lvl + 2)
|
|
i = treestore.iter_next(i)
|
|
|
|
print('\n%s' % title)
|
|
_print_treestore_children(root, level)
|
|
print('')
|
|
|
|
def verify_treestore(self, treestore, tree):
|
|
def _verify_treestore(itr, tree_values):
|
|
i = 0
|
|
while itr:
|
|
values = tree_values[i]
|
|
if treestore[itr][0] != values[0]:
|
|
return False
|
|
if treestore.iter_children(itr):
|
|
if not _verify_treestore(treestore.iter_children(itr), values[1]):
|
|
return False
|
|
itr = treestore.iter_next(itr)
|
|
i += 1
|
|
return True
|
|
|
|
return _verify_treestore(treestore.get_iter_first(), tree)
|
|
|
|
def test_files_tab(self):
|
|
self.filestab.files_list[self.t_id] = (
|
|
{'index': 0, 'path': '1/test_10.txt', 'offset': 0, 'size': 13},
|
|
{'index': 1, 'path': 'test_100.txt', 'offset': 13, 'size': 14},
|
|
)
|
|
self.filestab.update_files()
|
|
self.filestab._on_torrentfilerenamed_event(
|
|
self.t_id, self.index, '2/test_100.txt'
|
|
)
|
|
|
|
ret = self.verify_treestore(
|
|
self.filestab.treestore,
|
|
[['1/', [['test_10.txt']]], ['2/', [['test_100.txt']]]],
|
|
)
|
|
if not ret:
|
|
self.print_treestore('Treestore not expected:', self.filestab.treestore)
|
|
self.assertTrue(ret)
|
|
|
|
def test_files_tab2(self):
|
|
if windows_check():
|
|
raise unittest.SkipTest('on windows \\ != / for path names')
|
|
self.filestab.files_list[self.t_id] = (
|
|
{'index': 0, 'path': '1/1/test_10.txt', 'offset': 0, 'size': 13},
|
|
{'index': 1, 'path': 'test_100.txt', 'offset': 13, 'size': 14},
|
|
)
|
|
self.filestab.update_files()
|
|
self.filestab._on_torrentfilerenamed_event(
|
|
self.t_id, self.index, '1/1/test_100.txt'
|
|
)
|
|
|
|
ret = self.verify_treestore(
|
|
self.filestab.treestore,
|
|
[['1/', [['1/', [['test_100.txt'], ['test_10.txt']]]]]],
|
|
)
|
|
if not ret:
|
|
self.print_treestore('Treestore not expected:', self.filestab.treestore)
|
|
self.assertTrue(ret)
|
|
|
|
def test_files_tab3(self):
|
|
if windows_check():
|
|
raise unittest.SkipTest('on windows \\ != / for path names')
|
|
self.filestab.files_list[self.t_id] = (
|
|
{'index': 0, 'path': '1/test_10.txt', 'offset': 0, 'size': 13},
|
|
{'index': 1, 'path': 'test_100.txt', 'offset': 13, 'size': 14},
|
|
)
|
|
self.filestab.update_files()
|
|
self.filestab._on_torrentfilerenamed_event(
|
|
self.t_id, self.index, '1/test_100.txt'
|
|
)
|
|
|
|
ret = self.verify_treestore(
|
|
self.filestab.treestore, [['1/', [['test_100.txt'], ['test_10.txt']]]]
|
|
)
|
|
if not ret:
|
|
self.print_treestore('Treestore not expected:', self.filestab.treestore)
|
|
self.assertTrue(ret)
|
|
|
|
def test_files_tab4(self):
|
|
self.filestab.files_list[self.t_id] = (
|
|
{'index': 0, 'path': '1/test_10.txt', 'offset': 0, 'size': 13},
|
|
{'index': 1, 'path': '1/test_100.txt', 'offset': 13, 'size': 14},
|
|
)
|
|
self.filestab.update_files()
|
|
self.filestab._on_torrentfilerenamed_event(
|
|
self.t_id, self.index, '1/2/test_100.txt'
|
|
)
|
|
|
|
ret = self.verify_treestore(
|
|
self.filestab.treestore,
|
|
[['1/', [['2/', [['test_100.txt']]], ['test_10.txt']]]],
|
|
)
|
|
if not ret:
|
|
self.print_treestore('Treestore not expected:', self.filestab.treestore)
|
|
self.assertTrue(ret)
|
|
|
|
def test_files_tab5(self):
|
|
if windows_check():
|
|
raise unittest.SkipTest('on windows \\ != / for path names')
|
|
self.filestab.files_list[self.t_id] = (
|
|
{'index': 0, 'path': '1/test_10.txt', 'offset': 0, 'size': 13},
|
|
{'index': 1, 'path': '2/test_100.txt', 'offset': 13, 'size': 14},
|
|
)
|
|
self.filestab.update_files()
|
|
self.filestab._on_torrentfilerenamed_event(
|
|
self.t_id, self.index, '1/test_100.txt'
|
|
)
|
|
|
|
ret = self.verify_treestore(
|
|
self.filestab.treestore, [['1/', [['test_100.txt'], ['test_10.txt']]]]
|
|
)
|
|
if not ret:
|
|
self.print_treestore('Treestore not expected:', self.filestab.treestore)
|
|
self.assertTrue(ret)
|