From a27dbfa4accba7b807bbe5fdd333267358409f5f Mon Sep 17 00:00:00 2001 From: Tamino Huxohl Date: Fri, 13 Dec 2024 13:49:00 +0100 Subject: [PATCH] extend tests --- tests/test_dict_state.py | 4 ++++ tests/test_higher_order_state.py | 12 ++++++++++++ tests/test_list_state.py | 9 +++++++++ tests/test_state.py | 5 +++++ widget_state/dict_state.py | 4 ++-- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/test_dict_state.py b/tests/test_dict_state.py index 97fc054..9cdf721 100644 --- a/tests/test_dict_state.py +++ b/tests/test_dict_state.py @@ -35,3 +35,7 @@ def test_set(vector_state: VectorState) -> None: assert isinstance(vector_state.x, IntState) and vector_state.x.value == 1 assert isinstance(vector_state.y, IntState) and vector_state.y.value == 2 assert isinstance(vector_state.z, IntState) and vector_state.z.value == 3 + + vector_state.set(*[], y=IntState(10), z=5) + assert isinstance(vector_state.y, IntState) and vector_state.y.value == 10 + assert isinstance(vector_state.z, IntState) and vector_state.z.value == 5 diff --git a/tests/test_higher_order_state.py b/tests/test_higher_order_state.py index 3de8faa..02d2619 100644 --- a/tests/test_higher_order_state.py +++ b/tests/test_higher_order_state.py @@ -97,3 +97,15 @@ def test_deserialize(super_state: SuperState, callback: MockCallback) -> None: def test_to_str(super_state: SuperState) -> None: assert super_state.to_str() == _str assert str(super_state) == _str + + +def test_copy_from(super_state: SuperState) -> None: + new_state = SuperState() + new_state.name.value = "Test" + new_state.count.value = 2 + new_state.nested.length.value = 2.71 + + super_state.copy_from(new_state) + assert super_state.name.value == "Test" + assert super_state.count.value == 2 + assert super_state.nested.length.value == 2.71 diff --git a/tests/test_list_state.py b/tests/test_list_state.py index d3fb3dc..faa2926 100644 --- a/tests/test_list_state.py +++ b/tests/test_list_state.py @@ -164,3 +164,12 @@ def test_serialize(list_state: ListState) -> None: def test_deserialize(list_state: ListState) -> None: with pytest.raises(NotImplementedError): list_state.deserialize([0, 1, 2]) + + +def test_copy_from(list_state: ListState) -> None: + new_list: ListState[IntState] = ListState() + new_list.copy_from(list_state) + + assert len(new_list) == len(list_state) + for i in range(len(new_list)): + assert new_list[i].value == list_state[i].value diff --git a/tests/test_state.py b/tests/test_state.py index f8a8e9d..e9f7f4a 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -76,3 +76,8 @@ def test_serialize(state: State) -> None: def test_deserialize(state: State) -> None: with pytest.raises(NotImplementedError): state.deserialize(0) + + +def test_copy_from(state: State) -> None: + with pytest.raises(NotImplementedError): + state.copy_from(state) diff --git a/widget_state/dict_state.py b/widget_state/dict_state.py index 19bebdb..dfc2425 100644 --- a/widget_state/dict_state.py +++ b/widget_state/dict_state.py @@ -56,13 +56,13 @@ def values(self) -> list[Any]: def set( self, *args: BasicState[Any] | Primitive, - **kwargs: dict[str, BasicState[Any] | Primitive], + **kwargs: BasicState[Any] | Primitive, ) -> None: """ Reassign internal basic state values and only trigger a notification afterwards. """ - assert len(args) == len(self) + assert len(args) <= len(self) with self: for i, arg in enumerate(args):