74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
"""Tests for canonical issue workflow label policy (#513)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
import issue_workflow_labels as labels # noqa: E402
|
|
|
|
|
|
class TestIssueWorkflowLabelValidation(unittest.TestCase):
|
|
def test_valid_labeled_issue(self):
|
|
result = labels.assess_issue_labels(["type:feature", "status:ready"])
|
|
self.assertTrue(result["valid"])
|
|
self.assertEqual(result["type_labels"], ["type:feature"])
|
|
self.assertEqual(result["status_labels"], ["status:ready"])
|
|
|
|
def test_issue_missing_type_label(self):
|
|
result = labels.assess_issue_labels(["status:ready"])
|
|
self.assertFalse(result["valid"])
|
|
self.assertIn("issue is missing a type:* label", result["errors"])
|
|
|
|
def test_issue_missing_status_label(self):
|
|
result = labels.assess_issue_labels(["type:bug"])
|
|
self.assertFalse(result["valid"])
|
|
self.assertIn("issue is missing a status:* label", result["errors"])
|
|
|
|
def test_discussion_issue_missing_type_discussion(self):
|
|
result = labels.assess_issue_labels(
|
|
["type:feature", "status:triage"],
|
|
discussion=True,
|
|
)
|
|
self.assertFalse(result["valid"])
|
|
self.assertIn("discussion issue is missing type:discussion", result["errors"])
|
|
|
|
def test_multiple_conflicting_status_labels(self):
|
|
result = labels.assess_issue_labels(
|
|
["type:feature", "status:ready", "status:blocked"]
|
|
)
|
|
self.assertFalse(result["valid"])
|
|
self.assertTrue(
|
|
any("multiple active status:* labels" in err for err in result["errors"])
|
|
)
|
|
|
|
|
|
class TestIssueWorkflowStatusTransitions(unittest.TestCase):
|
|
def test_status_transition_removes_old_status_label(self):
|
|
result = labels.transition_status_labels(
|
|
["type:feature", "status:ready", "workflow"],
|
|
"in-progress",
|
|
)
|
|
self.assertEqual(result, ["type:feature", "workflow", "status:in-progress"])
|
|
|
|
def test_pr_open_transition_applies_status_pr_open(self):
|
|
result = labels.transition_status_labels(
|
|
["type:feature", "status:in-progress"],
|
|
"pr-open",
|
|
)
|
|
self.assertEqual(result, ["type:feature", "status:pr-open"])
|
|
|
|
def test_duplicate_transition_applies_status_duplicate(self):
|
|
result = labels.transition_status_labels(
|
|
["type:process", "status:triage"],
|
|
"duplicate",
|
|
)
|
|
self.assertEqual(result, ["type:process", "status:duplicate"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|