Files
pkgmgr/tests/e2e/test_publish_commands.py

71 lines
2.0 KiB
Python
Raw Permalink Normal View History

from __future__ import annotations
import os
import shutil
import subprocess
import unittest
2025-12-14 21:08:23 +01:00
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
2025-12-14 21:08:23 +01:00
def _run_help(cmd: list[str], label: str) -> str:
print(f"\n[TEST] Running ({label}): {' '.join(cmd)}")
proc = subprocess.run(
cmd,
2025-12-14 21:08:23 +01:00
cwd=PROJECT_ROOT,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False,
env=os.environ.copy(),
)
2025-12-14 21:08:23 +01:00
print(proc.stdout.rstrip())
# For --help we expect success (0). Anything else is an error.
if proc.returncode != 0:
raise AssertionError(
f"[TEST] Help command failed ({label}).\n"
f"Command: {' '.join(cmd)}\n"
f"Exit code: {proc.returncode}\n"
f"--- output ---\n{proc.stdout}\n"
)
2025-12-14 21:08:23 +01:00
return proc.stdout
2025-12-14 21:08:23 +01:00
class TestPublishHelpE2E(unittest.TestCase):
def test_pkgmgr_publish_help(self) -> None:
out = _run_help(["pkgmgr", "publish", "--help"], "pkgmgr publish --help")
self.assertIn("usage:", out)
self.assertIn("publish", out)
2025-12-14 21:08:23 +01:00
def test_pkgmgr_help_mentions_publish(self) -> None:
out = _run_help(["pkgmgr", "--help"], "pkgmgr --help")
self.assertIn("publish", out)
2025-12-14 21:08:23 +01:00
def test_nix_run_pkgmgr_publish_help(self) -> None:
if shutil.which("nix") is None:
self.skipTest("nix is not available in this environment")
2025-12-14 21:08:23 +01:00
out = _run_help(
["nix", "run", ".#pkgmgr", "--", "publish", "--help"],
"nix run .#pkgmgr -- publish --help",
)
2025-12-14 21:08:23 +01:00
self.assertIn("usage:", out)
self.assertIn("publish", out)
2025-12-14 21:08:23 +01:00
def test_nix_run_pkgmgr_help_mentions_publish(self) -> None:
if shutil.which("nix") is None:
self.skipTest("nix is not available in this environment")
2025-12-14 21:08:23 +01:00
out = _run_help(
["nix", "run", ".#pkgmgr", "--", "--help"],
"nix run .#pkgmgr -- --help",
)
2025-12-14 21:08:23 +01:00
self.assertIn("publish", out)
2025-12-14 21:08:23 +01:00
if __name__ == "__main__":
unittest.main()