From 10cd25ae0ef13d821a5ec29154f0e416d770aa0c Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Wed, 22 Jul 2026 17:29:27 -0600 Subject: [PATCH 1/2] add test for order and duplicates in from_streams args --- tests/unit/test_cashflow_stream.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/unit/test_cashflow_stream.py b/tests/unit/test_cashflow_stream.py index 4556e3f..b1f0466 100644 --- a/tests/unit/test_cashflow_stream.py +++ b/tests/unit/test_cashflow_stream.py @@ -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(): From 49f5651aa1cdd0d69cc8a9374dd2ec69a0078335 Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Wed, 22 Jul 2026 17:35:55 -0600 Subject: [PATCH 2/2] mirror added from_streams test for generation streams --- tests/unit/test_generation.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/unit/test_generation.py b/tests/unit/test_generation.py index 335b573..91bf837 100644 --- a/tests/unit/test_generation.py +++ b/tests/unit/test_generation.py @@ -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():