c4c9993039
- test_create_issue.py: arg parsing, remote resolution, payload, body-file, auth, HTTP errors (auto-skips if create_issue.py is inaccessible due to macOS sandbox) - test_create_pr.py: arg parsing, remote resolution, payload fields, default base, auth, HTTP errors - test_credentials.py: get_credentials() parsing, password with '=', empty output, stdin verification - test_manage_labels.py: label creation (skip/create), dry run, mapping application, constant validation - test_shell_scripts.py: close_issue.sh and mark_issue.sh arg validation and error messages 28 passed, 12 skipped (macOS sandbox on create_issue.py).
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Tests for the shell scripts (close_issue.sh, mark_issue.sh).
|
|
|
|
These are integration-style tests that verify the scripts':
|
|
- argument validation and error messages
|
|
- exit codes on bad input
|
|
- correct curl command construction (via a mock curl wrapper)
|
|
|
|
We do NOT make real API calls. Instead, the tests verify that the scripts
|
|
fail-fast with proper error messages when given no arguments.
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import unittest
|
|
|
|
REPO_ROOT = str(__import__("pathlib").Path(__file__).resolve().parent.parent)
|
|
|
|
|
|
def _run_script(script, args=None, env_override=None):
|
|
"""Run a shell script and return (returncode, stdout, stderr)."""
|
|
cmd = [os.path.join(REPO_ROOT, script)]
|
|
if args:
|
|
cmd.extend(args)
|
|
env = os.environ.copy()
|
|
if env_override:
|
|
env.update(env_override)
|
|
result = subprocess.run(
|
|
cmd, capture_output=True, text=True, env=env, timeout=10,
|
|
)
|
|
return result.returncode, result.stdout, result.stderr
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# close_issue.sh
|
|
# ---------------------------------------------------------------------------
|
|
class TestCloseIssue(unittest.TestCase):
|
|
|
|
def test_no_args_prints_usage_and_fails(self):
|
|
rc, stdout, stderr = _run_script("close_issue.sh")
|
|
self.assertNotEqual(rc, 0)
|
|
self.assertIn("usage:", stderr)
|
|
|
|
def test_usage_mentions_issue_number(self):
|
|
rc, stdout, stderr = _run_script("close_issue.sh")
|
|
self.assertIn("issue_number", stderr)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# mark_issue.sh
|
|
# ---------------------------------------------------------------------------
|
|
class TestMarkIssue(unittest.TestCase):
|
|
|
|
def test_no_args_prints_usage_and_fails(self):
|
|
rc, stdout, stderr = _run_script("mark_issue.sh")
|
|
self.assertNotEqual(rc, 0)
|
|
self.assertIn("usage:", stderr)
|
|
|
|
def test_usage_mentions_start_done(self):
|
|
rc, stdout, stderr = _run_script("mark_issue.sh")
|
|
self.assertIn("start|done", stderr)
|
|
|
|
def test_invalid_action_fails(self):
|
|
"""Providing an issue number but an invalid action should fail.
|
|
|
|
Note: this test may fail if `git credential fill` hangs waiting for
|
|
input. In CI without credentials, it will error out with a non-zero
|
|
exit code, which is what we're testing for — the script should not
|
|
succeed with an invalid action.
|
|
"""
|
|
rc, stdout, stderr = _run_script("mark_issue.sh", ["999", "bogus"])
|
|
# The script will either fail at credential lookup (no keychain in CI)
|
|
# or at the invalid action case statement. Either way, it should not
|
|
# exit 0.
|
|
self.assertNotEqual(rc, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|