def test_get_rate(pre_state, time, value, onwrap, expected):
    item_state.set_item_state("foo", pre_state)
    result = item_state.get_rate("foo",
                                 time,
                                 value,
                                 onwrap=onwrap,
                                 allow_negative=True)
    assert result == expected
def _test_context(mock_state: Mapping[str, object]):
    previous_prefix = item_state.get_item_state_prefix()
    item_state._cached_item_states.reset()
    item_state.set_item_state_prefix(("item_state_unit_tests", None))
    for k, v in mock_state.items():
        item_state.set_item_state(k, v)
    try:
        yield
    finally:
        item_state._cached_item_states.reset()
        item_state.set_item_state_prefix(previous_prefix)
Exemple #3
0
 def __setitem__(self, key: str, value: Any) -> None:
     self._raise_for_scope_violation()
     if not isinstance(key, str):
         raise TypeError("key must be str")
     return set_item_state(key, value)
def test_get_rate_raises(pre_state, time, value, errmsg):
    item_state.set_item_state("foo", pre_state)
    with pytest.raises(item_state.MKCounterWrapped, match=errmsg):
        item_state.get_rate("foo", time, value, onwrap=item_state.RAISE)