feat(docs): implement slice 8 documentation triad, man page, completions and Gitea Actions CI/CD
Build and Publish Release / test-and-release (push) Failing after 48s
Build and Publish Release / test-and-release (push) Failing after 48s
This commit is contained in:
1 parent
c5c3b87bd9
commit
6f23f14b76
14 files changed
+1730
-10
No files matched your search
@@ -0,0 +1,59 @@
|
||||
"""Unit tests for shell completions and CLI help."""
|
||||
|
||||
import io
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from linux_backuper.cli import main
|
||||
from linux_backuper.core.completions import generate_completion
|
||||
|
||||
|
||||
class TestCompletions(unittest.TestCase):
|
||||
"""Test shell autocompletion generator and CLI output."""
|
||||
|
||||
def test_generate_bash_completion(self):
|
||||
script = generate_completion("bash")
|
||||
self.assertIn("_linux_backuper()", script)
|
||||
self.assertIn("complete -F _linux_backuper linux-backuper", script)
|
||||
self.assertIn("snapshot list show diff extract restore prune push verify completion", script)
|
||||
|
||||
def test_generate_zsh_completion(self):
|
||||
script = generate_completion("zsh")
|
||||
self.assertIn("#compdef linux-backuper", script)
|
||||
self.assertIn("_linux_backuper()", script)
|
||||
self.assertIn("snapshot:Capture a new system state snapshot", script)
|
||||
|
||||
def test_generate_invalid_shell(self):
|
||||
with self.assertRaises(ValueError):
|
||||
generate_completion("fish")
|
||||
|
||||
def test_cli_completion_subcommand_bash(self):
|
||||
stdout_buf = io.StringIO()
|
||||
with patch("sys.stdout", stdout_buf):
|
||||
code = main(["completion", "bash"])
|
||||
self.assertEqual(code, 0)
|
||||
out = stdout_buf.getvalue()
|
||||
self.assertIn("complete -F _linux_backuper linux-backuper", out)
|
||||
|
||||
def test_cli_completion_subcommand_zsh(self):
|
||||
stdout_buf = io.StringIO()
|
||||
with patch("sys.stdout", stdout_buf):
|
||||
code = main(["completion", "zsh"])
|
||||
self.assertEqual(code, 0)
|
||||
out = stdout_buf.getvalue()
|
||||
self.assertIn("#compdef linux-backuper", out)
|
||||
|
||||
def test_cli_help(self):
|
||||
stdout_buf = io.StringIO()
|
||||
with patch("sys.stdout", stdout_buf):
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
main(["--help"])
|
||||
self.assertEqual(cm.exception.code, 0)
|
||||
out = stdout_buf.getvalue()
|
||||
self.assertIn("Enterprise Linux system snapshot", out)
|
||||
for subcmd in ["snapshot", "list", "show", "diff", "extract", "restore", "prune", "push", "verify", "completion"]:
|
||||
self.assertIn(subcmd, out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+22
-8
@@ -1,5 +1,4 @@
|
||||
"""Unit tests for packaging builder."""
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
import tarfile
|
||||
@@ -7,12 +6,18 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
from linux_backuper import __version__
|
||||
from packaging.build_packages import (
|
||||
build_deb_package,
|
||||
build_tar_package,
|
||||
generate_rpm_spec,
|
||||
get_version,
|
||||
)
|
||||
|
||||
repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
builder_path = os.path.join(repo_root, "packaging", "build_packages.py")
|
||||
|
||||
spec = importlib.util.spec_from_file_location("build_packages", builder_path)
|
||||
build_packages_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(build_packages_mod)
|
||||
|
||||
build_deb_package = build_packages_mod.build_deb_package
|
||||
build_tar_package = build_packages_mod.build_tar_package
|
||||
generate_rpm_spec = build_packages_mod.generate_rpm_spec
|
||||
get_version = build_packages_mod.get_version
|
||||
|
||||
|
||||
class TestPackaging(unittest.TestCase):
|
||||
@@ -39,6 +44,9 @@ class TestPackaging(unittest.TestCase):
|
||||
self.assertIn(f"{prefix}/bin/linux-backuper", names)
|
||||
self.assertIn(f"{prefix}/install.sh", names)
|
||||
self.assertIn(f"{prefix}/linux_backuper/cli.py", names)
|
||||
self.assertIn(f"{prefix}/man/linux-backuper.8", names)
|
||||
self.assertIn(f"{prefix}/completions/bash/linux-backuper", names)
|
||||
self.assertIn(f"{prefix}/docs/user-guide.md", names)
|
||||
|
||||
def test_build_deb_package(self):
|
||||
deb_path = build_deb_package(self.repo_root, self.test_dir, __version__)
|
||||
@@ -91,6 +99,10 @@ class TestPackaging(unittest.TestCase):
|
||||
self.assertIn("./usr/bin/linux-backuper", dnames)
|
||||
self.assertIn("./usr/lib/linux-backuper/linux_backuper/cli.py", dnames)
|
||||
self.assertIn("./var/backups/linux-backuper", dnames)
|
||||
self.assertIn("./usr/share/man/man8/linux-backuper.8.gz", dnames)
|
||||
self.assertIn("./usr/share/bash-completion/completions/linux-backuper", dnames)
|
||||
self.assertIn("./usr/share/zsh/site-functions/_linux-backuper", dnames)
|
||||
self.assertIn("./usr/share/doc/linux-backuper/user-guide.md", dnames)
|
||||
|
||||
def test_generate_rpm_spec(self):
|
||||
spec_path = generate_rpm_spec(self.repo_root, self.test_dir, __version__)
|
||||
@@ -101,6 +113,8 @@ class TestPackaging(unittest.TestCase):
|
||||
self.assertIn(f"Version: {__version__}", content)
|
||||
self.assertIn("Requires: python3 >= 3.6", content)
|
||||
self.assertIn("/usr/bin/linux-backuper", content)
|
||||
self.assertIn("%{_mandir}/man8/linux-backuper.8*", content)
|
||||
self.assertIn("/usr/share/bash-completion/completions/linux-backuper", content)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user