Skip to content

Commit 28b2d9e

Browse files
committed
Test CI
1 parent 9da3a6a commit 28b2d9e

File tree

6 files changed

+31
-36
lines changed

6 files changed

+31
-36
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ jobs:
5959
- name: Test with pytest (macOS)
6060
if: runner.os == 'macOS'
6161
run: |
62-
pytest
62+
pytest --cov=vorta
6363
6464
- name: Upload coverage to Codecov
65-
if: runner.os == 'Linux'
6665
uses: codecov/codecov-action@v1
6766
env:
6867
OS: ${{ runner.os }}

src/vorta/borg/borg_thread.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import time
99
import logging
1010
from collections import namedtuple
11+
from threading import Lock
1112
from PyQt5 import QtCore
1213
from PyQt5.QtWidgets import QApplication
1314
from subprocess import Popen, PIPE, TimeoutExpired
@@ -18,7 +19,7 @@
1819
from vorta.keyring.abc import VortaKeyring
1920
from vorta.keyring.db import VortaDBKeyring
2021

21-
mutex = QtCore.QMutex()
22+
mutex = Lock()
2223
logger = logging.getLogger(__name__)
2324

2425
FakeRepo = namedtuple('Repo', ['url', 'id', 'extra_borg_arguments', 'encryption'])
@@ -93,11 +94,7 @@ def __init__(self, cmd, params, parent=None):
9394

9495
@classmethod
9596
def is_running(cls):
96-
if mutex.tryLock():
97-
mutex.unlock()
98-
return False
99-
else:
100-
return True
97+
return mutex.locked()
10198

10299
@classmethod
103100
def prepare(cls, profile):
@@ -190,7 +187,7 @@ def prepare_bin(cls):
190187

191188
def run(self):
192189
self.started_event()
193-
mutex.lock()
190+
mutex.acquire()
194191
log_entry = EventLogModel(category='borg-run',
195192
subcommand=self.cmd[1],
196193
profile=self.params.get('profile_name', None)
@@ -275,7 +272,7 @@ def read_async(fd):
275272

276273
self.process_result(result)
277274
self.finished_event(result)
278-
mutex.unlock()
275+
mutex.release()
279276

280277
def cancel(self):
281278
"""
@@ -287,10 +284,11 @@ def cancel(self):
287284
try:
288285
self.process.wait(timeout=3)
289286
except TimeoutExpired:
290-
self.process.terminate()
291-
mutex.unlock()
292-
self.terminate()
287+
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
288+
self.quit()
293289
self.wait()
290+
if mutex.locked():
291+
mutex.release()
294292

295293
def process_result(self, result):
296294
pass

src/vorta/keyring/abc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import sys
77
from pkg_resources import parse_version
8+
from vorta.i18n import trans_late
89

910

1011
class VortaKeyring:
@@ -55,6 +56,12 @@ def get_keyring(cls):
5556

5657
return cls._keyring
5758

59+
def get_backend_warning(self):
60+
if self.is_system:
61+
return trans_late('utils', 'Storing password in your password manager.')
62+
else:
63+
return trans_late('utils', 'Saving password with Vorta settings.')
64+
5865
def set_password(self, service, repo_url, password):
5966
"""
6067
Writes a password to the underlying store.

src/vorta/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def get_misc_settings():
279279
def cleanup_db():
280280
# Clean up database
281281
db.execute_sql("VACUUM")
282+
db.close()
282283

283284

284285
def init_db(con=None):

src/vorta/views/repo_add_dialog.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from vorta.keyring.abc import VortaKeyring
88
from vorta.borg.init import BorgInitThread
99
from vorta.borg.info_repo import BorgInfoRepoThread
10-
from vorta.i18n import translate, trans_late
10+
from vorta.i18n import translate
1111
from vorta.views.utils import get_colored_icon
1212
from vorta.models import RepoModel
1313

@@ -31,7 +31,7 @@ def __init__(self, parent=None):
3131
self.repoURL.textChanged.connect(self.set_password)
3232
self.passwordLineEdit.textChanged.connect(self.password_listener)
3333
self.confirmLineEdit.textChanged.connect(self.password_listener)
34-
self.encryptionComboBox.activated.connect(self.display_password_backend)
34+
self.encryptionComboBox.activated.connect(self.display_backend_warning)
3535

3636
# Add clickable icon to toggle password visibility to end of box
3737
self.showHideAction = QAction(self.tr("Show my passwords"), self)
@@ -45,7 +45,7 @@ def __init__(self, parent=None):
4545
self.init_encryption()
4646
self.init_ssh_key()
4747
self.set_icons()
48-
self.display_password_backend()
48+
self.display_backend_warning()
4949

5050
def set_icons(self):
5151
self.chooseLocalFolderButton.setIcon(get_colored_icon('folder-open'))
@@ -64,17 +64,10 @@ def values(self):
6464
out['encryption'] = self.encryptionComboBox.currentData()
6565
return out
6666

67-
def display_password_backend(self):
67+
def display_backend_warning(self):
6868
'''Display password backend message based off current keyring'''
69-
backend_msg = ''
7069
if self.encryptionComboBox.currentData() != 'none':
71-
keyring = VortaKeyring.get_keyring()
72-
if keyring.is_system:
73-
backend_msg = trans_late('utils', 'Storing password in your password manager.')
74-
else:
75-
backend_msg = trans_late('utils', 'Saving password with Vorta settings.')
76-
77-
self.passwordLabel.setText(backend_msg)
70+
self.passwordLabel.setText(VortaKeyring.get_keyring().get_backend_warning())
7871

7972
def choose_local_backup_folder(self):
8073
def receive():

tests/conftest.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ def qapp(tmpdir_factory):
3434
qapp = VortaApp([]) # Only init QApplication once to avoid segfaults while testing.
3535

3636
yield qapp
37+
mock_db.close()
3738
qapp.quit()
3839

3940

4041
@pytest.fixture(scope='function', autouse=True)
41-
def init_db(qapp, tmpdir_factory):
42+
def init_db(qapp, qtbot, tmpdir_factory):
4243
tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
4344
mock_db = peewee.SqliteDatabase(str(tmp_db), pragmas={'journal_mode': 'wal', })
4445
vorta.models.init_db(mock_db)
@@ -61,18 +62,14 @@ def init_db(qapp, tmpdir_factory):
6162
source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo, dir_size=100, dir_files_count=18, path_isdir=True)
6263
source_dir.save()
6364

65+
qapp.main_window.deleteLater()
66+
del qapp.main_window
6467
qapp.main_window = MainWindow(qapp) # Re-open main window to apply mock data in UI
6568

66-
67-
@pytest.fixture(scope='function', autouse=True)
68-
def cleanup(request, qapp, qtbot):
69-
"""
70-
Cleanup after each test
71-
"""
72-
def ensure_borg_thread_stopped():
73-
qapp.backup_cancelled_event.emit()
74-
qtbot.waitUntil(lambda: not vorta.borg.borg_thread.BorgThread.is_running())
75-
request.addfinalizer(ensure_borg_thread_stopped)
69+
yield
70+
qapp.backup_cancelled_event.emit()
71+
qtbot.waitUntil(lambda: not vorta.borg.borg_thread.BorgThread.is_running())
72+
mock_db.close()
7673

7774

7875
@pytest.fixture

0 commit comments

Comments
 (0)