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 all commits
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
84 changes: 83 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os
from typing import Optional

import pytest

# needed to get pretty assertion failures in unit tests:
from borg.testsuite.archiver import BORG_EXES

if hasattr(pytest, "register_assert_rewrite"):
pytest.register_assert_rewrite("borg.testsuite")


import borg.cache # noqa: E402
from borg.archiver import Archiver
from borg.logger import setup_logging # noqa: E402

# Ensure that the loggers exist for all tests
Expand Down Expand Up @@ -73,3 +76,82 @@ def undo(self):
@pytest.fixture(autouse=True)
def default_patches(request):
return DefaultPatches(request)


@pytest.fixture()
def set_env_variables():
os.environ["BORG_CHECK_I_KNOW_WHAT_I_AM_DOING"] = "YES"
os.environ["BORG_DELETE_I_KNOW_WHAT_I_AM_DOING"] = "YES"
os.environ["BORG_PASSPHRASE"] = "waytooeasyonlyfortests"
os.environ["BORG_SELFTEST"] = "disabled"


class ArchiverSetup:
EXE: str = None # python source based
FORK_DEFAULT = False
BORG_EXES = []

def __init__(self):
self.archiver = None
self.tmpdir: Optional[str] = None
self.repository_path: Optional[str] = None
self.repository_location: Optional[str] = None
self.input_path: Optional[str] = None
self.output_path: Optional[str] = None
self.keys_path: Optional[str] = None
self.cache_path: Optional[str] = None
self.exclude_file_path: Optional[str] = None
self.patterns_file_path: Optional[str] = None

def get_kind(self) -> str:
if self.repository_location.startswith("ssh://__testsuite__"):
return "remote"
elif self.EXE == "borg.exe":
return "binary"
else:
return "local"

ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture()
def archiver(tmp_path, set_env_variables):
archiver = ArchiverSetup()
archiver.archiver = not archiver.FORK_DEFAULT and Archiver() or None
archiver.tmpdir = tmp_path
archiver.repository_path = os.fspath(tmp_path / "repository")
archiver.repository_location = archiver.repository_path
archiver.input_path = os.fspath(tmp_path / "input")
archiver.output_path = os.fspath(tmp_path / "output")
archiver.keys_path = os.fspath(tmp_path / "keys")
archiver.cache_path = os.fspath(tmp_path / "cache")
archiver.exclude_file_path = os.fspath(tmp_path / "excludes")
archiver.patterns_file_path = os.fspath(tmp_path / "patterns")
os.environ["BORG_KEYS_DIR"] = archiver.keys_path
os.environ["BORG_CACHE_DIR"] = archiver.cache_path
os.mkdir(archiver.input_path)
os.chmod(archiver.input_path, 0o777) # avoid troubles with fakeroot / FUSE
os.mkdir(archiver.output_path)
os.mkdir(archiver.keys_path)
os.mkdir(archiver.cache_path)
with open(archiver.exclude_file_path, "wb") as fd:
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")
old_wd = os.getcwd()
os.chdir(archiver.tmpdir)
yield archiver
os.chdir(old_wd)


@pytest.fixture()
def remote_archiver(archiver):
archiver.repository_location = "ssh://__testsuite__" + str(archiver.repository_path)
yield archiver


@pytest.fixture()
def binary_archiver(archiver):
if "binary" not in BORG_EXES:
pytest.skip("No borg.exe binary available")
archiver.EXE = "borg.exe"
archiver.FORK_DEFAULT = True
yield archiver
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved
Loading