146 lines
4.2 KiB
Python
146 lines
4.2 KiB
Python
"""Tests for marker parsing."""
|
|
|
|
import pytest
|
|
from discussions.markers import (
|
|
extract_vote,
|
|
extract_questions,
|
|
extract_action_items,
|
|
extract_decisions,
|
|
extract_concerns,
|
|
extract_mentions,
|
|
extract_all_markers,
|
|
)
|
|
|
|
|
|
class TestExtractVote:
|
|
def test_ready_vote(self):
|
|
assert extract_vote("VOTE: READY") == "READY"
|
|
|
|
def test_changes_vote(self):
|
|
assert extract_vote("VOTE: CHANGES") == "CHANGES"
|
|
|
|
def test_reject_vote(self):
|
|
assert extract_vote("VOTE: REJECT") == "REJECT"
|
|
|
|
def test_case_insensitive(self):
|
|
assert extract_vote("vote: ready") == "READY"
|
|
assert extract_vote("Vote: Changes") == "CHANGES"
|
|
|
|
def test_vote_in_multiline(self):
|
|
text = """Some comment here.
|
|
|
|
More text.
|
|
|
|
VOTE: READY
|
|
"""
|
|
assert extract_vote(text) == "READY"
|
|
|
|
def test_no_vote(self):
|
|
assert extract_vote("No vote here") is None
|
|
|
|
def test_invalid_vote(self):
|
|
assert extract_vote("VOTE: MAYBE") is None
|
|
|
|
|
|
class TestExtractQuestions:
|
|
def test_simple_question(self):
|
|
questions = extract_questions("Q: What about caching?", "Alice")
|
|
assert len(questions) == 1
|
|
assert questions[0].text == "What about caching?"
|
|
assert questions[0].author == "Alice"
|
|
|
|
def test_question_prefix(self):
|
|
questions = extract_questions("QUESTION: How does this scale?", "Bob")
|
|
assert len(questions) == 1
|
|
assert questions[0].text == "How does this scale?"
|
|
|
|
def test_multiple_questions(self):
|
|
text = """Q: First question?
|
|
Some text
|
|
Q: Second question?
|
|
"""
|
|
questions = extract_questions(text)
|
|
assert len(questions) == 2
|
|
|
|
def test_no_questions(self):
|
|
questions = extract_questions("Just regular text")
|
|
assert len(questions) == 0
|
|
|
|
|
|
class TestExtractActionItems:
|
|
def test_todo_item(self):
|
|
items = extract_action_items("TODO: Write tests", "Dev")
|
|
assert len(items) == 1
|
|
assert items[0].text == "Write tests"
|
|
assert items[0].author == "Dev"
|
|
assert items[0].status == "todo"
|
|
|
|
def test_action_item(self):
|
|
items = extract_action_items("ACTION: Review PR", "Dev")
|
|
assert len(items) == 1
|
|
assert items[0].text == "Review PR"
|
|
|
|
def test_with_assignee(self):
|
|
items = extract_action_items("TODO: @alice should review this", "Bob")
|
|
assert len(items) == 1
|
|
assert items[0].assignee == "alice"
|
|
|
|
|
|
class TestExtractDecisions:
|
|
def test_decision(self):
|
|
decisions = extract_decisions("DECISION: We will use Redis", "Team")
|
|
assert len(decisions) == 1
|
|
assert decisions[0].text == "We will use Redis"
|
|
assert decisions[0].author == "Team"
|
|
|
|
|
|
class TestExtractConcerns:
|
|
def test_concern(self):
|
|
concerns = extract_concerns("CONCERN: Security implications", "Steve")
|
|
assert len(concerns) == 1
|
|
assert concerns[0].text == "Security implications"
|
|
assert concerns[0].author == "Steve"
|
|
|
|
|
|
class TestExtractMentions:
|
|
def test_single_mention(self):
|
|
mentions = extract_mentions("What do you think @architect?", "Maya")
|
|
assert len(mentions) == 1
|
|
assert mentions[0].target == "architect"
|
|
assert mentions[0].author == "Maya"
|
|
|
|
def test_multiple_mentions(self):
|
|
mentions = extract_mentions("@architect and @security should review", "Lead")
|
|
assert len(mentions) == 2
|
|
targets = {m.target for m in mentions}
|
|
assert targets == {"architect", "security"}
|
|
|
|
def test_mention_all(self):
|
|
mentions = extract_mentions("@all please vote", "Moderator")
|
|
assert len(mentions) == 1
|
|
assert mentions[0].target == "all"
|
|
|
|
|
|
class TestExtractAllMarkers:
|
|
def test_full_comment(self):
|
|
text = """I have concerns about this approach.
|
|
|
|
Q: Have we considered alternatives?
|
|
|
|
CONCERN: This might not scale.
|
|
|
|
TODO: @security review threat model
|
|
|
|
DECISION: We'll proceed with option A.
|
|
|
|
VOTE: CHANGES
|
|
"""
|
|
markers = extract_all_markers(text, "Architect")
|
|
|
|
assert markers["vote"] == "CHANGES"
|
|
assert len(markers["questions"]) == 1
|
|
assert len(markers["concerns"]) == 1
|
|
assert len(markers["action_items"]) == 1
|
|
assert len(markers["decisions"]) == 1
|
|
assert len(markers["mentions"]) == 1
|