Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
* Remove legacy *main.py* and introduce *pkgmgr* module entry via *python -m pkgmgr* * Add ***main**.py* as the canonical entry point delegating to the CLI * Export *PYTHONPATH=src* in Makefile to ensure reliable imports in dev and CI * Update setup scripts (venv & nix) to use module execution * Refactor all E2E tests to execute the real module entry instead of file paths This aligns pkgmgr with standard Python packaging practices and simplifies testing, setup, and execution across environments. https://chatgpt.com/share/693c9056-716c-800f-b583-fc9245eab2b4
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import io
|
|
import runpy
|
|
import sys
|
|
import unittest
|
|
from contextlib import redirect_stdout, redirect_stderr
|
|
|
|
|
|
def _run_pkgmgr_help(argv_tail: list[str]) -> str:
|
|
"""
|
|
Run `pkgmgr <argv_tail> --help` via the main module and return captured output.
|
|
|
|
argparse parses sys.argv[1:], so argv[0] must be a dummy program name.
|
|
Any SystemExit with code 0 or None is treated as success.
|
|
"""
|
|
original_argv = list(sys.argv)
|
|
buffer = io.StringIO()
|
|
cmd_repr = "pkgmgr " + " ".join(argv_tail) + " --help"
|
|
|
|
try:
|
|
# IMPORTANT: argv[0] must be a dummy program name
|
|
sys.argv = ["pkgmgr"] + list(argv_tail) + ["--help"]
|
|
|
|
try:
|
|
with redirect_stdout(buffer), redirect_stderr(buffer):
|
|
runpy.run_module("pkgmgr", run_name="__main__")
|
|
except SystemExit as exc:
|
|
code = exc.code if isinstance(exc.code, int) else None
|
|
if code not in (0, None):
|
|
raise AssertionError(
|
|
f"{cmd_repr!r} failed with exit code {exc.code}."
|
|
) from exc
|
|
|
|
return buffer.getvalue()
|
|
finally:
|
|
sys.argv = original_argv
|
|
|
|
|
|
class TestBranchHelpE2E(unittest.TestCase):
|
|
"""
|
|
End-to-end tests ensuring that `pkgmgr branch` help commands
|
|
run without error and print usage information.
|
|
"""
|
|
|
|
def test_branch_root_help(self) -> None:
|
|
"""
|
|
`pkgmgr branch --help` should run without error.
|
|
"""
|
|
output = _run_pkgmgr_help(["branch"])
|
|
self.assertIn("usage:", output)
|
|
self.assertIn("pkgmgr branch", output)
|
|
|
|
def test_branch_open_help(self) -> None:
|
|
"""
|
|
`pkgmgr branch open --help` should run without error.
|
|
"""
|
|
output = _run_pkgmgr_help(["branch", "open"])
|
|
self.assertIn("usage:", output)
|
|
self.assertIn("branch open", output)
|
|
|
|
def test_branch_close_help(self) -> None:
|
|
"""
|
|
`pkgmgr branch close --help` should run without error.
|
|
"""
|
|
output = _run_pkgmgr_help(["branch", "close"])
|
|
self.assertIn("usage:", output)
|
|
self.assertIn("branch close", output)
|
|
|
|
def test_branch_drop_help(self) -> None:
|
|
"""
|
|
`pkgmgr branch drop --help` should run without error.
|
|
"""
|
|
output = _run_pkgmgr_help(["branch", "drop"])
|
|
self.assertIn("usage:", output)
|
|
self.assertIn("branch drop", output)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|