Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pLeminoq committed Dec 13, 2024
1 parent dec7801 commit a27dbfa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/test_dict_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions tests/test_higher_order_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions tests/test_list_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions widget_state/dict_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a27dbfa

Please sign in to comment.