Skip to content

Commit a66f6c9

Browse files
committed
Start fixing tests
1 parent 6d6351a commit a66f6c9

File tree

4 files changed

+66
-57
lines changed

4 files changed

+66
-57
lines changed

src/vorta/views/archive_tab.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def populate_from_profile(self):
273273
populateArchiveTableWorker.start()
274274
self.archiveTable.hideColumn(3)
275275

276-
archives = [s for s in profile.repo.archives.select().order_by(ArchiveModel.time.desc())]
276+
archives = list(profile.repo.archives.select().order_by(ArchiveModel.time.desc()))
277277

278278
sorting = self.archiveTable.isSortingEnabled()
279279
self.archiveTable.setSortingEnabled(False)
@@ -307,12 +307,12 @@ def populate_from_profile(self):
307307
item.setTextAlignment(Qt.AlignmentFlag.AlignRight)
308308
self.archiveTable.setItem(row, 5, item)
309309

310-
self.archiveTable.setRowCount(len(archives))
311-
self.archiveTable.setSortingEnabled(sorting)
312-
item = self.archiveTable.item(0, 0)
313-
self.archiveTable.scrollToItem(item)
310+
self.archiveTable.setRowCount(len(archives))
311+
self.archiveTable.setSortingEnabled(sorting)
312+
item = self.archiveTable.item(0, 0)
313+
self.archiveTable.scrollToItem(item)
314314

315-
self.archiveTable.selectionModel().clearSelection()
315+
self.archiveTable.selectionModel().clearSelection()
316316

317317
if self.remaining_refresh_archives == 0:
318318
self._toggle_all_buttons(enabled=True)

tests/unit/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def init_db(qapp, qtbot, tmpdir_factory):
7474
qapp.backup_finished_event.disconnect()
7575
qapp.scheduler.schedule_changed.disconnect()
7676
qtbot.waitUntil(lambda: not qapp.jobs_manager.is_worker_running(), **pytest._wait_defaults)
77+
for worker in qapp.main_window.archiveTab.workers:
78+
worker.quit()
79+
worker.exit()
80+
for worker in qapp.main_window.scheduleTab.workers:
81+
worker.quit()
82+
worker.exit()
7783
mock_db.close()
7884

7985

tests/unit/test_utils.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import sys
21
import uuid
32

43
import pytest
54
from vorta.keyring.abc import VortaKeyring
65
from vorta.utils import (
76
find_best_unit_for_sizes,
8-
get_path_datasize,
97
is_system_tray_available,
10-
normalize_path,
118
pretty_bytes,
12-
sort_sizes,
139
)
10+
from vorta.views.utils import sort_sizes
1411

1512

1613
def test_keyring():
@@ -110,53 +107,6 @@ def test_pretty_bytes_nonfixed_units(size, metric, expected_output):
110107
assert output == expected_output
111108

112109

113-
def test_normalize_path():
114-
"""
115-
Test that path is normalized for macOS, but does nothing for other platforms.
116-
"""
117-
input_path = '/Users/username/caf\u00e9/file.txt'
118-
expected_output = '/Users/username/café/file.txt'
119-
120-
actual_output = normalize_path(input_path)
121-
122-
if sys.platform == 'darwin':
123-
assert actual_output == expected_output
124-
else:
125-
assert actual_output == input_path
126-
127-
128-
def test_get_path_datasize(tmpdir):
129-
"""
130-
Test that get_path_datasize() works correctly when passed excluded patterns.
131-
"""
132-
# Create a temporary directory for testing
133-
test_dir = tmpdir.mkdir("test_dir")
134-
test_file = test_dir.join("test_file.txt")
135-
test_file.write("Hello, World!")
136-
137-
# Create a subdirectory with a file to exclude
138-
excluded_dir = test_dir.mkdir("excluded_dir")
139-
excluded_file = excluded_dir.join("excluded_file.txt")
140-
excluded_file.write("Excluded file, should not be checked.")
141-
142-
exclude_patterns = [f"{excluded_dir}"]
143-
144-
# Test when the path is a directory
145-
data_size, files_count = get_path_datasize(str(test_dir), exclude_patterns)
146-
assert data_size == len("Hello, World!")
147-
assert files_count == 1
148-
149-
# Test when the path is a file
150-
data_size, files_count = get_path_datasize(str(test_file), exclude_patterns)
151-
assert data_size == len("Hello, World!")
152-
assert files_count == 1
153-
154-
# Test when the path is a directory with an excluded file
155-
data_size, files_count = get_path_datasize(str(excluded_dir), exclude_patterns)
156-
assert data_size == 0
157-
assert files_count == 0
158-
159-
160110
def test_is_system_tray_available(mocker):
161111
"""
162112
Sanity check to ensure proper behavior

tests/unit/test_workers.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sys
2+
3+
from vorta.views.workers.file_path_info_worker import (
4+
get_path_datasize,
5+
normalize_path,
6+
)
7+
8+
9+
def test_normalize_path():
10+
"""
11+
Test that path is normalized for macOS, but does nothing for other platforms.
12+
"""
13+
input_path = '/Users/username/caf\u00e9/file.txt'
14+
expected_output = '/Users/username/café/file.txt'
15+
16+
actual_output = normalize_path(input_path)
17+
18+
if sys.platform == 'darwin':
19+
assert actual_output == expected_output
20+
else:
21+
assert actual_output == input_path
22+
23+
24+
def test_get_path_datasize(tmpdir):
25+
"""
26+
Test that get_path_datasize() works correctly when passed excluded patterns.
27+
"""
28+
# Create a temporary directory for testing
29+
test_dir = tmpdir.mkdir("test_dir")
30+
test_file = test_dir.join("test_file.txt")
31+
test_file.write("Hello, World!")
32+
33+
# Create a subdirectory with a file to exclude
34+
excluded_dir = test_dir.mkdir("excluded_dir")
35+
excluded_file = excluded_dir.join("excluded_file.txt")
36+
excluded_file.write("Excluded file, should not be checked.")
37+
38+
exclude_patterns = [f"{excluded_dir}"]
39+
40+
# Test when the path is a directory
41+
data_size, files_count = get_path_datasize(str(test_dir), exclude_patterns)
42+
assert data_size == len("Hello, World!")
43+
assert files_count == 1
44+
45+
# Test when the path is a file
46+
data_size, files_count = get_path_datasize(str(test_file), exclude_patterns)
47+
assert data_size == len("Hello, World!")
48+
assert files_count == 1
49+
50+
# Test when the path is a directory with an excluded file
51+
data_size, files_count = get_path_datasize(str(excluded_dir), exclude_patterns)
52+
assert data_size == 0
53+
assert files_count == 0

0 commit comments

Comments
 (0)