Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions tests/unit/test_cashflow_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,22 +275,19 @@ def test_from_recurring_rejects_escalation_builder_override():
)


def test_from_streams():
"""
Tests the CashFlowStream.from_streams method, providing a CashFlow, a CashFlowStream,
a list of CashFlow objects, and a set of CashFlow objects as arguments.
"""
cf = CashFlow(amount=100.0, date=date(2020, 1, 1))
cf_stream_old = CashFlowStream([CashFlow(amount=-300.0, date=date(2023, 1, 1))])
cf_list = [
CashFlow(amount=200.0, date=date(2021, 1, 1)),
CashFlow(amount=-100.0, date=date(2022, 1, 1)),
]
cf_set = {CashFlow(amount=-200.0, date=date(2025, 1, 1))}
def test_from_streams_preserves_order_and_duplicates():
"""from_streams concatenates mixed input forms without removing duplicates."""
first = CashFlow(100.0, date(2026, 1, 1), label="first")
duplicate = CashFlow(200.0, date(2026, 2, 1), label="duplicate")
last = CashFlow(300.0, date(2026, 3, 1), label="last")

result = CashFlowStream.from_streams(
[first, duplicate],
CashFlowStream([duplicate]),
last,
)

cf_stream_new = CashFlowStream.from_streams(cf, cf_stream_old, cf_list, cf_set)
expected_flows = {cf, cf_stream_old.entries[0], cf_list[0], cf_list[1], list(cf_set)[0]}
assert set(cf_stream_new.entries) == expected_flows
assert result.entries == [first, duplicate, duplicate, last]


def test_from_streams_rejects_other_stream_types():
Expand Down
29 changes: 15 additions & 14 deletions tests/unit/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,21 @@ def test_from_outage_rejects_invalid_inputs():
# === GenerationStream.from_streams ===


def test_from_streams_combines():
"""from_streams combines multiple GenerationStreams."""
gs1 = GenerationStream.from_capacity(100, 0.9, date(2030, 1, 1), 2)
gs2 = GenerationStream.from_capacity(50, 0.8, date(2032, 1, 1), 3)
combined = GenerationStream.from_streams(gs1, gs2)
assert combined.count() == 5


def test_from_streams_accepts_entries_and_iterables():
"""from_streams also accepts individual Generation entries and plain iterables."""
g1 = Generation(100.0, date(2030, 1, 1))
g2 = Generation(200.0, date(2031, 1, 1))
combined = GenerationStream.from_streams(g1, [g2])
assert combined.entries == [g1, g2]
def test_from_streams_preserves_order_and_duplicates():
"""from_streams concatenates mixed input forms without removing duplicates."""
first = Generation(100.0, date(2030, 1, 1), label="first")
duplicate = Generation(200.0, date(2031, 1, 1), label="duplicate")
middle = Generation(300.0, date(2032, 1, 1), label="middle")
last = Generation(400.0, date(2033, 1, 1), label="last")

result = GenerationStream.from_streams(
[first, duplicate],
GenerationStream([duplicate]),
GenerationStream([middle]),
last,
)

assert result.entries == [first, duplicate, duplicate, middle, last]


def test_from_streams_rejects_other_stream_types():
Expand Down