from pathlib import Path import sys import pytest SCRIPTS = Path(__file__).resolve().parents[1] / "scripts" sys.path.insert(0, str(SCRIPTS)) from flow_network import FlowNetwork # noqa: E402 def test_returns_all_upstream_reaches_without_including_target(): network = FlowNetwork( [ ("headwater-a", "confluence"), ("headwater-b", "confluence"), ("confluence", "emerson"), ] ) assert network.upstream_reaches("emerson") == { "headwater-a", "headwater-b", "confluence", } def test_rejects_cycle_in_directed_flow_network(): with pytest.raises(ValueError, match="cycle"): FlowNetwork( [ ("reach-a", "reach-b"), ("reach-b", "reach-a"), ] )