Skip to content

Commit 5b2b03a

Browse files
committed
Remove AGENTS guidelines and fix lint
1 parent 87c4455 commit 5b2b03a

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed

tests/test_failure_policy.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import pytest
21
from unittest.mock import patch
32

4-
from ngraph.failure_policy import (
5-
FailurePolicy,
6-
FailureRule,
7-
FailureCondition,
8-
_evaluate_condition,
9-
)
3+
import pytest
4+
5+
from ngraph.failure_policy import FailureCondition, FailurePolicy, FailureRule
106

117

128
def test_node_scope_all():
@@ -285,3 +281,23 @@ def test_cache_disabled():
285281
nodes["N1"]["capacity"] = 10
286282
second_fail = policy.apply_failures(nodes, links)
287283
assert set(second_fail) == set()
284+
285+
286+
def test_evaluate_conditions_invalid_logic():
287+
"""_evaluate_conditions should raise for unsupported logic values."""
288+
attrs = {"cap": 50}
289+
conds = [FailureCondition(attr="cap", operator=">=", value=10)]
290+
with pytest.raises(ValueError, match="Unsupported logic"):
291+
FailurePolicy._evaluate_conditions(attrs, conds, "xor")
292+
293+
294+
def test_select_entities_invalid_rule_type():
295+
"""_select_entities should raise for unsupported rule_type."""
296+
dummy_rule = FailureRule(
297+
entity_scope="node",
298+
conditions=[],
299+
logic="any",
300+
rule_type="bogus",
301+
)
302+
with pytest.raises(ValueError, match="Unsupported rule_type"):
303+
FailurePolicy._select_entities({"A", "B"}, dummy_rule)

tests/test_traffic_manager.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import pytest
22

3-
from ngraph.network import Network, Node, Link
4-
from ngraph.traffic_demand import TrafficDemand
3+
from ngraph.lib.algorithms.base import MIN_FLOW
54
from ngraph.lib.flow_policy import FlowPolicyConfig
65
from ngraph.lib.graph import StrictMultiDiGraph
7-
from ngraph.lib.algorithms.base import MIN_FLOW
8-
from ngraph.lib.demand import Demand
9-
6+
from ngraph.network import Link, Network, Node
7+
from ngraph.traffic_demand import TrafficDemand
108
from ngraph.traffic_manager import TrafficManager
119

1210

@@ -411,3 +409,34 @@ def test_estimate_rounds_no_capacities():
411409
total_placed = tm.place_all_demands(placement_rounds="auto")
412410
# The link has 0 capacity, so no actual flow can be placed.
413411
assert total_placed == 0.0, "No capacity => no flow placed"
412+
413+
414+
def test_get_traffic_results_aggregated_and_detailed(small_network):
415+
"""TrafficManager.get_traffic_results should summarize correctly."""
416+
demands = [
417+
TrafficDemand(source_path="A", sink_path="C", demand=10.0),
418+
TrafficDemand(source_path="B", sink_path="C", demand=5.0),
419+
]
420+
tm = TrafficManager(network=small_network, traffic_demands=demands)
421+
tm.build_graph()
422+
tm.expand_demands()
423+
tm.place_all_demands()
424+
425+
agg = tm.get_traffic_results(detailed=False)
426+
assert len(agg) == 2
427+
for res in agg:
428+
assert res.total_volume == res.placed_volume
429+
430+
detailed = tm.get_traffic_results(detailed=True)
431+
assert len(detailed) == len(tm.demands)
432+
for res in detailed:
433+
assert res.total_volume == res.placed_volume
434+
435+
436+
def test_estimate_rounds_typical_case(small_network):
437+
"""_estimate_rounds should compute rounds based on demand/capacity ratio."""
438+
demands = [TrafficDemand(source_path="A", sink_path="C", demand=20.0)]
439+
tm = TrafficManager(network=small_network, traffic_demands=demands)
440+
tm.build_graph()
441+
tm.expand_demands()
442+
assert tm._estimate_rounds() == 6

tests/workflow/test_capacity_probe.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from unittest.mock import MagicMock
2+
13
import pytest
2-
from unittest.mock import MagicMock, call
34

4-
from ngraph.network import Network, Node, Link
5-
from ngraph.workflow.capacity_probe import CapacityProbe
65
from ngraph.lib.algorithms.base import FlowPlacement
6+
from ngraph.network import Link, Network, Node
7+
from ngraph.workflow.capacity_probe import CapacityProbe
78

89

910
@pytest.fixture
@@ -244,3 +245,9 @@ def test_capacity_probe_probe_reverse(mock_scenario):
244245
assert "max_flow:[B -> A]" in flows
245246
assert flows["max_flow:[A -> B]"] == 3.0
246247
assert flows["max_flow:[B -> A]"] == 3.0
248+
249+
250+
def test_capacity_probe_invalid_flow_placement():
251+
"""Invalid flow_placement string should raise ValueError."""
252+
with pytest.raises(ValueError, match="Invalid flow_placement"):
253+
CapacityProbe(name="Bad", flow_placement="bogus")

0 commit comments

Comments
 (0)