refactor test_return_codes

... so works in a similar way as test_exit_codes.
This commit is contained in:
Thomas Waldmann 2025-04-17 17:57:38 +02:00
parent 0b284db33a
commit 8ec48ffb05
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -3,28 +3,28 @@ import os
from ...constants import * # NOQA
from ...helpers import IncludePatternNeverMatchedWarning
from ...repository import Repository
from . import cmd, cmd_fixture, changedir, generate_archiver_tests # NOQA
from . import cmd, changedir, generate_archiver_tests # NOQA
pytest_generate_tests = lambda metafunc: generate_archiver_tests(metafunc, kinds="local,remote,binary") # NOQA
def test_return_codes(cmd_fixture, tmpdir):
repo = tmpdir / "repo" # borg creates the directory
input = tmpdir.mkdir("input")
output = tmpdir.mkdir("output")
input.join("test_file").write("content")
rc, out = cmd_fixture("--repo=%s" % str(repo), "repo-create", "--encryption=none")
assert rc == EXIT_SUCCESS
rc, out = cmd_fixture("--repo=%s" % repo, "create", "archive", str(input))
assert rc == EXIT_SUCCESS
with changedir(str(output)):
rc, out = cmd_fixture("--repo=%s" % repo, "extract", "archive")
assert rc == EXIT_SUCCESS
rc, out = cmd_fixture("--repo=%s" % repo, "extract", "archive", "does/not/match")
assert rc == IncludePatternNeverMatchedWarning().exit_code
def test_return_codes(archivers, request):
archiver = request.getfixturevalue(archivers)
cmd(archiver, "repo-create", "--encryption=none")
cmd(archiver, "create", "archive", "input")
with changedir("output"):
cmd(archiver, "extract", "archive")
cmd(
archiver,
"extract",
"archive",
"does/not/match",
fork=True,
exit_code=IncludePatternNeverMatchedWarning().exit_code,
)
def test_exit_codes(archivers, request, tmpdir, monkeypatch):
def test_exit_codes(archivers, request, monkeypatch):
archiver = request.getfixturevalue(archivers)
# we create the repo path, but do NOT initialize the borg repo,
# so the borg create commands are expected to fail with DoesNotExist (was: InvalidRepository in borg 1.4).