diff --git a/src/vorta/views/archive_tab.py b/src/vorta/views/archive_tab.py index 9408b3cba..5b43c58a0 100644 --- a/src/vorta/views/archive_tab.py +++ b/src/vorta/views/archive_tab.py @@ -273,7 +273,7 @@ def populate_from_profile(self): populateArchiveTableWorker.start() self.archiveTable.hideColumn(3) - archives = [s for s in profile.repo.archives.select().order_by(ArchiveModel.time.desc())] + archives = list(profile.repo.archives.select().order_by(ArchiveModel.time.desc())) sorting = self.archiveTable.isSortingEnabled() self.archiveTable.setSortingEnabled(False) @@ -307,12 +307,12 @@ def populate_from_profile(self): item.setTextAlignment(Qt.AlignmentFlag.AlignRight) self.archiveTable.setItem(row, 5, item) - self.archiveTable.setRowCount(len(archives)) - self.archiveTable.setSortingEnabled(sorting) - item = self.archiveTable.item(0, 0) - self.archiveTable.scrollToItem(item) + self.archiveTable.setRowCount(len(archives)) + self.archiveTable.setSortingEnabled(sorting) + item = self.archiveTable.item(0, 0) + self.archiveTable.scrollToItem(item) - self.archiveTable.selectionModel().clearSelection() + self.archiveTable.selectionModel().clearSelection() if self.remaining_refresh_archives == 0: self._toggle_all_buttons(enabled=True) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index e622a2118..ad64fffc5 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -74,6 +74,12 @@ def init_db(qapp, qtbot, tmpdir_factory): qapp.backup_finished_event.disconnect() qapp.scheduler.schedule_changed.disconnect() qtbot.waitUntil(lambda: not qapp.jobs_manager.is_worker_running(), **pytest._wait_defaults) + for worker in qapp.main_window.archiveTab.workers: + worker.quit() + worker.exit() + for worker in qapp.main_window.scheduleTab.workers: + worker.quit() + worker.exit() mock_db.close() diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index ea529c089..3180a859e 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,16 +1,13 @@ -import sys import uuid import pytest from vorta.keyring.abc import VortaKeyring from vorta.utils import ( find_best_unit_for_sizes, - get_path_datasize, is_system_tray_available, - normalize_path, pretty_bytes, - sort_sizes, ) +from vorta.views.utils import sort_sizes def test_keyring(): @@ -110,53 +107,6 @@ def test_pretty_bytes_nonfixed_units(size, metric, expected_output): assert output == expected_output -def test_normalize_path(): - """ - Test that path is normalized for macOS, but does nothing for other platforms. - """ - input_path = '/Users/username/caf\u00e9/file.txt' - expected_output = '/Users/username/café/file.txt' - - actual_output = normalize_path(input_path) - - if sys.platform == 'darwin': - assert actual_output == expected_output - else: - assert actual_output == input_path - - -def test_get_path_datasize(tmpdir): - """ - Test that get_path_datasize() works correctly when passed excluded patterns. - """ - # Create a temporary directory for testing - test_dir = tmpdir.mkdir("test_dir") - test_file = test_dir.join("test_file.txt") - test_file.write("Hello, World!") - - # Create a subdirectory with a file to exclude - excluded_dir = test_dir.mkdir("excluded_dir") - excluded_file = excluded_dir.join("excluded_file.txt") - excluded_file.write("Excluded file, should not be checked.") - - exclude_patterns = [f"{excluded_dir}"] - - # Test when the path is a directory - data_size, files_count = get_path_datasize(str(test_dir), exclude_patterns) - assert data_size == len("Hello, World!") - assert files_count == 1 - - # Test when the path is a file - data_size, files_count = get_path_datasize(str(test_file), exclude_patterns) - assert data_size == len("Hello, World!") - assert files_count == 1 - - # Test when the path is a directory with an excluded file - data_size, files_count = get_path_datasize(str(excluded_dir), exclude_patterns) - assert data_size == 0 - assert files_count == 0 - - def test_is_system_tray_available(mocker): """ Sanity check to ensure proper behavior diff --git a/tests/unit/test_workers.py b/tests/unit/test_workers.py new file mode 100644 index 000000000..121d5e26f --- /dev/null +++ b/tests/unit/test_workers.py @@ -0,0 +1,53 @@ +import sys + +from vorta.views.workers.file_path_info_worker import ( + get_path_datasize, + normalize_path, +) + + +def test_normalize_path(): + """ + Test that path is normalized for macOS, but does nothing for other platforms. + """ + input_path = '/Users/username/caf\u00e9/file.txt' + expected_output = '/Users/username/café/file.txt' + + actual_output = normalize_path(input_path) + + if sys.platform == 'darwin': + assert actual_output == expected_output + else: + assert actual_output == input_path + + +def test_get_path_datasize(tmpdir): + """ + Test that get_path_datasize() works correctly when passed excluded patterns. + """ + # Create a temporary directory for testing + test_dir = tmpdir.mkdir("test_dir") + test_file = test_dir.join("test_file.txt") + test_file.write("Hello, World!") + + # Create a subdirectory with a file to exclude + excluded_dir = test_dir.mkdir("excluded_dir") + excluded_file = excluded_dir.join("excluded_file.txt") + excluded_file.write("Excluded file, should not be checked.") + + exclude_patterns = [f"{excluded_dir}"] + + # Test when the path is a directory + data_size, files_count = get_path_datasize(str(test_dir), exclude_patterns) + assert data_size == len("Hello, World!") + assert files_count == 1 + + # Test when the path is a file + data_size, files_count = get_path_datasize(str(test_file), exclude_patterns) + assert data_size == len("Hello, World!") + assert files_count == 1 + + # Test when the path is a directory with an excluded file + data_size, files_count = get_path_datasize(str(excluded_dir), exclude_patterns) + assert data_size == 0 + assert files_count == 0