diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5030e1e..b4adf1db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,19 @@ jobs: uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} + + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + - name: pip cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg', 'requirements.d/**') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install system dependencies (Linux) if: runner.os == 'Linux' run: | @@ -34,8 +47,10 @@ jobs: run: | pip install -e . pip install -r requirements.d/dev.txt + # - name: Setup tmate session # uses: mxschmitt/action-tmate@v1 + - name: Test with pytest (Linux) if: runner.os == 'Linux' run: | @@ -44,7 +59,8 @@ jobs: - name: Test with pytest (macOS) if: runner.os == 'macOS' run: | - pytest --cov=vorta + pytest + - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 env: @@ -53,6 +69,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} env_vars: OS, python + lint: runs-on: ubuntu-latest steps: diff --git a/src/vorta/application.py b/src/vorta/application.py index fc3360c8..04f9cbe4 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -75,7 +75,7 @@ class VortaApp(QtSingleApplication): self.backup_cancelled_event.connect(self.backup_cancelled_event_response) self.message_received_event.connect(self.message_received_event_response) self.backup_log_event.connect(self.react_to_log) - self.aboutToQuit.connect(cleanup_db) + self.aboutToQuit.connect(self.quit_app_action) self.set_borg_details_action() self.installEventFilter(self) @@ -101,6 +101,12 @@ class VortaApp(QtSingleApplication): self.tray.set_tray_icon() return False + def quit_app_action(self): + del self.main_window + self.scheduler.shutdown() + self.backup_cancelled_event.emit() + cleanup_db() + def create_backup_action(self, profile_id=None): if not profile_id: profile_id = self.main_window.current_profile.id diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 0ff7c24f..33b7754b 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -62,12 +62,13 @@ def get_directory_size(dir_path): if os.path.islink(file_path): continue - stat = os.stat(file_path) - - # Visit each file once - if stat.st_ino not in seen: - seen.add(stat.st_ino) - data_size += stat.st_size + try: + stat = os.stat(file_path) + if stat.st_ino not in seen: # Visit each file only once + seen.add(stat.st_ino) + data_size += stat.st_size + except FileNotFoundError: + continue files_count = len(seen) diff --git a/tests/conftest.py b/tests/conftest.py index 3f8939a5..afe950e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,6 +34,7 @@ def qapp(tmpdir_factory): qapp = VortaApp([]) # Only init QApplication once to avoid segfaults while testing. yield qapp + qapp.quit() @pytest.fixture(scope='function', autouse=True) diff --git a/tests/test_source.py b/tests/test_source.py index 976e6109..8249605d 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -1,12 +1,8 @@ -import os import pytest -import vorta.models import vorta.views -from PyQt5.QtWidgets import QApplication -from PyQt5 import QtCore -def test_add_folder(qapp, qtbot, tmpdir, monkeypatch, choose_file_dialog): +def test_add_folder(qapp, qtbot, mocker, monkeypatch, choose_file_dialog): monkeypatch.setattr( vorta.views.source_tab, "choose_file_dialog", choose_file_dialog ) @@ -17,7 +13,12 @@ def test_add_folder(qapp, qtbot, tmpdir, monkeypatch, choose_file_dialog): tab.sourceAddFolder.click() qtbot.waitUntil(lambda: tab.sourceFilesWidget.rowCount() == 2, **pytest._wait_defaults) - # Test paste button - QApplication.clipboard().setText(os.path.expanduser('~')) # Load clipboard - qtbot.mouseClick(tab.paste, QtCore.Qt.LeftButton) - assert tab.sourceFilesWidget.rowCount() == 3 + # Test paste button with mocked clipboard + mock_clipboard = mocker.Mock() + mock_clipboard.text.return_value = __file__ + mocker.patch.object(vorta.views.source_tab.QApplication, 'clipboard', return_value=mock_clipboard) + tab.paste_text() + qtbot.waitUntil(lambda: tab.sourceFilesWidget.rowCount() == 3, **pytest._wait_defaults) + + # Wait for directory sizing to finish + qtbot.waitUntil(lambda: len(qapp.main_window.sourceTab.updateThreads) == 0, **pytest._wait_defaults) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1f5197a2..d0dc6ab3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,7 @@ import uuid from vorta.keyring.abc import VortaKeyring -def test_keyring(qapp): +def test_keyring(): UNICODE_PW = 'kjalsdfüadsfäadsfß' REPO = f'vorta-test-repo.{uuid.uuid4()}.com:repo' # Random repo URL