Applied 236 return type annotations to functions with no return values across 100+ files (core modules, tests, scripts, simulations). Added Phase 4 to python_style_refactor track for remaining 597 items (untyped params, vars, and functions with return values). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
3.6 KiB
Python
75 lines
3.6 KiB
Python
import pytest
|
|
from models import Ticket
|
|
from dag_engine import TrackDAG
|
|
|
|
def test_get_ready_tasks_linear() -> None:
|
|
t1 = Ticket(id="T1", description="Task 1", status="completed", assigned_to="worker")
|
|
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
t3 = Ticket(id="T3", description="Task 3", status="todo", assigned_to="worker", depends_on=["T2"])
|
|
dag = TrackDAG([t1, t2, t3])
|
|
ready = dag.get_ready_tasks()
|
|
assert len(ready) == 1
|
|
assert ready[0].id == "T2"
|
|
|
|
def test_get_ready_tasks_branching() -> None:
|
|
t1 = Ticket(id="T1", description="Task 1", status="completed", assigned_to="worker")
|
|
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
t3 = Ticket(id="T3", description="Task 3", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
dag = TrackDAG([t1, t2, t3])
|
|
ready = dag.get_ready_tasks()
|
|
assert len(ready) == 2
|
|
ready_ids = {t.id for t in ready}
|
|
assert ready_ids == {"T2", "T3"}
|
|
|
|
def test_has_cycle_no_cycle() -> None:
|
|
t1 = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker")
|
|
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
dag = TrackDAG([t1, t2])
|
|
assert not dag.has_cycle()
|
|
|
|
def test_has_cycle_direct_cycle() -> None:
|
|
t1 = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker", depends_on=["T2"])
|
|
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
dag = TrackDAG([t1, t2])
|
|
assert dag.has_cycle()
|
|
|
|
def test_has_cycle_indirect_cycle() -> None:
|
|
t1 = Ticket(id="T1", description="Task 1", status="todo", assigned_to="worker", depends_on=["T2"])
|
|
t2 = Ticket(id="T2", description="Task 2", status="todo", assigned_to="worker", depends_on=["T3"])
|
|
t3 = Ticket(id="T3", description="Task 3", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
dag = TrackDAG([t1, t2, t3])
|
|
assert dag.has_cycle()
|
|
|
|
def test_has_cycle_complex_no_cycle():
|
|
# T1 -> T2, T1 -> T3, T2 -> T4, T3 -> T4
|
|
t1 = Ticket(id="T1", description="T1", status="todo", assigned_to="worker", depends_on=["T2", "T3"])
|
|
t2 = Ticket(id="T2", description="T2", status="todo", assigned_to="worker", depends_on=["T4"])
|
|
t3 = Ticket(id="T3", description="T3", status="todo", assigned_to="worker", depends_on=["T4"])
|
|
t4 = Ticket(id="T4", description="T4", status="todo", assigned_to="worker")
|
|
dag = TrackDAG([t1, t2, t3, t4])
|
|
assert not dag.has_cycle()
|
|
|
|
def test_get_ready_tasks_multiple_deps() -> None:
|
|
t1 = Ticket(id="T1", description="T1", status="completed", assigned_to="worker")
|
|
t2 = Ticket(id="T2", description="T2", status="completed", assigned_to="worker")
|
|
t3 = Ticket(id="T3", description="T3", status="todo", assigned_to="worker", depends_on=["T1", "T2"])
|
|
dag = TrackDAG([t1, t2, t3])
|
|
assert [t.id for t in dag.get_ready_tasks()] == ["T3"]
|
|
t2.status = "todo"
|
|
assert [t.id for t in dag.get_ready_tasks()] == ["T2"]
|
|
|
|
def test_topological_sort() -> None:
|
|
t1 = Ticket(id="T1", description="T1", status="todo", assigned_to="worker")
|
|
t2 = Ticket(id="T2", description="T2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
t3 = Ticket(id="T3", description="T3", status="todo", assigned_to="worker", depends_on=["T2"])
|
|
dag = TrackDAG([t1, t2, t3])
|
|
sort = dag.topological_sort()
|
|
assert sort == ["T1", "T2", "T3"]
|
|
|
|
def test_topological_sort_cycle() -> None:
|
|
t1 = Ticket(id="T1", description="T1", status="todo", assigned_to="worker", depends_on=["T2"])
|
|
t2 = Ticket(id="T2", description="T2", status="todo", assigned_to="worker", depends_on=["T1"])
|
|
dag = TrackDAG([t1, t2])
|
|
with pytest.raises(ValueError, match="Dependency cycle detected"):
|
|
dag.topological_sort()
|