52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SCRIPT = ROOT / "scripts" / "playbook.py"
|
|
|
|
|
|
def run_cli(*args):
|
|
return subprocess.run(
|
|
[sys.executable, str(SCRIPT), *args],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
|
|
class PlaybookCliTests(unittest.TestCase):
|
|
def test_help_shows_usage(self):
|
|
result = run_cli("-h")
|
|
self.assertEqual(result.returncode, 0)
|
|
self.assertIn("Usage:", result.stdout + result.stderr)
|
|
|
|
def test_missing_config_is_error(self):
|
|
result = run_cli()
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("-config", result.stdout + result.stderr)
|
|
|
|
def test_action_order(self):
|
|
config_body = """
|
|
[playbook]
|
|
project_root = "."
|
|
|
|
[format_md]
|
|
|
|
[sync_standards]
|
|
langs = ["tsl"]
|
|
"""
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
config_path = Path(tmp_dir) / "playbook.toml"
|
|
config_path.write_text(config_body, encoding="utf-8")
|
|
result = run_cli("-config", str(config_path))
|
|
|
|
self.assertEqual(result.returncode, 0)
|
|
output = result.stdout + result.stderr
|
|
self.assertIn("sync_standards", output)
|
|
self.assertIn("format_md", output)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|