Skip to content

Commit

Permalink
Start fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m3nu committed Mar 18, 2024
1 parent 6d6351a commit a66f6c9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
12 changes: 6 additions & 6 deletions src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
52 changes: 1 addition & 51 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/test_workers.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a66f6c9

Please sign in to comment.