def test_objectLifeTime(self):
     data_store = DataStore()
     self_wrapper = self
     test_module = TestObjectLifeTimeModule(lambda: self_wrapper.assertRaises(NotFoundInDataStore, data_store.get, 'EventLifetime'))
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module], data_store)
     run_engine.run()
     data_store.get('ApplicationLifetime')
 def test_order_of_execution(self):
     order_begin_list = []
     order_event_list = []
     order_end_list = []
     test_module0 = TestOrderOfExcecutionModule(0, order_begin_list, order_event_list, order_end_list)
     test_module1 = TestOrderOfExcecutionModule(1, order_begin_list, order_event_list, order_end_list)
     test_module2 = TestOrderOfExcecutionModule(2, order_begin_list, order_event_list, order_end_list)
     data_store = DataStore()
     data_store.put('nEvent', 3)
     
     run_engine = RunEngine([test_module0, test_module1, test_module2], data_store)
     run_engine.run()
     self.assertEqual(order_begin_list, [0, 1, 2])
     self.assertEqual(order_event_list, [0, 1, 2, 0, 1, 2, 0, 1, 2,])
     self.assertEqual(order_end_list, [0, 1, 2])
    def test_run(self):
        test_module1 = Test()
        test_module2 = Test()
        data_store = DataStore()
        data_store.put('nEvent', 100)
        
        self.assertEqual(test_module1.beginCalled, 0)
        self.assertEqual(test_module1.eventCalled, 0)
        self.assertEqual(test_module1.endCalled, 0)
        
        self.assertEqual(test_module2.beginCalled, 0)
        self.assertEqual(test_module2.eventCalled, 0)
        self.assertEqual(test_module2.endCalled, 0)

        run_engine = RunEngine([test_module1, test_module2], data_store)
        run_engine.run()
        
        self.assertEqual(test_module1.beginCalled, 1)
        self.assertEqual(test_module1.eventCalled, 100)
        self.assertEqual(test_module1.endCalled, 1)
        
        self.assertEqual(test_module2.beginCalled, 1)
        self.assertEqual(test_module2.eventCalled, 100)
        self.assertEqual(test_module2.endCalled, 1)
 def test_impossibility_to_get_run_engine_in_invalid_state(self):
     test_module1 = Test()
     test_module2 = Test()
     data_store = DataStore()
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module1, test_module2], data_store)
     self.assertRaises(RunEngineInInconsistentState, run_engine.call_next_event_methods)
     
     test_module1 = Test()
     test_module2 = Test()
     data_store = DataStore()
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module1, test_module2], data_store)
     self.assertRaises(RunEngineInInconsistentState, run_engine.call_all_end_methods)
     
     test_module1 = Test()
     test_module2 = Test()
     data_store = DataStore()
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module1, test_module2], data_store)
     run_engine.call_all_begin_methods()
     self.assertRaises(RunEngineInInconsistentState, run_engine.call_all_begin_methods)
     
     test_module1 = Test()
     test_module2 = Test()
     data_store = DataStore()
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module1, test_module2], data_store)
     run_engine.call_all_begin_methods()
     run_engine.call_next_event_methods()
     run_engine.clear_event_based_storage()
     run_engine.call_next_event_methods()
     run_engine.clear_event_based_storage()
     # can not call call_next_event_methods() method more often than nEvent times
     self.assertRaises(RunEngineInInconsistentState, run_engine.call_next_event_methods)
     
     test_module1 = Test()
     test_module2 = Test()
     data_store = DataStore()
     data_store.put('nEvent', 2)
     run_engine = RunEngine([test_module1, test_module2], data_store)
     run_engine.call_all_begin_methods()
     run_engine.call_next_event_methods()
     run_engine.clear_event_based_storage()
     run_engine.call_next_event_methods()
     run_engine.clear_event_based_storage()
     run_engine.call_all_end_methods()
     self.assertRaises(RunEngineInInconsistentState, run_engine.call_all_end_methods)