diff --git a/scripts/test_gitea_issue_parser.py b/scripts/test_gitea_issue_parser.py new file mode 100644 index 0000000..3f1af6d --- /dev/null +++ b/scripts/test_gitea_issue_parser.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +"""Tests for gitea_issue_parser.""" + +import json +import sys +import os + +sys.path.insert(0, os.path.dirname(__file__)) +from gitea_issue_parser import parse_issue_body + + +def test_basic_structure(): + body = """## Context +This is the background. + +## Acceptance Criteria +- [ ] First criterion +- [x] Second criterion (already done) +- [ ] Third criterion + +## Labels +`pipeline`, `extraction` +""" + result = parse_issue_body(body, "Test Issue", ["pipeline", "extraction"]) + assert result["title"] == "Test Issue" + assert "background" in result["context"].lower() + assert len(result["criteria"]) == 3 + assert "First criterion" in result["criteria"] + assert result["labels"] == ["pipeline", "extraction"] + print("PASS: test_basic_structure") + + +def test_epic_ref(): + body = "Closes #645\n\nSome description." + result = parse_issue_body(body, "feat: thing (#688)") + assert result["epic_ref"] == "#645" + print("PASS: test_epic_ref") + + +def test_epic_ref_from_title(): + body = "Some description without close ref." + result = parse_issue_body(body, "feat: scene descriptions (#645)") + assert result["epic_ref"] == "#645" + print("PASS: test_epic_ref_from_title") + + +def test_no_checkboxes(): + body = """## Requirements +1. First thing +2. Second thing +3. Third thing +""" + result = parse_issue_body(body) + assert len(result["criteria"]) == 3 + print("PASS: test_no_checkboxes") + + +def test_empty_body(): + result = parse_issue_body("", "Empty Issue") + assert result["title"] == "Empty Issue" + assert result["criteria"] == [] + assert result["context"] == "" + print("PASS: test_empty_body") + + +def test_real_issue_format(): + body = """Closes #681 + +## Changes + +Add `#!/usr/bin/env python3` shebang to 6 Python scripts. + +## Verification + +All 6 files confirmed missing shebangs before fix. + +## Impact + +Scripts can now be executed directly. +""" + result = parse_issue_body(body, "fix: add python3 shebangs (#685)") + assert result["epic_ref"] == "#681" + assert "shebang" in result["context"].lower() + print("PASS: test_real_issue_format") + + +def test_all_sections_captured(): + body = """## Context +Background info. + +## Acceptance Criteria +- [ ] Do thing + +## Labels +`test` +""" + result = parse_issue_body(body) + assert "context" in result["sections"] + assert "acceptance criteria" in result["sections"] + print("PASS: test_all_sections_captured") + + +if __name__ == "__main__": + test_basic_structure() + test_epic_ref() + test_epic_ref_from_title() + test_no_checkboxes() + test_empty_body() + test_real_issue_format() + test_all_sections_captured() + print("\nAll tests passed.")