Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archiver folder - all tests converted from unittest to pytest #7722

Merged
merged 55 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2cf784d
combined all tests into one single Archiver folder PR
bigtedde Jul 4, 2023
d18525a
debug_cmds added
bigtedde Jul 4, 2023
99bf56c
delete_cmd converted
bigtedde Jul 4, 2023
dfaea06
diff_cmd converted
bigtedde Jul 4, 2023
95d48c0
disk_full converted
bigtedde Jul 4, 2023
5bc1bbd
extract_cmd converted
bigtedde Jul 5, 2023
a438176
help_cmd converted
bigtedde Jul 7, 2023
b5901eb
merge upstream changes
bigtedde Jul 7, 2023
725149c
info_cmd converted, edited generate tests comment
bigtedde Jul 7, 2023
3cccf19
key_cmds converted
bigtedde Jul 7, 2023
08ab716
list_cmd converted
bigtedde Jul 7, 2023
91dd71e
lock_cmds converted
bigtedde Jul 7, 2023
0a104a3
mount_cmds converted
bigtedde Jul 7, 2023
7e14361
patterns converted
bigtedde Jul 7, 2023
a4fc546
prune_cmd converted
bigtedde Jul 8, 2023
216f138
rcompress_cmd converted
bigtedde Jul 8, 2023
a3bfc4d
rdelete_cmd converted
bigtedde Jul 9, 2023
673cd47
rcreate_cmd converted
bigtedde Jul 9, 2023
c68e0b9
recreate_cmd converted
bigtedde Jul 9, 2023
227f439
rename_cmd converted
bigtedde Jul 9, 2023
0f160cd
return_codes converted
bigtedde Jul 9, 2023
116428c
rinfo_cmd converted
bigtedde Jul 9, 2023
a9cf42f
rlist_cmd
bigtedde Jul 9, 2023
5cdbf03
rlist_cmd converted
bigtedde Jul 9, 2023
9a8fb00
serve_cmd converted
bigtedde Jul 9, 2023
6ca4e15
fixed issue in test_unix_socket
bigtedde Jul 9, 2023
751bac0
tar_cmds converted
bigtedde Jul 9, 2023
6cb87e5
transfer_cmd converted
bigtedde Jul 9, 2023
efc4481
removed erroneous test from init
bigtedde Jul 9, 2023
f1af13e
removed unittest skips
bigtedde Jul 9, 2023
ed02164
fixed fuse_mount CM
bigtedde Jul 9, 2023
2c5f664
changed socket path to secure temp file
bigtedde Jul 9, 2023
62bfd5e
create_cmd changes
bigtedde Jul 9, 2023
912df41
test_unix_socket fix
bigtedde Jul 10, 2023
1e5c62f
test_unix_socket fix
bigtedde Jul 10, 2023
fdb21af
cleanup bypass_lock_option tests
bigtedde Jul 13, 2023
f502941
check_cmd cleaned up
bigtedde Jul 13, 2023
b2d8210
testsuite/benchmark.py - 'cmd' -> 'cmd_fixture'
bigtedde Jul 13, 2023
73c178d
cleanup create_cmd
bigtedde Jul 13, 2023
9a8d5da
ValueError added in 'open_repository'
bigtedde Jul 13, 2023
7fea384
removed print statement from transfer_cmd
bigtedde Jul 13, 2023
eb37f4b
corrupted_archiver changed from fixture to function call
bigtedde Jul 13, 2023
225fdb0
increased readability in delete_cmd
bigtedde Jul 13, 2023
3a7ee07
debug_cmds cleanup
bigtedde Jul 13, 2023
535b336
delete_cmd cleanup
bigtedde Jul 13, 2023
bbb5340
diff_cmd cleanup
bigtedde Jul 13, 2023
0c899a7
extract_cmd cleanup
bigtedde Jul 14, 2023
fcddbc6
Fixed: camelcase, generate test dupe, init vars declerations, general…
bigtedde Jul 16, 2023
8a5664d
remote archiver prefix check
bigtedde Jul 16, 2023
7f1847e
typehint and initialize variable in ArchiverSetup init
bigtedde Jul 16, 2023
975a094
generate_archiver_tests added: generate tests by specifying kinds of …
bigtedde Jul 19, 2023
0fa1034
removed 'prefix'
bigtedde Jul 20, 2023
683bf72
redundent comments
bigtedde Jul 21, 2023
b8b80c5
get_kind added to ArchiverSetup
bigtedde Jul 21, 2023
6f35f5b
simplified remote repo check
bigtedde Jul 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,20 @@ def set_env_variables():
class ArchiverSetup:
EXE: str = None # python source based
FORK_DEFAULT = False
prefix = ""
BORG_EXES = []

