Przeglądaj źródła

fix binary_archiver tests for modern exit codes

Thomas Waldmann 10 miesięcy temu
rodzic
commit
39e0109f43

+ 2 - 1
src/borg/testsuite/archiver/config_cmd.py

@@ -52,7 +52,8 @@ def test_config(archivers, request):
 
     cmd(archiver, "config", "--list", "--delete", exit_code=2)
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "config", exit_code=2)
+        expected_ec = CommandError().exit_code
+        cmd(archiver, "config", exit_code=expected_ec)
     else:
         with pytest.raises(CommandError):
             cmd(archiver, "config")

+ 8 - 2
src/borg/testsuite/archiver/create_cmd.py

@@ -366,7 +366,10 @@ def test_create_content_from_command_with_failed_command(archivers, request):
     archiver = request.getfixturevalue(archivers)
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        output = cmd(archiver, "create", "--content-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=2)
+        expected_ec = CommandError().exit_code
+        output = cmd(
+            archiver, "create", "--content-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=expected_ec
+        )
         assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
     else:
         with pytest.raises(CommandError):
@@ -418,7 +421,10 @@ def test_create_paths_from_command_with_failed_command(archivers, request):
     archiver = request.getfixturevalue(archivers)
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        output = cmd(archiver, "create", "--paths-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=2)
+        expected_ec = CommandError().exit_code
+        output = cmd(
+            archiver, "create", "--paths-from-command", "test", "--", "sh", "-c", "exit 73;", exit_code=expected_ec
+        )
         assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
     else:
         with pytest.raises(CommandError):

+ 11 - 6
src/borg/testsuite/archiver/key_cmds.py

@@ -6,7 +6,7 @@ import pytest
 from ...constants import *  # NOQA
 from ...crypto.key import AESOCBRepoKey, AESOCBKeyfileKey, CHPOKeyfileKey, Passphrase
 from ...crypto.keymanager import RepoIdMismatch, NotABorgKeyFile
-from ...helpers import EXIT_ERROR, CommandError
+from ...helpers import CommandError
 from ...helpers import bin_to_hex, hex_to_bin
 from ...helpers import msgpack
 from ...repository import Repository
@@ -171,7 +171,8 @@ def test_key_export_directory(archivers, request):
     os.mkdir(export_directory)
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "key", "export", export_directory, exit_code=EXIT_ERROR)
+        expected_ec = CommandError().exit_code
+        cmd(archiver, "key", "export", export_directory, exit_code=expected_ec)
     else:
         with pytest.raises(CommandError):
             cmd(archiver, "key", "export", export_directory)
@@ -183,7 +184,8 @@ def test_key_export_qr_directory(archivers, request):
     os.mkdir(export_directory)
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "key", "export", "--qr-html", export_directory, exit_code=EXIT_ERROR)
+        expected_ec = CommandError().exit_code
+        cmd(archiver, "key", "export", "--qr-html", export_directory, exit_code=expected_ec)
     else:
         with pytest.raises(CommandError):
             cmd(archiver, "key", "export", "--qr-html", export_directory)
@@ -194,7 +196,8 @@ def test_key_import_errors(archivers, request):
     export_file = archiver.output_path + "/exported"
     cmd(archiver, "rcreate", KF_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "key", "import", export_file, exit_code=EXIT_ERROR)
+        expected_ec = CommandError().exit_code
+        cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
     else:
         with pytest.raises(CommandError):
             cmd(archiver, "key", "import", export_file)
@@ -203,7 +206,8 @@ def test_key_import_errors(archivers, request):
         fd.write("something not a key\n")
 
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "key", "import", export_file, exit_code=2)
+        expected_ec = NotABorgKeyFile().exit_code
+        cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
     else:
         with pytest.raises(NotABorgKeyFile):
             cmd(archiver, "key", "import", export_file)
@@ -212,7 +216,8 @@ def test_key_import_errors(archivers, request):
         fd.write("BORG_KEY a0a0a0\n")
 
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "key", "import", export_file, exit_code=2)
+        expected_ec = RepoIdMismatch().exit_code
+        cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
     else:
         with pytest.raises(RepoIdMismatch):
             cmd(archiver, "key", "import", export_file)

+ 2 - 1
src/borg/testsuite/archiver/rcreate_cmd.py

@@ -56,7 +56,8 @@ def test_rcreate_nested_repositories(archivers, request):
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     archiver.repository_location += "/nested"
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "rcreate", RK_ENCRYPTION, exit_code=2)
+        expected_ec = Repository.AlreadyExists().exit_code
+        cmd(archiver, "rcreate", RK_ENCRYPTION, exit_code=expected_ec)
     else:
         with pytest.raises(Repository.AlreadyExists):
             cmd(archiver, "rcreate", RK_ENCRYPTION)

+ 2 - 1
src/borg/testsuite/archiver/rdelete_cmd.py

@@ -18,7 +18,8 @@ def test_delete_repo(archivers, request):
     cmd(archiver, "create", "test.2", "input")
     os.environ["BORG_DELETE_I_KNOW_WHAT_I_AM_DOING"] = "no"
     if archiver.FORK_DEFAULT:
-        cmd(archiver, "rdelete", exit_code=2)
+        expected_ec = CancelledByUser().exit_code
+        cmd(archiver, "rdelete", exit_code=expected_ec)
     else:
         with pytest.raises(CancelledByUser):
             cmd(archiver, "rdelete")

+ 2 - 1
src/borg/testsuite/archiver/recreate_cmd.py

@@ -84,7 +84,8 @@ def test_recreate_target_rc(archivers, request):
     archiver = request.getfixturevalue(archivers)
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     if archiver.FORK_DEFAULT:
-        output = cmd(archiver, "recreate", "--target=asdf", exit_code=2)
+        expected_ec = CommandError().exit_code
+        output = cmd(archiver, "recreate", "--target=asdf", exit_code=expected_ec)
         assert "Need to specify single archive" in output
     else:
         with pytest.raises(CommandError):