53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
import io
|
|
import unittest
|
|
from contextlib import redirect_stdout
|
|
from pathlib import Path
|
|
|
|
from linux_updater.cli import create_parser, main
|
|
from linux_updater.core.completion import get_bash_completion, get_zsh_completion
|
|
|
|
|
|
class TestCompletion(unittest.TestCase):
|
|
def test_bash_completion_content(self):
|
|
content = get_bash_completion()
|
|
self.assertIn("complete -F _linux_updater linux-updater", content)
|
|
self.assertIn("update check release-upgrade clean health completion", content)
|
|
self.assertIn("--packages", content)
|
|
self.assertIn("--exclude", content)
|
|
self.assertIn("--security", content)
|
|
self.assertIn("--flatpak", content)
|
|
|
|
def test_zsh_completion_content(self):
|
|
content = get_zsh_completion()
|
|
self.assertIn("#compdef linux-updater", content)
|
|
self.assertIn("_linux_updater", content)
|
|
self.assertIn("update:Inspect health", content)
|
|
self.assertIn("completion:Generate shell autocompletion script", content)
|
|
|
|
def test_cli_completion_bash_runs_without_root_or_lock(self):
|
|
f = io.StringIO()
|
|
with redirect_stdout(f):
|
|
exit_code = main(["completion", "bash"])
|
|
self.assertEqual(exit_code, 0)
|
|
output = f.getvalue()
|
|
self.assertIn("complete -F _linux_updater linux-updater", output)
|
|
|
|
def test_cli_completion_zsh_runs_without_root_or_lock(self):
|
|
f = io.StringIO()
|
|
with redirect_stdout(f):
|
|
exit_code = main(["completion", "zsh"])
|
|
self.assertEqual(exit_code, 0)
|
|
output = f.getvalue()
|
|
self.assertIn("#compdef linux-updater", output)
|
|
|
|
def test_static_completion_files_exist(self):
|
|
root_dir = Path(__file__).resolve().parent.parent
|
|
bash_file = root_dir / "completions" / "bash" / "linux-updater"
|
|
zsh_file = root_dir / "completions" / "zsh" / "_linux-updater"
|
|
|
|
self.assertTrue(bash_file.exists(), f"Missing {bash_file}")
|
|
self.assertTrue(zsh_file.exists(), f"Missing {zsh_file}")
|
|
|
|
self.assertEqual(bash_file.read_text(encoding="utf-8").strip(), get_bash_completion().strip())
|
|
self.assertEqual(zsh_file.read_text(encoding="utf-8").strip(), get_zsh_completion().strip())
|