def __init__(self):
self.archiver = None
self.tmpdir = str
self.repository_path = str
self.repository_location = str
self.input_path = str
self.output_path = str
self.keys_path = str
self.cache_path = str
self.exclude_file_path = str
self.patterns_file_path = str
self.old_wd = str
self.tmpdir: str
self.prefix = ""
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved
self.repository_path: str
self.repository_location: str
self.input_path: str
self.output_path: str
self.keys_path: str
self.cache_path: str
self.exclude_file_path: str
self.patterns_file_path: str
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved

ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture()
Expand All @@ -129,10 +128,10 @@ def archiver(tmp_path, set_env_variables):
fd.write(b"input/file2\n# A comment line, then a blank line\n\n")
with open(archiver.patterns_file_path, "wb") as fd:
fd.write(b"+input/file_important\n- input/file*\n# A comment line, then a blank line\n\n")
archiver.old_wd = os.getcwd()
old_wd = os.getcwd()
os.chdir(archiver.tmpdir)
yield archiver
os.chdir(archiver.old_wd)
os.chdir(old_wd)


@pytest.fixture()
Expand Down
14 changes: 9 additions & 5 deletions src/borg/testsuite/archiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, input=b"", binary_outpu
try:
ret = archiver.run(args) # calls setup_logging internally
finally:
flush_logging() # usually done at exit, but we do not exit here
flush_logging() # usually done via atexit, but we do not exit here
output_text.flush()
return ret, output.getvalue() if binary_output else output.getvalue().decode()
finally:
Expand Down Expand Up @@ -119,6 +119,12 @@ def exec_fn(*args, **kw):
return exec_fn


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"])


def checkts(ts):
# check if the timestamp is in the expected format
assert datetime.strptime(ts, ISO_FORMAT + "%z") # must not raise
Expand Down Expand Up @@ -159,12 +165,10 @@ def open_archive(repo_path, name):


def open_repository(archiver):
if archiver.prefix == "":
return Repository(archiver.repository_path, exclusive=True)
elif archiver.prefix == "ssh://__testsuite__":
if archiver.repository_location.startswith("ssh://__testsuite__"):
return RemoteRepository(Location(archiver.repository_location))
else:
raise ValueError(f"Archiver prefix '{archiver.prefix}' is not a valid prefix.")
return Repository(archiver.repository_path, exclusive=True)


def create_regular_file(input_path, name, size=0, contents=None):
Expand Down
36 changes: 15 additions & 21 deletions src/borg/testsuite/archiver/check_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@
from ...helpers import msgpack
from ...manifest import Manifest
from ...repository import Repository
from . import src_file
from . import cmd, create_src_archive, open_archive, RK_ENCRYPTION
from . import pytest_generate_tests # NOQA
from . import cmd, src_file, create_src_archive, open_archive, RK_ENCRYPTION


def check_cmd_setUp(archiver):
def check_cmd_setup(archiver):
with patch.object(ChunkBuffer, "BUFFER_SIZE", 10):
cmd(archiver, f"--repo={archiver.repository_location}", "rcreate", RK_ENCRYPTION)
create_src_archive(archiver, "archive1")
create_src_archive(archiver, "archive2")


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"])


def test_check_usage(archivers, request):
archiver = request.getfixturevalue(archivers)
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
repo_location = archiver.repository_location

output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--progress", exit_code=0)
Expand Down Expand Up @@ -61,7 +55,7 @@ def test_check_usage(archivers, request):

def test_date_matching(archivers, request):
archiver = request.getfixturevalue(archivers)
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
repo_location, repo_path = archiver.repository_location, archiver.repository_path

shutil.rmtree(repo_path)
Expand Down Expand Up @@ -102,7 +96,7 @@ def test_date_matching(archivers, request):
def test_missing_file_chunk(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)

archive, repository = open_archive(repo_path, "archive1")

