diff --git a/tests/test_plumbing.py b/tests/test_plumbing.py index ecf80ef70..b51187be8 100644 --- a/tests/test_plumbing.py +++ b/tests/test_plumbing.py @@ -6,34 +6,60 @@ SPDX-License-Identifier: MIT """ +import numpy as np import pytest +from oemof.solph._plumbing import _FakeSequence from oemof.solph._plumbing import sequence -def test_sequence(): - seq0 = sequence(0) - assert seq0[0] == 0 +def test_fake_sequence(): + seq0 = _FakeSequence(42) + assert seq0[0] == 42 assert seq0.size is None - assert seq0[10] == 0 + assert seq0[10] == 42 assert seq0.size is None - assert seq0.max() == 0 + assert seq0.max() == 42 + assert seq0.min() == 42 + assert seq0.value == 42 + assert seq0.sum() == np.inf + + assert str(seq0) == "[42, 42, ..., 42]" + + with pytest.raises(TypeError): + seq0.to_numpy() + assert (seq0.to_numpy(length=5) == np.array(5 * [42])).all() + + with pytest.raises(TypeError): + len(seq0) + + seq0.size = 2 + assert seq0.size == 2 + assert len(seq0) == 2 - seq10 = sequence(10) - assert seq10.max() == 10 + assert seq0.max() == 42 + assert seq0.min() == 42 + assert seq0.value == 42 + assert seq0.sum() == 84 - assert seq10[0] == 10 - assert seq10.size is None + assert str(seq0) == "[42, 42]" - seq10.size = 10 - assert seq10.size == 10 + assert (seq0.to_numpy() == np.array(2 * [42])).all() + assert (seq0.to_numpy(length=5) == np.array(5 * [42])).all() + + +def test_sequence(): + seq0 = sequence(0) + assert isinstance(seq0, _FakeSequence) + assert seq0.value == 0 + assert seq0.size is None - seq12 = sequence([1, 3]) - assert max(seq12) == 3 - assert seq12[0] == 1 - assert seq12[1] == 3 + seq13 = sequence([1, 3]) + assert isinstance(seq13, np.ndarray) + assert (seq13 == np.array([1, 3])).all() - with pytest.raises(IndexError): - _ = seq12[2] + seq_ab = sequence("ab") + assert isinstance(seq_ab, str) + assert seq_ab == "ab"