11# License: MIT
22# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
33
4- """Tests for the OnlyIfPrevious implementation."""
4+ """Tests for the WithPrevious implementation."""
55
66from dataclasses import dataclass
77from typing import Callable , Generic , TypeVar
88
99import pytest
1010
11- from frequenz .channels .experimental import OnlyIfPrevious
11+ from frequenz .channels .experimental import WithPrevious
1212
1313_T = TypeVar ("_T" )
1414
1515
1616@dataclass (frozen = True , kw_only = True )
1717class PredicateTestCase (Generic [_T ]):
18- """Test case for testing OnlyIfPrevious behavior with different predicates."""
18+ """Test case for testing WithPrevious behavior with different predicates."""
1919
2020 title : str
2121 messages : list [_T ]
@@ -113,12 +113,12 @@ def is_not_same_instance(old: object, new: object) -> bool:
113113 ids = lambda test_case : test_case .title ,
114114)
115115def test_only_if_previous (test_case : PredicateTestCase [_T ]) -> None :
116- """Test the OnlyIfPrevious with different predicates and sequences.
116+ """Test the WithPrevious with different predicates and sequences.
117117
118118 Args:
119119 test_case: The test case containing the input values and expected results.
120120 """
121- only_if_previous = OnlyIfPrevious (
121+ only_if_previous = WithPrevious (
122122 test_case .predicate ,
123123 first_is_true = test_case .first_is_true ,
124124 )
@@ -127,9 +127,9 @@ def test_only_if_previous(test_case: PredicateTestCase[_T]) -> None:
127127
128128
129129def test_only_if_previous_state_independence () -> None :
130- """Test that multiple OnlyIfPrevious instances maintain independent state."""
131- only_if_previous1 = OnlyIfPrevious (is_greater )
132- only_if_previous2 = OnlyIfPrevious (is_greater )
130+ """Test that multiple WithPrevious instances maintain independent state."""
131+ only_if_previous1 = WithPrevious (is_greater )
132+ only_if_previous2 = WithPrevious (is_greater )
133133
134134 # First message should be accepted (first_is_true default is True)
135135 assert only_if_previous1 (1 ) is True
@@ -141,17 +141,17 @@ def test_only_if_previous_state_independence() -> None:
141141
142142
143143def test_only_if_previous_str_representation () -> None :
144- """Test the string representation of OnlyIfPrevious ."""
145- only_if_previous = OnlyIfPrevious (is_greater )
146- assert str (only_if_previous ) == "OnlyIfPrevious :is_greater"
144+ """Test the string representation of WithPrevious ."""
145+ only_if_previous = WithPrevious (is_greater )
146+ assert str (only_if_previous ) == "WithPrevious :is_greater"
147147 assert (
148- repr (only_if_previous ) == f"<OnlyIfPrevious : { is_greater !r} first_is_true=True>"
148+ repr (only_if_previous ) == f"<WithPrevious : { is_greater !r} first_is_true=True>"
149149 )
150150
151151
152152def test_only_if_previous_sentinel_str () -> None :
153153 """Test the string representation of the sentinel value."""
154- only_if_previous = OnlyIfPrevious (always_true )
154+ only_if_previous = WithPrevious (always_true )
155155
156156 # Access the private attribute for testing purposes
157157 # pylint: disable=protected-access
0 commit comments