Files
yiyezhqiu-refactored/tests/domain/test_schedule.py
T

91 lines
2.3 KiB
Python

from dx_productivity.domain.schedule import build_apply_schedule
def _triples(steps):
return [
(step.bridge_id, step.expected_refdes, step.new_refdes) for step in steps
]
def test_schedule_breaks_refdes_swap_with_prefix_placeholder(plan_row_factory):
rows = (
plan_row_factory("a", "R1", "R2"),
plan_row_factory("b", "R2", "R1"),
)
steps = build_apply_schedule(rows)
assert _triples(steps) == [
("a", "R1", "R?"),
("b", "R2", "R1"),
("a", "R?", "R2"),
]
assert [step.sequence for step in steps] == [1, 2, 3]
assert [step.final_refdes for step in steps] == ["R2", "R1", "R2"]
def test_schedule_orders_acyclic_dependency_from_tail(plan_row_factory):
rows = (
plan_row_factory("a", "R1", "R2"),
plan_row_factory("b", "R2", "R3"),
)
steps = build_apply_schedule(rows)
assert _triples(steps) == [("b", "R2", "R3"), ("a", "R1", "R2")]
def test_schedule_breaks_three_component_cycle_deterministically(plan_row_factory):
rows = (
plan_row_factory("c", "R3", "R1"),
plan_row_factory("b", "R2", "R3"),
plan_row_factory("a", "R1", "R2"),
)
steps = build_apply_schedule(rows)
assert _triples(steps) == [
("a", "R1", "R?"),
("c", "R3", "R1"),
("b", "R2", "R3"),
("a", "R?", "R2"),
]
def test_schedule_ignores_preserved_rows(plan_row_factory):
row = plan_row_factory("a", "R1", "R1", changed=False, status="preserved")
assert build_apply_schedule((row,)) == ()
def test_schedule_allows_restore_to_blank_reference(plan_row_factory):
row = plan_row_factory("a", "R1", "")
steps = build_apply_schedule((row,))
assert _triples(steps) == [("a", "R1", "")]
def test_schedule_rejects_duplicate_targets_across_rows(plan_row_factory):
rows = (
plan_row_factory("a", "R1", "R2"),
plan_row_factory("b", "R?", "R2"),
)
import pytest
with pytest.raises(ValueError, match="duplicate target"):
build_apply_schedule(rows)
def test_schedule_rejects_duplicate_suffixed_targets(plan_row_factory):
rows = (
plan_row_factory("a", "R1", "R2A"),
plan_row_factory("b", "R?", "R2A"),
)
import pytest
with pytest.raises(ValueError, match="duplicate target"):
build_apply_schedule(rows)