From 91dd71e3b15c39e61490b1bbc5c1fc2d5813c2cf Mon Sep 17 00:00:00 2001 From: bigtedde Date: Fri, 7 Jul 2023 16:49:01 -0400 Subject: [PATCH] lock_cmds converted --- src/borg/testsuite/archiver/lock_cmds.py | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/borg/testsuite/archiver/lock_cmds.py b/src/borg/testsuite/archiver/lock_cmds.py index 797ce7a28..7cbc62ae6 100644 --- a/src/borg/testsuite/archiver/lock_cmds.py +++ b/src/borg/testsuite/archiver/lock_cmds.py @@ -1,26 +1,26 @@ import os -import unittest from ...constants import * # NOQA -from . import ArchiverTestCaseBase, RemoteArchiverTestCaseBase, ArchiverTestCaseBinaryBase, RK_ENCRYPTION, BORG_EXES +from . import cmd, RK_ENCRYPTION -class ArchiverTestCase(ArchiverTestCaseBase): - def test_break_lock(self): - self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) - self.cmd(f"--repo={self.repository_location}", "break-lock") - - def test_with_lock(self): - self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) - lock_path = os.path.join(self.repository_path, "lock.exclusive") - cmd = "python3", "-c", 'import os, sys; sys.exit(42 if os.path.exists("%s") else 23)' % lock_path - self.cmd(f"--repo={self.repository_location}", "with-lock", *cmd, fork=True, exit_code=42) +def pytest_generate_tests(metafunc): + # Generate tests for different scenarios: local repository, remote repository, and using the borg binary. + if "archivers" in metafunc.fixturenames: + metafunc.parametrize("archivers", ["archiver", "remote_archiver", "binary_archiver"]) -class RemoteArchiverTestCase(RemoteArchiverTestCaseBase, ArchiverTestCase): - """run the same tests, but with a remote repository""" +def test_break_lock(archivers, request): + archiver = request.getfixturevalue(archivers) + repo_location = archiver.repository_location + cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION) + cmd(archiver, f"--repo={repo_location}", "break-lock") -@unittest.skipUnless("binary" in BORG_EXES, "no borg.exe available") -class ArchiverTestCaseBinary(ArchiverTestCaseBinaryBase, ArchiverTestCase): - """runs the same tests, but via the borg binary""" +def test_with_lock(archivers, request): + archiver = request.getfixturevalue(archivers) + repo_location, repo_path = archiver.repository_location, archiver.repository_path + cmd(archiver, f"--repo={repo_location}", "rcreate", RK_ENCRYPTION) + lock_path = os.path.join(repo_path, "lock.exclusive") + command = "python3", "-c", 'import os, sys; sys.exit(42 if os.path.exists("%s") else 23)' % lock_path + cmd(archiver, f"--repo={repo_location}", "with-lock", *command, fork=True, exit_code=42)