Skip to content

Commit

Permalink
Add test for get_node_id
Browse files Browse the repository at this point in the history
  • Loading branch information
chongshenng committed Nov 7, 2024
1 parent 1fbf1de commit 070aa1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/py/flwr/client/nodestate/in_memory_nodestate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InMemoryNodeState(NodeState):

def __init__(self) -> None:
# Store node_id
self.node_id: Optional[int]
self.node_id: Optional[int] = None

def set_node_id(self, node_id: Optional[int]) -> None:
"""Set the node ID."""
Expand Down
9 changes: 9 additions & 0 deletions src/py/flwr/client/nodestate/nodestate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def test_get_set_node_id(self) -> None:
# Assert
assert node_id == retrieved_node_id

def test_get_node_id_fails(self) -> None:
"""Test get_node_id fails correctly if node_id is not set."""
# Prepare
state: NodeState = self.state_factory()

# Execute and assert
with self.assertRaises(ValueError):
state.get_node_id()


class InMemoryStateTest(StateTest):
"""Test InMemoryState implementation."""
Expand Down

0 comments on commit 070aa1f

Please sign in to comment.