Expand Down Expand Up @@ -165,7 +159,7 @@ def test_missing_file_chunk(archivers, request):
def test_missing_archive_item_chunk(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")

with repository:
Expand All @@ -180,7 +174,7 @@ def test_missing_archive_item_chunk(archivers, request):
def test_missing_archive_metadata(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")

with repository:
Expand All @@ -195,7 +189,7 @@ def test_missing_archive_metadata(archivers, request):
def test_missing_manifest(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")

with repository:
Expand All @@ -212,7 +206,7 @@ def test_missing_manifest(archivers, request):
def test_corrupted_manifest(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")

with repository:
Expand All @@ -231,7 +225,7 @@ def test_corrupted_manifest(archivers, request):
def test_manifest_rebuild_corrupted_chunk(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")

with repository:
Expand All @@ -252,7 +246,7 @@ def test_manifest_rebuild_corrupted_chunk(archivers, request):
def test_manifest_rebuild_duplicate_archive(archivers, request):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
archive, repository = open_archive(repo_path, "archive1")
repo_objs = archive.repo_objs

Expand Down Expand Up @@ -288,7 +282,7 @@ def test_extra_chunks(archivers, request):
if archiver.prefix:
pytest.skip("only works locally")
repo_location = archiver.repository_location
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)

with Repository(repo_location, exclusive=True) as repository:
Expand All @@ -306,7 +300,7 @@ def test_extra_chunks(archivers, request):
def test_verify_data(archivers, request, init_args):
archiver = request.getfixturevalue(archivers)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
check_cmd_setup(archiver)
shutil.rmtree(repo_path)
cmd(archiver, f"--repo={repo_location}", "rcreate", *init_args)
create_src_archive(archiver, "archive1")
Expand Down Expand Up @@ -337,7 +331,7 @@ def test_empty_repository(archivers, request):
if archiver.prefix:
pytest.skip("only works locally")
repo_location = archiver.repository_location
check_cmd_setUp(archiver)
check_cmd_setup(archiver)

with Repository(repo_location, exclusive=True) as repository:
for id_ in repository.list():
Expand Down
2 changes: 1 addition & 1 deletion src/borg/testsuite/archiver/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cmd_raises_unknown_feature(archiver, args):


def pytest_generate_tests(metafunc):
# Generate tests for different scenarios: local repository, remote repository, and using the borg binary.
# Generate tests for local and remote archivers
if "archivers" in metafunc.fixturenames:
metafunc.parametrize("archivers", ["archiver", "remote_archiver"])
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
8 changes: 1 addition & 7 deletions src/borg/testsuite/archiver/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
same_ts_ns,
is_root,
)

from . import pytest_generate_tests # NOQA
from . import (
cmd,
create_test_files,
Expand All @@ -44,12 +44,6 @@
)


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"])


def test_basic_functionality(archivers, request):
archiver = request.getfixturevalue(archivers)
if archiver.EXE:
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/debug_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
from .. import changedir
from ..compress import Compressor
from . import cmd, create_test_files, create_regular_file, RK_ENCRYPTION


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"])
from . import pytest_generate_tests # NOQA


def test_debug_profile(archivers, request):
Expand Down
9 changes: 2 additions & 7 deletions src/borg/testsuite/archiver/delete_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
from ...constants import * # NOQA
from ...manifest import Manifest
from ...repository import Repository
from . import cmd, create_regular_file, RK_ENCRYPTION, src_file, create_src_archive


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"])
from . import cmd, create_regular_file, src_file, create_src_archive, RK_ENCRYPTION
from . import pytest_generate_tests # NOQA


def test_delete(archivers, request):
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/diff_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
from .. import are_symlinks_supported, are_hardlinks_supported
from ..platform import is_win32, is_darwin
from . import cmd, create_regular_file, RK_ENCRYPTION, assert_line_exists


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"])
from . import pytest_generate_tests # NOQA


def test_basic_functionality(archivers, request):
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/extract_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .. import changedir, same_ts_ns
from .. import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported, is_birthtime_fully_supported
from ..platform import is_darwin, is_win32
from . import pytest_generate_tests # NOQA
from . import (
RK_ENCRYPTION,
requires_hardlinks,
Expand All @@ -26,12 +27,6 @@
)


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"])


@pytest.mark.skipif(not are_symlinks_supported(), reason="symlinks not supported")
def test_symlink_extract(archivers, request):
archiver = request.getfixturevalue(archivers)
Expand Down
9 changes: 2 additions & 7 deletions src/borg/testsuite/archiver/info_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
import os

from ...constants import * # NOQA
from . import cmd, RK_ENCRYPTION, checkts, create_regular_file


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"])
from . import cmd, checkts, create_regular_file, RK_ENCRYPTION
from . import pytest_generate_tests # NOQA


def test_info(archivers, request):
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/key_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
from .. import environment_variable
from .. import key
from . import RK_ENCRYPTION, KF_ENCRYPTION, cmd, _extract_repository_id, _set_repository_id


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"])
from . import pytest_generate_tests # NOQA


def test_change_passphrase(archivers, request):
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@

from ...constants import * # NOQA
from . import src_dir, cmd, create_regular_file, RK_ENCRYPTION


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"])
from . import pytest_generate_tests # NOQA


def test_list_format(archivers, request):
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/lock_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

from ...constants import * # NOQA
from . import cmd, RK_ENCRYPTION


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"])
from . import pytest_generate_tests # NOQA


def test_break_lock(archivers, request):
Expand Down
11 changes: 3 additions & 8 deletions src/borg/testsuite/archiver/mount_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
from .. import changedir, no_selinux, same_ts_ns
from .. import are_symlinks_supported, are_hardlinks_supported, are_fifos_supported
from ..platform import fakeroot_detected
from . import RK_ENCRYPTION, cmd, assert_dirs_equal, create_regular_file, create_src_archive, open_archive
from . import src_file, requires_hardlinks, _extract_hardlinks_setup, fuse_mount, create_test_files


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"])
from . import RK_ENCRYPTION, cmd, assert_dirs_equal, create_regular_file, create_src_archive, open_archive, src_file
from . import requires_hardlinks, _extract_hardlinks_setup, fuse_mount, create_test_files
from . import pytest_generate_tests # NOQA


@requires_hardlinks
Expand Down
7 changes: 1 addition & 6 deletions src/borg/testsuite/archiver/prune_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@

from ...constants import * # NOQA
from . import cmd, RK_ENCRYPTION, src_dir


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"])
from . import pytest_generate_tests # NOQA


def _create_archive_ts(archiver, name, y, m, d, H=0, M=0, S=0):
Expand Down
Loading