Files
compounding-intelligence/scripts/test_gitea_issue_parser.py

110 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Tests for scripts/gitea_issue_parser.py"""
import sys
import os
sys.path.insert(0, os.path.dirname(__file__) or ".")
# Import from sibling
import importlib.util
spec = importlib.util.spec_from_file_location("parser", os.path.join(os.path.dirname(__file__) or ".", "gitea_issue_parser.py"))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
parse_issue_body = mod.parse_issue_body
def test_basic_parsing():
body = """## Context
This is the background info.
## Acceptance Criteria
- [ ] First criterion
- [x] Second criterion (done)
## What to build
Some description.
"""
result = parse_issue_body(body, title="Test (#42)", labels=["bug"])
assert result["title"] == "Test (#42)"
assert result["labels"] == ["bug"]
assert result["epic_ref"] == 42
assert len(result["criteria"]) == 2
assert result["criteria"][0]["text"] == "First criterion"
assert result["criteria"][0]["checked"] == False
assert result["criteria"][1]["checked"] == True
assert "context" in result["sections"]
print("PASS: test_basic_parsing")
def test_numbered_criteria():
body = """## Acceptance Criteria
1. First item
2. Second item
3. Third item
"""
result = parse_issue_body(body)
assert len(result["criteria"]) == 3
assert result["criteria"][0]["text"] == "First item"
print("PASS: test_numbered_criteria")
def test_epic_ref_from_body():
body = "Closes #123\n\nSome description."
result = parse_issue_body(body)
assert result["epic_ref"] == 123
print("PASS: test_epic_ref_from_body")
def test_empty_body():
result = parse_issue_body("")
assert result["criteria"] == []
assert result["context"] == ""
assert result["sections"] == {}
print("PASS: test_empty_body")
def test_no_sections():
body = "Just a plain issue body with no headings."
result = parse_issue_body(body)
assert result["context"] == "Just a plain issue body with no headings."
print("PASS: test_no_sections")
def test_multiple_sections():
body = """## Problem
Something is broken.
## Fix
Do this instead.
## Notes
Additional info.
"""
result = parse_issue_body(body)
assert "problem" in result["sections"]
assert "fix" in result["sections"]
assert "notes" in result["sections"]
assert "Something is broken" in result["sections"]["problem"]
print("PASS: test_multiple_sections")
def run_all():
test_basic_parsing()
test_numbered_criteria()
test_epic_ref_from_body()
test_empty_body()
test_no_sections()
test_multiple_sections()
print("\nAll 6 tests passed!")
if __name__ == "__main__":
run_all()