@@ -24,6 +24,14 @@ async def clear_data(self) -> None:
2424 async def test_data (self ) -> int :
2525 ...
2626
27+ @actormethod (name = 'AddState' )
28+ async def add_state (self , name : str , data : object ) -> None :
29+ ...
30+
31+ @actormethod (name = 'UpdateState' )
32+ async def update_state (self , name : str , data : object ) -> None :
33+ ...
34+
2735 @actormethod (name = 'AddDataNoSave' )
2836 async def add_data_no_save (self , data : object ) -> None :
2937 ...
@@ -77,6 +85,15 @@ async def test_data(self) -> int:
7785 return 3
7886 return 4
7987
88+ async def add_state (self , name : str , data : object ) -> None :
89+ await self ._state_manager .add_state (name , data )
90+
91+ async def update_state (self , name : str , data : object ) -> None :
92+ def double (_ : str , x : int ) -> int :
93+ return 2 * x
94+
95+ await self ._state_manager .add_or_update_state (name , data , double )
96+
8097 async def add_data_no_save (self , data : object ) -> None :
8198 await self ._state_manager .set_state ('state' , data )
8299
@@ -227,6 +244,31 @@ async def test_test_data(self):
227244 result = await mockactor .test_data ()
228245 self .assertEqual (result , 3 )
229246
247+ async def test_add_state (self ):
248+ mockactor = create_mock_actor (MockTestActor , '1' )
249+ print (mockactor ._state_manager ._mock_state )
250+ self .assertFalse (mockactor ._state_manager ._mock_state )
251+ await mockactor .add_state ('test' , 5 )
252+ self .assertTrue ('test' in mockactor ._state_manager ._mock_state )
253+ self .assertEqual (mockactor ._state_manager ._mock_state ['test' ], 5 )
254+ await mockactor .add_state ('test2' , 10 )
255+ self .assertTrue ('test2' in mockactor ._state_manager ._mock_state )
256+ self .assertEqual (mockactor ._state_manager ._mock_state ['test2' ], 10 )
257+ self .assertEqual (len (mockactor ._state_manager ._mock_state ), 2 )
258+ with self .assertRaises (ValueError ):
259+ await mockactor .add_state ('test' , 10 )
260+
261+ async def test_update_state (self ):
262+ mockactor = create_mock_actor (MockTestActor , '1' )
263+ self .assertFalse (mockactor ._state_manager ._mock_state )
264+ await mockactor .update_state ('test' , 10 )
265+ self .assertTrue ('test' in mockactor ._state_manager ._mock_state )
266+ self .assertEqual (mockactor ._state_manager ._mock_state ['test' ], 10 )
267+ await mockactor .update_state ('test' , 10 )
268+ self .assertTrue ('test' in mockactor ._state_manager ._mock_state )
269+ self .assertEqual (mockactor ._state_manager ._mock_state ['test' ], 20 )
270+ self .assertEqual (len (mockactor ._state_manager ._mock_state ), 1 )
271+
230272 async def test_state_change_tracker (self ):
231273 mockactor = create_mock_actor (MockTestActor , '1' )
232274 self .assertEqual (len (mockactor ._state_manager ._default_state_change_tracker ), 0 )
0 commit comments