From 63b2eb1089d3b1baf5918b5c0a1cc003615da14a Mon Sep 17 00:00:00 2001 From: real-yfprojects <62463991+real-yfprojects@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:42:36 +0200 Subject: [PATCH 1/2] Configure pre-commit hooks and configure black for tests also. These include flake8 linting, black and isort formatting as well as some general hooks with minor checks. * .pre-commit-config.yaml * pyproject.toml : Run black on test files also. --- .pre-commit-config.yaml | 81 +++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..d6b613fa --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,81 @@ +# pre-commit is a useful tool which can be setup by contributors +# per-repository in a few simple steps given that the +# repository has a config file like this one. +# +# The configured hooks are run on `git commit`. If one of the hooks makes or +# demands a change of the commits contents the commit process is aborted. +# The hooks can also be run manually through `pre-commit run --all-files`. + +minimum_pre_commit_version: "1.15" + +# The following hooks will be run before a commit is created +repos: + # general stuff + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + # check file system problems + - id: check-case-conflict + - id: check-symlinks + - id: destroyed-symlinks + + # unify whitespace and line ending + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer + - id: mixed-line-ending + + # sort requirements.txt files + - id: requirements-txt-fixer + + # format python files + - repo: https://github.com/psf/black + rev: 22.6.0 + hooks: + - id: black + files: ^(src/vorta/|tests) + + # sort python imports + - repo: https://github.com/PyCQA/isort + rev: 5.10.1 + hooks: + - id: isort + + # # run black on code embedded in docstrings + # - repo: https://github.com/asottile/blacken-docs + # rev: v1.12.1 + # hooks: + # - id: blacken-docs + # additional_dependencies: [black] + # args: + # [ + # --line-length, + # "120", + # --skip-string-normalization, + # --target-version, + # py39, + # ] + + # check pep8 conformity using flake8 + - repo: https://github.com/PyCQA/flake8 + rev: 5.0.4 + hooks: + - id: flake8 + +# configuration for the pre-commit.ci bot +# only relevant when actually using the bot +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit.com hooks + + for more information, see https://pre-commit.ci and + the `.pre-commit-config.yaml` file in this repository. + + autofix_prs: true # default + autoupdate_commit_msg: | + [pre-commit.ci] Autoupdate pre-commit hook versions. + + for more information, see https://pre-commit.ci and + the `.pre-commit-config.yaml` file in this repository. + + submodules: false # default diff --git a/pyproject.toml b/pyproject.toml index 87e63787..01eda5ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ line-length = 120 skip-string-normalization = true target-version = ['py39'] -include = "src/vorta/.*.py$" +include = "(src/vorta/|tests).*.py$" [tool.isort] profile = "black" From ca497f8815323d1a7dee53cc1a844e0a69dffe4e Mon Sep 17 00:00:00 2001 From: real-yfprojects <62463991+real-yfprojects@users.noreply.github.com> Date: Mon, 15 Aug 2022 19:02:40 +0200 Subject: [PATCH 2/2] Run hooks on the code base. This adds trailing lines to files, removes trailing white space in all the other lines and unifies line endings. Additionally it formats the test code with `black`. --- .git-blame-ignore-revs | 2 +- .gitattributes | 2 +- .github/workflows/test.yml | 4 +- .gitignore | 1 - .tx/config | 1 - .../fuse-2.9.2-namespace-conflict-fix.patch | 4 +- ...fuse-disable-sys-mount-under-flatpak.patch | 5 +- flatpak/dependencies/pyqt5.json | 2 +- flatpak/dependencies/python3-appdirs.json | 2 +- flatpak/dependencies/python3-paramiko.json | 2 +- flatpak/dependencies/python3-peewee.json | 2 +- flatpak/dependencies/python3-psutil.json | 2 +- flatpak/dependencies/python3-setuptools.json | 2 +- .../dependencies/python3-setuptools_git.json | 2 +- .../dependencies/python3-setuptools_scm.json | 2 +- flatpak/dependencies/python3-wheels.json | 2 +- package/entitlements.plist | 2 +- package/vorta.spec | 1 - src/vorta/assets/icons/broom-solid.svg | 2 +- src/vorta/assets/icons/folder-on-top.svg | 2 +- src/vorta/assets/icons/folder.svg | 2 +- src/vorta/assets/icons/minus.svg | 2 +- src/vorta/assets/icons/paste.svg | 2 +- src/vorta/i18n/ts/vorta.cs.ts | 8 +- src/vorta/i18n/ts/vorta.de.ts | 10 +- src/vorta/i18n/ts/vorta.es.ts | 6 +- src/vorta/i18n/ts/vorta.fi.ts | 10 +- src/vorta/i18n/ts/vorta.fr.ts | 10 +- src/vorta/i18n/ts/vorta.gl.ts | 8 +- src/vorta/i18n/ts/vorta.it.ts | 2 +- src/vorta/i18n/ts/vorta.nl.ts | 6 +- src/vorta/i18n/ts/vorta.ru.ts | 10 +- src/vorta/i18n/ts/vorta.sk.ts | 6 +- src/vorta/i18n/ts/vorta.sv.ts | 6 +- tests/conftest.py | 25 +- tests/network_manager/test_darwin.py | 13 +- tests/network_manager/test_network_manager.py | 86 +++-- tests/test_archives.py | 11 +- tests/test_diff.py | 309 ++++++++++-------- tests/test_import_export.py | 20 +- tests/test_misc.py | 13 +- tests/test_repo.py | 13 +- tests/test_schedule.py | 14 +- tests/test_scheduler.py | 70 ++-- tests/test_source.py | 4 +- tests/test_treemodel.py | 3 +- 46 files changed, 375 insertions(+), 338 deletions(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index f0c751d3..5c5d09a1 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,2 @@ # Migrate code style to Black -b6a24debb78b953117a3f637db18942f370a4b85 \ No newline at end of file +b6a24debb78b953117a3f637db18942f370a4b85 diff --git a/.gitattributes b/.gitattributes index 84ef90f3..95105a37 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -*.py diff=python \ No newline at end of file +*.py diff=python diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e27a09e1..e9ccec86 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,8 +30,8 @@ jobs: black --check . # - name: Run PyLint (info only) # run: pylint --rcfile=setup.cfg src --exit-zero - - + + test: timeout-minutes: 20 runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 022ae91d..061f6a9b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,3 @@ src/vorta/i18n/ts/vorta.en.ts src/vorta/i18n/ts/vorta.en_US.ts flatpak/app/ flatpak/.flatpak-builder/ - diff --git a/.tx/config b/.tx/config index e0ffc9f4..8a9c57d2 100644 --- a/.tx/config +++ b/.tx/config @@ -7,4 +7,3 @@ minimum_perc = 80 source_file = src/vorta/i18n/ts/vorta.en.ts source_lang = en type = QT - diff --git a/flatpak/dependencies/fuse-2.9.2-namespace-conflict-fix.patch b/flatpak/dependencies/fuse-2.9.2-namespace-conflict-fix.patch index ae67e7d4..3dec9fb6 100644 --- a/flatpak/dependencies/fuse-2.9.2-namespace-conflict-fix.patch +++ b/flatpak/dependencies/fuse-2.9.2-namespace-conflict-fix.patch @@ -4,7 +4,7 @@ diff -up fuse-2.9.2/include/fuse_kernel.h.conflictfix fuse-2.9.2/include/fuse_ke @@ -88,12 +88,16 @@ #ifndef _LINUX_FUSE_H #define _LINUX_FUSE_H - + -#include +#ifdef __linux__ +#include @@ -16,6 +16,6 @@ diff -up fuse-2.9.2/include/fuse_kernel.h.conflictfix fuse-2.9.2/include/fuse_ke #define __s32 int32_t #define __u16 uint16_t +#endif - + /* * Version negotiation: diff --git a/flatpak/dependencies/fuse-disable-sys-mount-under-flatpak.patch b/flatpak/dependencies/fuse-disable-sys-mount-under-flatpak.patch index 9c2f65e8..fa2977ad 100644 --- a/flatpak/dependencies/fuse-disable-sys-mount-under-flatpak.patch +++ b/flatpak/dependencies/fuse-disable-sys-mount-under-flatpak.patch @@ -14,13 +14,12 @@ index 7a18c11..1667db2 100644 @@ -392,6 +392,9 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo, int fd; int res; - + + /* disable in flatpak */ + return -2; + if (!mnt) { fprintf(stderr, "fuse: missing mountpoint parameter\n"); return -1; --- +-- 2.17.0.rc2 - diff --git a/flatpak/dependencies/pyqt5.json b/flatpak/dependencies/pyqt5.json index d55b0e18..b72fe36b 100644 --- a/flatpak/dependencies/pyqt5.json +++ b/flatpak/dependencies/pyqt5.json @@ -41,4 +41,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-appdirs.json b/flatpak/dependencies/python3-appdirs.json index 74a5baab..bed12713 100644 --- a/flatpak/dependencies/python3-appdirs.json +++ b/flatpak/dependencies/python3-appdirs.json @@ -11,4 +11,4 @@ "sha256": "d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-paramiko.json b/flatpak/dependencies/python3-paramiko.json index 5b4637a4..4dbb1020 100644 --- a/flatpak/dependencies/python3-paramiko.json +++ b/flatpak/dependencies/python3-paramiko.json @@ -61,4 +61,4 @@ "sha256": "a8975a7df3560c9f1e2b43dc54ebd40fd00a7017392ca5445ce7df409f900fcb" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-peewee.json b/flatpak/dependencies/python3-peewee.json index 4e3566fe..fc547df4 100644 --- a/flatpak/dependencies/python3-peewee.json +++ b/flatpak/dependencies/python3-peewee.json @@ -11,4 +11,4 @@ "sha256": "f3f5c80c51b632d031f60454accadd84f166453a471bff63093ca674973f2a4e" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-psutil.json b/flatpak/dependencies/python3-psutil.json index c01175d4..85b6eacf 100644 --- a/flatpak/dependencies/python3-psutil.json +++ b/flatpak/dependencies/python3-psutil.json @@ -11,4 +11,4 @@ "sha256": "863a85c1c0a5103a12c05a35e59d336e1d665747e531256e061213e2e90f63f3" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-setuptools.json b/flatpak/dependencies/python3-setuptools.json index 66df5404..8cdc6ef2 100644 --- a/flatpak/dependencies/python3-setuptools.json +++ b/flatpak/dependencies/python3-setuptools.json @@ -67,4 +67,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-setuptools_git.json b/flatpak/dependencies/python3-setuptools_git.json index eb54eb99..53dd2bd7 100644 --- a/flatpak/dependencies/python3-setuptools_git.json +++ b/flatpak/dependencies/python3-setuptools_git.json @@ -11,4 +11,4 @@ "sha256": "ff64136da01aabba76ae88b050e7197918d8b2139ccbf6144e14d472b9c40445" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-setuptools_scm.json b/flatpak/dependencies/python3-setuptools_scm.json index 99c49e6e..f5acb05f 100644 --- a/flatpak/dependencies/python3-setuptools_scm.json +++ b/flatpak/dependencies/python3-setuptools_scm.json @@ -11,4 +11,4 @@ "sha256": "52ab47715fa0fc7d8e6cd15168d1a69ba995feb1505131c3e814eb7087b57358" } ] -} \ No newline at end of file +} diff --git a/flatpak/dependencies/python3-wheels.json b/flatpak/dependencies/python3-wheels.json index 4f8cf18b..fe73c0f8 100644 --- a/flatpak/dependencies/python3-wheels.json +++ b/flatpak/dependencies/python3-wheels.json @@ -75,4 +75,4 @@ "sources": [] } ] -} \ No newline at end of file +} diff --git a/package/entitlements.plist b/package/entitlements.plist index 33740fa5..721e335b 100644 --- a/package/entitlements.plist +++ b/package/entitlements.plist @@ -10,4 +10,4 @@ com.apple.security.cs.disable-library-validation - \ No newline at end of file + diff --git a/package/vorta.spec b/package/vorta.spec index dd7ce49c..714228c7 100644 --- a/package/vorta.spec +++ b/package/vorta.spec @@ -81,4 +81,3 @@ app = BUNDLE(coll, 'PATH': '/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin' } }) - diff --git a/src/vorta/assets/icons/broom-solid.svg b/src/vorta/assets/icons/broom-solid.svg index 310fa606..929a9fa5 100644 --- a/src/vorta/assets/icons/broom-solid.svg +++ b/src/vorta/assets/icons/broom-solid.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/vorta/assets/icons/folder-on-top.svg b/src/vorta/assets/icons/folder-on-top.svg index 9924b159..0cab7744 100644 --- a/src/vorta/assets/icons/folder-on-top.svg +++ b/src/vorta/assets/icons/folder-on-top.svg @@ -1,3 +1,3 @@ - \ No newline at end of file + diff --git a/src/vorta/assets/icons/folder.svg b/src/vorta/assets/icons/folder.svg index 8a43015f..6ad5046f 100644 --- a/src/vorta/assets/icons/folder.svg +++ b/src/vorta/assets/icons/folder.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/vorta/assets/icons/minus.svg b/src/vorta/assets/icons/minus.svg index d450de45..ece52503 100644 --- a/src/vorta/assets/icons/minus.svg +++ b/src/vorta/assets/icons/minus.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/vorta/assets/icons/paste.svg b/src/vorta/assets/icons/paste.svg index 5d2c47e9..95398d03 100644 --- a/src/vorta/assets/icons/paste.svg +++ b/src/vorta/assets/icons/paste.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.cs.ts b/src/vorta/i18n/ts/vorta.cs.ts index b75a9bbb..d78e2d6f 100644 --- a/src/vorta/i18n/ts/vorta.cs.ts +++ b/src/vorta/i18n/ts/vorta.cs.ts @@ -1357,11 +1357,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Aktualizace schématu se nezdařila, vyplňte hlášení chyby s odkazem v panelu Různé s následující chybou: - {0} + {0} {1} @@ -2128,4 +2128,4 @@ Zkuste repozitář odpojit a znovu přidat. Je třeba, aby heslo bylo delší než 8 znaků. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.de.ts b/src/vorta/i18n/ts/vorta.de.ts index 182fd4b3..048f3c6b 100644 --- a/src/vorta/i18n/ts/vorta.de.ts +++ b/src/vorta/i18n/ts/vorta.de.ts @@ -1355,11 +1355,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} - Schema-Upgrade Fehler, erstelle einen Bugreport auf dem Link um "Misc"-Tab, mit folgendem Fehler: - {0} + Schema-Upgrade Fehler, erstelle einen Bugreport auf dem Link um "Misc"-Tab, mit folgendem Fehler: + {0} {1} @@ -2125,4 +2125,4 @@ Try unlinking and re-adding your repo. Passwörter müssen länger als 8 Zeichen sein. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.es.ts b/src/vorta/i18n/ts/vorta.es.ts index e628b63e..3b44545d 100644 --- a/src/vorta/i18n/ts/vorta.es.ts +++ b/src/vorta/i18n/ts/vorta.es.ts @@ -1357,8 +1357,8 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Falla al actualizar esquema, registre un reporte de error con el enlace en la pestaña Varios con el siguiente error: {0} @@ -2128,4 +2128,4 @@ Intente desvincular y volver a agregar su repositorio. Las contraseñas deben ser mayor a 8 caracteres. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.fi.ts b/src/vorta/i18n/ts/vorta.fi.ts index dda23597..555b9b0b 100644 --- a/src/vorta/i18n/ts/vorta.fi.ts +++ b/src/vorta/i18n/ts/vorta.fi.ts @@ -1357,11 +1357,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} - Skeeman päivitys epäonnistui, lähetä virheraportti Sekalaiset-välilehdellä olevasta linkistä. Liitä raporttiin seuraavat tiedot: - {0} + Skeeman päivitys epäonnistui, lähetä virheraportti Sekalaiset-välilehdellä olevasta linkistä. Liitä raporttiin seuraavat tiedot: + {0} {1} @@ -2128,4 +2128,4 @@ Poista tietovaraston linkitys ja lisää se uudelleen. Salasanojen tulee olla pidempiä kuin 8 merkkiä. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.fr.ts b/src/vorta/i18n/ts/vorta.fr.ts index 4f2bceb3..31a4c725 100644 --- a/src/vorta/i18n/ts/vorta.fr.ts +++ b/src/vorta/i18n/ts/vorta.fr.ts @@ -1354,11 +1354,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} - Échec de la mise à niveau de la base de donnée, veuillez remplir un rapport de bug en utilisant le lien dans l'onglet Divers avec l'erreur suivante : -{0} + Échec de la mise à niveau de la base de donnée, veuillez remplir un rapport de bug en utilisant le lien dans l'onglet Divers avec l'erreur suivante : +{0} {1} @@ -2125,4 +2125,4 @@ Essayez de dissocier et d'ajouter le dépôt à nouveau. Les mots de passe doivent faire plus de 8 caractères. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.gl.ts b/src/vorta/i18n/ts/vorta.gl.ts index 3c7480fe..401e3a0a 100644 --- a/src/vorta/i18n/ts/vorta.gl.ts +++ b/src/vorta/i18n/ts/vorta.gl.ts @@ -1210,11 +1210,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Produciuse u fallo na actualización do esquema, presenta un informe de erro coa ligazón na lapela Varios co seguinte erro: -{0} +{0} {1} @@ -1837,4 +1837,4 @@ Probe a desvincular e engadir de novo o repositorio. Os contrasinais deben ter máis de 8 caracteres. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.it.ts b/src/vorta/i18n/ts/vorta.it.ts index b45545a5..3c00af70 100644 --- a/src/vorta/i18n/ts/vorta.it.ts +++ b/src/vorta/i18n/ts/vorta.it.ts @@ -1409,4 +1409,4 @@ - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.nl.ts b/src/vorta/i18n/ts/vorta.nl.ts index 38f60448..b947c2a5 100644 --- a/src/vorta/i18n/ts/vorta.nl.ts +++ b/src/vorta/i18n/ts/vorta.nl.ts @@ -1357,8 +1357,8 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Het schema kan niet worden bijgewerkt. Stel een bugmelding op via de link op het tabblad ‘Overig’. Stuur de volgende informatie mee: @@ -2129,4 +2129,4 @@ Herkoppel je repo. De wachtwoorden moeten meer dan 8 tekens bevatten. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.ru.ts b/src/vorta/i18n/ts/vorta.ru.ts index d27c9fc3..394e5c82 100644 --- a/src/vorta/i18n/ts/vorta.ru.ts +++ b/src/vorta/i18n/ts/vorta.ru.ts @@ -1210,11 +1210,11 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} - Сбой обновления схемы. Отправьте сообщение об ошибке по ссылке на вкладке Разное со следующим текстом ошибки: - {0} + Сбой обновления схемы. Отправьте сообщение об ошибке по ссылке на вкладке Разное со следующим текстом ошибки: + {0} {1} @@ -1889,4 +1889,4 @@ Try unlinking and re-adding your repo. Пароль должен быть длиннее 8 символов. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.sk.ts b/src/vorta/i18n/ts/vorta.sk.ts index 8b123ceb..c3f9025d 100644 --- a/src/vorta/i18n/ts/vorta.sk.ts +++ b/src/vorta/i18n/ts/vorta.sk.ts @@ -1357,8 +1357,8 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Upgrade schémy skončil s chybou, otvorte hlásenie o chybe kliknutím na odkaz na karte Rôzne a skopírujte tento text: {0} @@ -2128,4 +2128,4 @@ Skúste tento repozitár odpojiť a opäť pridať. Heslá musia obsahovať aspoň 8 znakov. - \ No newline at end of file + diff --git a/src/vorta/i18n/ts/vorta.sv.ts b/src/vorta/i18n/ts/vorta.sv.ts index f6367b0f..5d0cfb85 100644 --- a/src/vorta/i18n/ts/vorta.sv.ts +++ b/src/vorta/i18n/ts/vorta.sv.ts @@ -1210,8 +1210,8 @@ - Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: - {0} + Schema upgrade failure, file a bug report with the link in the Misc tab with the following error: + {0} {1} Schemauppgraderingsfel, skicka en felrapport med hjälp av länken i diversefliken och ange följande fel: {0} @@ -1890,4 +1890,4 @@ Försök avlänka och återansluta ditt förråd. Lösenord måste vara längre än 8 tecken. - \ No newline at end of file + diff --git a/tests/conftest.py b/tests/conftest.py index f5fe1613..9350489c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,8 +20,17 @@ from vorta.store.models import ( ) from vorta.views.main_window import MainWindow -models = [RepoModel, RepoPassword, BackupProfileModel, SourceFileModel, - SettingsModel, ArchiveModel, WifiSettingModel, EventLogModel, SchemaVersion] +models = [ + RepoModel, + RepoPassword, + BackupProfileModel, + SourceFileModel, + SettingsModel, + ArchiveModel, + WifiSettingModel, + EventLogModel, + SchemaVersion, +] def pytest_configure(config): @@ -38,6 +47,7 @@ def qapp(tmpdir_factory): vorta.store.connection.init_db(mock_db) from vorta.application import VortaApp + VortaApp.set_borg_details_action = MagicMock() # Can't use pytest-mock in session scope VortaApp.scheduler = MagicMock() @@ -51,7 +61,12 @@ def qapp(tmpdir_factory): @pytest.fixture(scope='function', autouse=True) def init_db(qapp, qtbot, tmpdir_factory): tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite') - mock_db = SqliteDatabase(str(tmp_db), pragmas={'journal_mode': 'wal', }) + mock_db = SqliteDatabase( + str(tmp_db), + pragmas={ + 'journal_mode': 'wal', + }, + ) vorta.store.connection.init_db(mock_db) default_profile = BackupProfileModel(name='Default') @@ -72,8 +87,7 @@ def init_db(qapp, qtbot, tmpdir_factory): test_archive1 = ArchiveModel(snapshot_id='99998', name='test-archive1', time=dt(2000, 1, 1, 0, 0), repo=1) test_archive1.save() - source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo, dir_size=100, dir_files_count=18, - path_isdir=True) + source_dir = SourceFileModel(dir='/tmp/another', repo=new_repo, dir_size=100, dir_files_count=18, path_isdir=True) source_dir.save() qapp.main_window.deleteLater() @@ -110,6 +124,7 @@ def borg_json_output(): stdout = open(f'tests/borg_json_output/{subcommand}_stdout.json') stderr = open(f'tests/borg_json_output/{subcommand}_stderr.json') return stdout, stderr + return _read_json diff --git a/tests/network_manager/test_darwin.py b/tests/network_manager/test_darwin.py index 57ac8abd..70c96cd2 100644 --- a/tests/network_manager/test_darwin.py +++ b/tests/network_manager/test_darwin.py @@ -2,10 +2,13 @@ import pytest from vorta.network_status import darwin -@pytest.mark.parametrize('getpacket_output_name, expected', [ - ('normal_router', False), - ('phone', True), -]) +@pytest.mark.parametrize( + 'getpacket_output_name, expected', + [ + ('normal_router', False), + ('phone', True), + ], +) def test_is_network_metered(getpacket_output_name, expected, monkeypatch): def mock_getpacket(device): assert device == 'en0' @@ -80,7 +83,7 @@ router (ip_mult): {192.168.43.242} domain_name_server (ip_mult): {192.168.43.242} vendor_specific (opaque): 0000 41 4e 44 52 4f 49 44 5f 4d 45 54 45 52 45 44 ANDROID_METERED -""" +""", } NETWORKSETUP_OUTPUT = b"""\ diff --git a/tests/network_manager/test_network_manager.py b/tests/network_manager/test_network_manager.py index 8e58221c..2c27a0d1 100644 --- a/tests/network_manager/test_network_manager.py +++ b/tests/network_manager/test_network_manager.py @@ -14,10 +14,7 @@ from vorta.network_status.network_manager import ( @pytest.fixture def mock_adapter(): - return MagicMock( - spec_set=NetworkManagerDBusAdapter, - wraps=UncallableNetworkManagerDBusAdapter() - ) + return MagicMock(spec_set=NetworkManagerDBusAdapter, wraps=UncallableNetworkManagerDBusAdapter()) @pytest.fixture @@ -29,13 +26,16 @@ def test_is_network_status_available(nm_monitor): assert nm_monitor.is_network_status_available() is True -@pytest.mark.parametrize('global_metered_status, expected', [ - (NMMetered.UNKNOWN, False), - (NMMetered.YES, True), - (NMMetered.NO, False), - (NMMetered.GUESS_YES, True), - (NMMetered.GUESS_NO, False), -]) +@pytest.mark.parametrize( + 'global_metered_status, expected', + [ + (NMMetered.UNKNOWN, False), + (NMMetered.YES, True), + (NMMetered.NO, False), + (NMMetered.GUESS_YES, True), + (NMMetered.GUESS_NO, False), + ], +) def test_is_network_metered(global_metered_status, expected, nm_monitor): nm_monitor._nm.get_global_metered_status.return_value = global_metered_status @@ -44,17 +44,22 @@ def test_is_network_metered(global_metered_status, expected, nm_monitor): assert result == expected -@pytest.mark.parametrize('connection_path, connection_type, type_settings, expected', [ - ('/org/freedesktop/NetworkManager/ActiveConnection/1', - '802-11-wireless', {'ssid': bytes([84, 69, 83, 84])}, 'TEST'), - ('/org/freedesktop/NetworkManager/ActiveConnection/2', - '802-11-ethernet', {}, None), -]) +@pytest.mark.parametrize( + 'connection_path, connection_type, type_settings, expected', + [ + ( + '/org/freedesktop/NetworkManager/ActiveConnection/1', + '802-11-wireless', + {'ssid': bytes([84, 69, 83, 84])}, + 'TEST', + ), + ('/org/freedesktop/NetworkManager/ActiveConnection/2', '802-11-ethernet', {}, None), + ], +) def test_get_current_wifi(connection_path, connection_type, type_settings, expected, nm_monitor): nm_monitor._nm.get_primary_connection_path.return_value = connection_path nm_monitor._nm.get_active_connection_info.return_value = ActiveConnectionInfo( - connection='/org/freedesktop/NetworkManager/Settings/12', - type=connection_type + connection='/org/freedesktop/NetworkManager/Settings/12', type=connection_type ) nm_monitor._nm.get_settings.side_effect = [{connection_type: type_settings}] @@ -78,10 +83,12 @@ def test_get_known_wifis(nm_monitor): result = nm_monitor.get_known_wifis() - assert result == [SystemWifiInfo( - ssid='TEST', - last_connected=datetime(2020, 8, 13, 7, 28, 56), - )] + assert result == [ + SystemWifiInfo( + ssid='TEST', + last_connected=datetime(2020, 8, 13, 7, 28, 56), + ) + ] def test_get_known_wifis_with_never_used_connection(nm_monitor): @@ -93,10 +100,12 @@ def test_get_known_wifis_with_never_used_connection(nm_monitor): result = nm_monitor.get_known_wifis() - assert result == [SystemWifiInfo( - ssid='TEST', - last_connected=None, - )] + assert result == [ + SystemWifiInfo( + ssid='TEST', + last_connected=None, + ) + ] def test_get_known_wifis_partial_failure(nm_monitor): @@ -114,10 +123,12 @@ def test_get_known_wifis_partial_failure(nm_monitor): result = nm_monitor.get_known_wifis() - assert result == [SystemWifiInfo( - ssid='TEST', - last_connected=None, - )] + assert result == [ + SystemWifiInfo( + ssid='TEST', + last_connected=None, + ) + ] def test_get_known_wifis_with_no_wifi_connections(nm_monitor): @@ -132,11 +143,14 @@ def test_get_known_wifis_with_no_wifi_connections(nm_monitor): assert result == [] -@pytest.mark.parametrize('ssid_bytes, expected', [ - ([84, 69, 83, 84], 'TEST'), - ([240, 159, 150, 150], '🖖'), - ([0, 1, 2, 10, 34, 39], '\\x00\\x01\\x02\\n"\''), -]) +@pytest.mark.parametrize( + 'ssid_bytes, expected', + [ + ([84, 69, 83, 84], 'TEST'), + ([240, 159, 150, 150], '🖖'), + ([0, 1, 2, 10, 34, 39], '\\x00\\x01\\x02\\n"\''), + ], +) def test_decode_ssid(ssid_bytes, expected): result = decode_ssid(ssid_bytes) assert result == expected diff --git a/tests/test_archives.py b/tests/test_archives.py index 52e19515..9386202e 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -76,8 +76,7 @@ def test_repo_compact(qapp, qtbot, mocker, borg_json_output): qtbot.mouseClick(tab.compactButton, QtCore.Qt.LeftButton) qtbot.waitUntil( - lambda: 'compaction freed about 56.00 kB repository space' in main.logText.text(), - **pytest._wait_defaults + lambda: 'compaction freed about 56.00 kB repository space' in main.logText.text(), **pytest._wait_defaults ) vorta.utils.borg_compat.version = '1.1.0' @@ -102,9 +101,7 @@ def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_d DiskPartitions = namedtuple('DiskPartitions', ['device', 'mountpoint']) return [DiskPartitions('borgfs', '/tmp')] - monkeypatch.setattr( - psutil, "disk_partitions", psutil_disk_partitions - ) + monkeypatch.setattr(psutil, "disk_partitions", psutil_disk_partitions) main = qapp.main_window tab = main.archiveTab @@ -116,9 +113,7 @@ def test_mount(qapp, qtbot, mocker, borg_json_output, monkeypatch, choose_file_d popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0) mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result) - monkeypatch.setattr( - vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog - ) + monkeypatch.setattr(vorta.views.archive_tab, "choose_file_dialog", choose_file_dialog) tab.bmountarchive_clicked() qtbot.waitUntil(lambda: tab.mountErrors.text().startswith('Mounted'), **pytest._wait_defaults) diff --git a/tests/test_diff.py b/tests/test_diff.py index edd60ea2..a4e265d4 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -7,8 +7,9 @@ import vorta.views.archive_tab from vorta.views.diff_result import ChangeType, DiffData, DiffTree, FileType, parse_diff_json, parse_diff_lines -@pytest.mark.parametrize('json_mock_file,folder_root', [ - ('diff_archives', 'test'), ('diff_archives_dict_issue', 'Users')]) +@pytest.mark.parametrize( + 'json_mock_file,folder_root', [('diff_archives', 'test'), ('diff_archives_dict_issue', 'Users')] +) def test_archive_diff(qapp, qtbot, mocker, borg_json_output, json_mock_file, folder_root): main = qapp.main_window tab = main.archiveTab @@ -27,6 +28,7 @@ def test_archive_diff(qapp, qtbot, mocker, borg_json_output, json_mock_file, fol if feature_name == 'DIFF_JSON_LINES': return False return vorta.utils.BorgCompatibility.check(compat, feature_name) + mocker.patch.object(vorta.utils.borg_compat, 'check', check) selection_model: QItemSelectionModel = tab.archiveTable.selectionModel() @@ -52,42 +54,74 @@ def test_archive_diff(qapp, qtbot, mocker, borg_json_output, json_mock_file, fol @pytest.mark.parametrize( 'line, expected', [ - ('changed link some/changed/link', - ('some/changed/link', FileType.LINK, ChangeType.CHANGED_LINK, 0, 0, - None, None, None)), - (' +77.8 kB -77.8 kB some/changed/file', - ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, 2 * 77800, - 0, None, None, - (77800, 77800))), - (' +77.8 kB -77.8 kB [-rw-rw-rw- -> -rw-r--r--] some/changed/file', - ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, 2 * 77800, 0, - ('-rw-rw-rw-', '-rw-r--r--'), None, (77800, 77800))), - ('[-rw-rw-rw- -> -rw-r--r--] some/changed/file', - ('some/changed/file', FileType.FILE, ChangeType.MODE, 0, 0, - ('-rw-rw-rw-', '-rw-r--r--'), None, None)), - ('added directory some/changed/dir', - ('some/changed/dir', FileType.DIRECTORY, ChangeType.ADDED, 0, 0, None, - None, None)), - ('removed directory some/changed/dir', - ('some/changed/dir', FileType.DIRECTORY, ChangeType.REMOVED_DIR, 0, 0, - None, None, None)), - + ( + 'changed link some/changed/link', + ('some/changed/link', FileType.LINK, ChangeType.CHANGED_LINK, 0, 0, None, None, None), + ), + ( + ' +77.8 kB -77.8 kB some/changed/file', + ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, 2 * 77800, 0, None, None, (77800, 77800)), + ), + ( + ' +77.8 kB -77.8 kB [-rw-rw-rw- -> -rw-r--r--] some/changed/file', + ( + 'some/changed/file', + FileType.FILE, + ChangeType.MODIFIED, + 2 * 77800, + 0, + ('-rw-rw-rw-', '-rw-r--r--'), + None, + (77800, 77800), + ), + ), + ( + '[-rw-rw-rw- -> -rw-r--r--] some/changed/file', + ('some/changed/file', FileType.FILE, ChangeType.MODE, 0, 0, ('-rw-rw-rw-', '-rw-r--r--'), None, None), + ), + ( + 'added directory some/changed/dir', + ('some/changed/dir', FileType.DIRECTORY, ChangeType.ADDED, 0, 0, None, None, None), + ), + ( + 'removed directory some/changed/dir', + ('some/changed/dir', FileType.DIRECTORY, ChangeType.REMOVED_DIR, 0, 0, None, None, None), + ), # Example from https://github.com/borgbase/vorta/issues/521 - ('[user:user -> nfsnobody:nfsnobody] home/user/arrays/test.txt', - ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, - None, ('user', 'user', 'nfsnobody', 'nfsnobody'), None)), - + ( + '[user:user -> nfsnobody:nfsnobody] home/user/arrays/test.txt', + ( + 'home/user/arrays/test.txt', + FileType.FILE, + ChangeType.OWNER, + 0, + 0, + None, + ('user', 'user', 'nfsnobody', 'nfsnobody'), + None, + ), + ), # Very short owner change, to check stripping whitespace from file path - ('[a:a -> b:b] home/user/arrays/test.txt', - ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, - None, ('a', 'a', 'b', 'b'), None)), - + ( + '[a:a -> b:b] home/user/arrays/test.txt', + ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, None, ('a', 'a', 'b', 'b'), None), + ), # All file-related changes in one test - (' +77.8 kB -800 B [user:user -> nfsnobody:nfsnobody] [-rw-rw-rw- -> -rw-r--r--] home/user/arrays/test.txt', - ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, - 77800 + 800, 77000, ('-rw-rw-rw-', '-rw-r--r--'), - ('user', 'user', 'nfsnobody', 'nfsnobody'), (77800, 800))), - ]) + ( + ' +77.8 kB -800 B [user:user -> nfsnobody:nfsnobody] [-rw-rw-rw- -> -rw-r--r--] home/user/arrays/test.txt', + ( + 'home/user/arrays/test.txt', + FileType.FILE, + ChangeType.OWNER, + 77800 + 800, + 77000, + ('-rw-rw-rw-', '-rw-r--r--'), + ('user', 'user', 'nfsnobody', 'nfsnobody'), + (77800, 800), + ), + ), + ], +) def test_archive_diff_parser(line, expected): model = DiffTree() model.setMode(model.DisplayMode.FLAT) @@ -103,113 +137,110 @@ def test_archive_diff_parser(line, expected): @pytest.mark.parametrize( 'line, expected', [ - ({ - 'path': 'some/changed/link', - 'changes': [{ - 'type': 'changed link' - }] - }, ('some/changed/link', FileType.LINK, ChangeType.CHANGED_LINK, 0, 0, - None, None, None)), - ({ - 'path': 'some/changed/file', - 'changes': [{ - 'type': 'modified', - 'added': 77800, - 'removed': 77800 - }] - }, ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, 2 * 77800, - 0, None, None, (77800, 77800))), - ({ - 'path': - 'some/changed/file', - 'changes': [{ - 'type': 'modified', - 'added': 77800, - 'removed': 800 - }, { - 'type': 'mode', - 'old_mode': '-rw-rw-rw-', - 'new_mode': '-rw-r--r--' - }] - }, ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, - 77800 + 800, 77000, ('-rw-rw-rw-', '-rw-r--r--'), None, - (77800, 800))), - ({ - 'path': - 'some/changed/file', - 'changes': [{ - 'type': 'mode', - 'old_mode': '-rw-rw-rw-', - 'new_mode': '-rw-r--r--' - }] - }, ('some/changed/file', FileType.FILE, ChangeType.MODE, 0, 0, - ('-rw-rw-rw-', '-rw-r--r--'), None, None)), - ({ - 'path': 'some/changed/dir', - 'changes': [{ - 'type': 'added directory' - }] - }, ('some/changed/dir', FileType.DIRECTORY, ChangeType.ADDED, 0, 0, - None, None, None)), - ({ - 'path': 'some/changed/dir', - 'changes': [{ - 'type': 'removed directory' - }] - }, ('some/changed/dir', FileType.DIRECTORY, ChangeType.REMOVED_DIR, 0, - 0, None, None, None)), - + ( + {'path': 'some/changed/link', 'changes': [{'type': 'changed link'}]}, + ('some/changed/link', FileType.LINK, ChangeType.CHANGED_LINK, 0, 0, None, None, None), + ), + ( + {'path': 'some/changed/file', 'changes': [{'type': 'modified', 'added': 77800, 'removed': 77800}]}, + ('some/changed/file', FileType.FILE, ChangeType.MODIFIED, 2 * 77800, 0, None, None, (77800, 77800)), + ), + ( + { + 'path': 'some/changed/file', + 'changes': [ + {'type': 'modified', 'added': 77800, 'removed': 800}, + {'type': 'mode', 'old_mode': '-rw-rw-rw-', 'new_mode': '-rw-r--r--'}, + ], + }, + ( + 'some/changed/file', + FileType.FILE, + ChangeType.MODIFIED, + 77800 + 800, + 77000, + ('-rw-rw-rw-', '-rw-r--r--'), + None, + (77800, 800), + ), + ), + ( + { + 'path': 'some/changed/file', + 'changes': [{'type': 'mode', 'old_mode': '-rw-rw-rw-', 'new_mode': '-rw-r--r--'}], + }, + ('some/changed/file', FileType.FILE, ChangeType.MODE, 0, 0, ('-rw-rw-rw-', '-rw-r--r--'), None, None), + ), + ( + {'path': 'some/changed/dir', 'changes': [{'type': 'added directory'}]}, + ('some/changed/dir', FileType.DIRECTORY, ChangeType.ADDED, 0, 0, None, None, None), + ), + ( + {'path': 'some/changed/dir', 'changes': [{'type': 'removed directory'}]}, + ('some/changed/dir', FileType.DIRECTORY, ChangeType.REMOVED_DIR, 0, 0, None, None, None), + ), # Example from https://github.com/borgbase/vorta/issues/521 - ({ - 'path': - 'home/user/arrays/test.txt', - 'changes': [{ - 'type': 'owner', - 'old_user': 'user', - 'new_user': 'nfsnobody', - 'old_group': 'user', - 'new_group': 'nfsnobody' - }] - }, ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, - None, ('user', 'user', 'nfsnobody', 'nfsnobody'), None)), - + ( + { + 'path': 'home/user/arrays/test.txt', + 'changes': [ + { + 'type': 'owner', + 'old_user': 'user', + 'new_user': 'nfsnobody', + 'old_group': 'user', + 'new_group': 'nfsnobody', + } + ], + }, + ( + 'home/user/arrays/test.txt', + FileType.FILE, + ChangeType.OWNER, + 0, + 0, + None, + ('user', 'user', 'nfsnobody', 'nfsnobody'), + None, + ), + ), # Very short owner change, to check stripping whitespace from file path - ({ - 'path': - 'home/user/arrays/test.txt', - 'changes': [{ - 'type': 'owner', - 'old_user': 'a', - 'new_user': 'b', - 'old_group': 'a', - 'new_group': 'b' - }] - }, ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, - None, ('a', 'a', 'b', 'b'), None)), - + ( + { + 'path': 'home/user/arrays/test.txt', + 'changes': [{'type': 'owner', 'old_user': 'a', 'new_user': 'b', 'old_group': 'a', 'new_group': 'b'}], + }, + ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, 0, 0, None, ('a', 'a', 'b', 'b'), None), + ), # All file-related changes in one test - ({ - 'path': - 'home/user/arrays/test.txt', - 'changes': [{ - 'type': 'modified', - 'added': 77800, - 'removed': 77800 - }, { - 'type': 'mode', - 'old_mode': '-rw-rw-rw-', - 'new_mode': '-rw-r--r--' - }, { - 'type': 'owner', - 'old_user': 'user', - 'new_user': 'nfsnobody', - 'old_group': 'user', - 'new_group': 'nfsnobody' - }] - }, ('home/user/arrays/test.txt', FileType.FILE, ChangeType.OWNER, - 2 * 77800, 0, ('-rw-rw-rw-', '-rw-r--r--'), - ('user', 'user', 'nfsnobody', 'nfsnobody'), (77800, 77800))), - ]) + ( + { + 'path': 'home/user/arrays/test.txt', + 'changes': [ + {'type': 'modified', 'added': 77800, 'removed': 77800}, + {'type': 'mode', 'old_mode': '-rw-rw-rw-', 'new_mode': '-rw-r--r--'}, + { + 'type': 'owner', + 'old_user': 'user', + 'new_user': 'nfsnobody', + 'old_group': 'user', + 'new_group': 'nfsnobody', + }, + ], + }, + ( + 'home/user/arrays/test.txt', + FileType.FILE, + ChangeType.OWNER, + 2 * 77800, + 0, + ('-rw-rw-rw-', '-rw-r--r--'), + ('user', 'user', 'nfsnobody', 'nfsnobody'), + (77800, 77800), + ), + ), + ], +) def test_archive_diff_json_parser(line, expected): model = DiffTree() model.setMode(model.DisplayMode.FLAT) diff --git a/tests/test_import_export.py b/tests/test_import_export.py index 1029b948..5e80d0eb 100644 --- a/tests/test_import_export.py +++ b/tests/test_import_export.py @@ -52,9 +52,7 @@ def test_import_fail_not_json(qapp, rootdir, monkeypatch): def getOpenFileName(*args, **kwargs): return [BAD_FILE] - monkeypatch.setattr( - QFileDialog, "getOpenFileName", getOpenFileName - ) + monkeypatch.setattr(QFileDialog, "getOpenFileName", getOpenFileName) alert_message = None @@ -62,9 +60,7 @@ def test_import_fail_not_json(qapp, rootdir, monkeypatch): nonlocal alert_message alert_message = message - monkeypatch.setattr( - QMessageBox, "critical", critical - ) + monkeypatch.setattr(QMessageBox, "critical", critical) main = qapp.main_window main.profile_import_action() @@ -79,9 +75,7 @@ def test_export_success(qapp, qtbot, tmpdir, monkeypatch): def getSaveFileName(*args, **kwargs): return [FILE_PATH] - monkeypatch.setattr( - QFileDialog, "getSaveFileName", getSaveFileName - ) + monkeypatch.setattr(QFileDialog, "getSaveFileName", getSaveFileName) main = qapp.main_window main.profile_export_action() @@ -99,9 +93,7 @@ def test_export_fail_unwritable(qapp, qtbot, tmpdir, monkeypatch): def getSaveFileName(*args, **kwargs): return [FILE_PATH] - monkeypatch.setattr( - QFileDialog, "getSaveFileName", getSaveFileName - ) + monkeypatch.setattr(QFileDialog, "getSaveFileName", getSaveFileName) alert_message = None @@ -109,9 +101,7 @@ def test_export_fail_unwritable(qapp, qtbot, tmpdir, monkeypatch): nonlocal alert_message alert_message = message - monkeypatch.setattr( - QMessageBox, "critical", critical - ) + monkeypatch.setattr(QMessageBox, "critical", critical) main = qapp.main_window main.profile_export_action() diff --git a/tests/test_misc.py b/tests/test_misc.py index de6ca646..1f721f9f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -7,15 +7,14 @@ from PyQt5.QtWidgets import QCheckBox, QFormLayout def test_autostart(qapp, qtbot): - ''' Check if file exists only on Linux, otherwise just check it doesn't crash ''' + '''Check if file exists only on Linux, otherwise just check it doesn't crash''' main = qapp.main_window main.tabWidget.setCurrentIndex(4) tab = main.miscTab def click_autostart(): for x in range(0, tab.checkboxLayout.count()): - item = tab.checkboxLayout.itemAt(x, - QFormLayout.ItemRole.FieldRole) + item = tab.checkboxLayout.itemAt(x, QFormLayout.ItemRole.FieldRole) if not item: continue checkbox = item.widget() @@ -29,14 +28,16 @@ def test_autostart(qapp, qtbot): click_autostart() if sys.platform == 'linux': - autostart_path = Path(os.environ.get( - "XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") / "vorta.desktop" + autostart_path = ( + Path(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") + / "vorta.desktop" + ) qtbot.waitUntil(lambda: autostart_path.exists(), **pytest._wait_defaults) with open(autostart_path) as desktop_file: desktop_file_text = desktop_file.read() - assert (desktop_file_text.startswith("[Desktop Entry]")) + assert desktop_file_text.startswith("[Desktop Entry]") click_autostart() if sys.platform == 'linux': diff --git a/tests/test_repo.py b/tests/test_repo.py index c306dd10..e1da84a6 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -57,8 +57,9 @@ def test_repo_unlink(qapp, qtbot): qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton) # -1 is the repo id in this test - qtbot.waitUntil(lambda: main.progressText.text().startswith('Add a backup repository first.'), - **pytest._wait_defaults) + qtbot.waitUntil( + lambda: main.progressText.text().startswith('Add a backup repository first.'), **pytest._wait_defaults + ) assert main.progressText.text() == 'Add a backup repository first.' @@ -74,7 +75,7 @@ def test_password_autofill(qapp, qtbot): qtbot.keyClicks(add_repo_window.repoURL, test_repo_url) - assert (add_repo_window.passwordLineEdit.text() == password) + assert add_repo_window.passwordLineEdit.text() == password def test_repo_add_success(qapp, qtbot, mocker, borg_json_output): @@ -93,9 +94,9 @@ def test_repo_add_success(qapp, qtbot, mocker, borg_json_output): mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result) add_repo_window.run() - qtbot.waitUntil(lambda: EventLogModel.select() - .where(EventLogModel.returncode == 0).count() == 2, - **pytest._wait_defaults) + qtbot.waitUntil( + lambda: EventLogModel.select().where(EventLogModel.returncode == 0).count() == 2, **pytest._wait_defaults + ) assert RepoModel.get(id=2).url == test_repo_url diff --git a/tests/test_schedule.py b/tests/test_schedule.py index 25c9abb1..7b896929 100644 --- a/tests/test_schedule.py +++ b/tests/test_schedule.py @@ -56,12 +56,14 @@ def test_schedule_tab(qapp: VortaApp, qtbot, clockmock): profile = BackupProfileModel.get(name=PROFILE_NAME) profile.schedule_make_up_missed = False profile.save() - event = EventLogModel(subcommand='create', - profile=profile.id, - returncode=0, - category='scheduled', - start_time=last_time, - end_time=last_time) + event = EventLogModel( + subcommand='create', + profile=profile.id, + returncode=0, + category='scheduled', + start_time=last_time, + end_time=last_time, + ) event.save() qapp.scheduler.set_timer_for_profile(profile.id) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 5952b1ad..12c6eea8 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -25,15 +25,12 @@ def clockmock(monkeypatch): def prepare(func): """Decorator adding common preparation steps.""" + @wraps(func) def do(qapp, qtbot, mocker, borg_json_output): stdout, stderr = borg_json_output('create') - popen_result = mocker.MagicMock(stdout=stdout, - stderr=stderr, - returncode=0) - mocker.patch.object(vorta.borg.borg_job, - 'Popen', - return_value=popen_result) + popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0) + mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result) return func(qapp, qtbot, mocker, borg_json_output) @@ -81,12 +78,9 @@ def test_simple_schedule(clockmock): profile.schedule_interval_count = 3 profile.save() - event = EventLogModel(subcommand='create', - profile=profile.id, - returncode=0, - category='scheduled', - start_time=time, - end_time=time) + event = EventLogModel( + subcommand='create', profile=profile.id, returncode=0, category='scheduled', start_time=time, end_time=time + ) event.save() # test set timer and next_job @@ -94,7 +88,8 @@ def test_simple_schedule(clockmock): assert len(scheduler.timers) == 1 assert scheduler.next_job() == '07:30 ({})'.format(PROFILE_NAME) assert scheduler.next_job_for_profile(profile.id) == ScheduleStatus( - ScheduleStatusType.SCHEDULED, dt(2020, 5, 6, 7, 30)) + ScheduleStatusType.SCHEDULED, dt(2020, 5, 6, 7, 30) + ) # test remove_job and next_job scheduler.remove_job(profile.id) @@ -109,21 +104,17 @@ def test_simple_schedule(clockmock): [ # simple (td(), td(hours=4, minutes=30), 'hours', 3, td(hours=3)), - # next day (td(), td(hours=4, minutes=30), 'hours', 20, td(hours=20)), - # passed by less than interval (td(hours=2), td(hours=4, minutes=30), 'hours', 3, td(hours=1)), - # passed by exactly interval (td(hours=3), td(hours=4, minutes=30), 'hours', 3, td(hours=3)), - # passed by multiple times the interval - (td(hours=7), td(hours=4, minutes=30), 'hours', 3, td(hours=2)) - ]) -def test_interval(clockmock, passed_time, scheduled, now, unit, count, - added_time): + (td(hours=7), td(hours=4, minutes=30), 'hours', 3, td(hours=2)), + ], +) +def test_interval(clockmock, passed_time, scheduled, now, unit, count, added_time): """Test scheduling in interval mode.""" # setup scheduler = VortaScheduler() @@ -138,12 +129,14 @@ def test_interval(clockmock, passed_time, scheduled, now, unit, count, profile.schedule_interval_count = count profile.save() - event = EventLogModel(subcommand='create', - profile=profile.id, - returncode=0, - category='scheduled' if scheduled else '', - start_time=time - passed_time, - end_time=time - passed_time) + event = EventLogModel( + subcommand='create', + profile=profile.id, + returncode=0, + category='scheduled' if scheduled else '', + start_time=time - passed_time, + end_time=time - passed_time, + ) event.save() # run test @@ -152,19 +145,16 @@ def test_interval(clockmock, passed_time, scheduled, now, unit, count, @mark.parametrize("scheduled", [True, False]) -@mark.parametrize( - "passed_time", - [td(hours=0), td(hours=5), - td(hours=14), td(hours=27)]) +@mark.parametrize("passed_time", [td(hours=0), td(hours=5), td(hours=14), td(hours=27)]) @mark.parametrize( "now, hour, minute", [ # same day (td(hours=4, minutes=30), 15, 00), - # next day (td(hours=4, minutes=30), 3, 30), - ]) + ], +) def test_fixed(clockmock, passed_time, scheduled, now, hour, minute): """Test scheduling in fixed mode.""" # setup @@ -181,12 +171,14 @@ def test_fixed(clockmock, passed_time, scheduled, now, hour, minute): profile.save() last_time = time - passed_time - event = EventLogModel(subcommand='create', - profile=profile.id, - returncode=0, - category='scheduled' if scheduled else '', - start_time=last_time, - end_time=last_time) + event = EventLogModel( + subcommand='create', + profile=profile.id, + returncode=0, + category='scheduled' if scheduled else '', + start_time=last_time, + end_time=last_time, + ) event.save() # run test diff --git a/tests/test_source.py b/tests/test_source.py index 55743ec5..a4209576 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -3,9 +3,7 @@ import vorta.views def test_add_folder(qapp, qtbot, mocker, monkeypatch, choose_file_dialog): - monkeypatch.setattr( - vorta.views.source_tab, "choose_file_dialog", choose_file_dialog - ) + monkeypatch.setattr(vorta.views.source_tab, "choose_file_dialog", choose_file_dialog) main = qapp.main_window main.tabWidget.setCurrentIndex(1) tab = main.sourceTab diff --git a/tests/test_treemodel.py b/tests/test_treemodel.py index bbe64123..40dffe78 100644 --- a/tests/test_treemodel.py +++ b/tests/test_treemodel.py @@ -142,8 +142,7 @@ class TestFileTreeModel: assert item is not None and item.data == 3 # test parent - assert (model.parent(model.indexPath( - PurePath('test/subtest'))) == model.indexPath(PurePath('test'))) + assert model.parent(model.indexPath(PurePath('test/subtest'))) == model.indexPath(PurePath('test')) # test index item1 = model.getItem(('test',))