def dry_run_actions(args): """Do a dry run of action replay without changing of affecting assets' states""" action_slc = get_action_slice(args["start"], args["end"]) action_details = StateClient.list_actions(action_slc) try: Recorder.perform_dry_run(action_details, action_slc) except KeyboardInterrupt: print("Dry-run was interrupted by the user", file=sys.stderr)
def test_serialization_save_range(self): """Test action saving but only slice of action history""" self.recorded_entity_1.double_a() # 4 self.recorded_entity_1.double_a() # 8 self.recorded_entity_1.double_a() # 16 # serialize only the last action REC.save_actions(action_file="/tmp/simengine_rec_utest.json", slc=slice(-1, None)) new_recorder = Recorder(module=__name__) new_recorder.load_actions(map_key_to_state=RecordedEntity, action_file="/tmp/simengine_rec_utest.json") new_recorder.replay_all() self.assertEqual(32, RecordedEntity.test_a["value"]) action_details = new_recorder.get_action_details() self.assertEqual(1, len(action_details))
def test_serialization(self): """Test action saving functionality""" self.recorded_entity_1.double_a() # 4 self.recorded_entity_2.double_a() # 8 self.recorded_entity_1.add(1) RecordedEntity.class_lvl_method() REC.save_actions(action_file="/tmp/simengine_rec_utest.json") self.recorded_entity_1.double_a() # 16 (action not saved) self.assertEqual(16, RecordedEntity.test_a["value"]) # Action history: a * 2 * 2 where test_a = 16 new_recorder = Recorder(module=__name__) new_recorder.load_actions(map_key_to_state=RecordedEntity, action_file="/tmp/simengine_rec_utest.json") new_recorder.replay_all() self.assertEqual(64, RecordedEntity.test_a["value"]) action_details = new_recorder.get_action_details() self.assertEqual(4, len(action_details))
"""Unittests for testing action recorder & action history replay""" import unittest from enginecore.tools.recorder import Recorder from enginecore.model.graph_reference import GraphReference REC = Recorder(module=__name__) class RecordedEntity: """Class to be "recorded" """ num_entities = 0 test_a = {"value": 2} def __init__(self, key=None): self.count = 0 self._graph_ref = GraphReference() RecordedEntity.num_entities = RecordedEntity.num_entities + 1 self.key = RecordedEntity.num_entities if not key else key @REC def add(self, value): """Test method 1""" self.count = self.count + value @REC def subtract(self, value): """Test method 2"""