def testPost(self):
     """Test posting an event"""
     event_manager = EventManager()
     event_tester = EventTester()
     event_manager.register_listener(event_tester)
     event = Event()
     event_manager.post(event)
     self.assertEqual(event_tester.last_event(), event)
Exemple #2
0
class MapStateTests(unittest.TestCase):
    
    def setUp(self):
        self.event_manager = EventManager()
    
    def testInit(self):
        """Test map state initalisation"""
        map_state = MapState(self.event_manager)
        self.assertEqual(map_state.event_manager, self.event_manager)
        self.assertTrue(map_state in self.event_manager.listener_groups["default"].listeners)
        self.assertEqual(map_state.occupied_sectors_by_actor_id, {})
        self.assertEqual(map_state.actors_by_sector_id, {})
        
    def testCharactorPlaceNotification(self):
        """Test charactor place notification"""
        map_state = MapState(self.event_manager)
        charactor = Charactor(self.event_manager)
        charactor.sector = Sector()
        charactor_place_event = CharactorPlaceEvent(charactor)
        self.event_manager.post(charactor_place_event)
        self.assertEqual(map_state.actors_by_sector_id[charactor.sector.sector_id], charactor)
        self.assertEqual(map_state.occupied_sectors_by_actor_id[charactor.charactor_id], charactor.sector)
        
    def testFreeSectorActionNotification(self):
        """Test free section action notification"""
        map_state = MapState(self.event_manager)
        sector = Sector()
        
        self.actionExecuted = False #TODO: this is no good
        def function(sector_is_free):
            if sector_is_free:
                self.actionExecuted = True
        callback_function = function
        free_sector_action = FreeSectorAction(sector, callback_function)
        self.event_manager.post(free_sector_action)
        self.assertTrue(self.actionExecuted)
        
        self.actionExecuted = False
        charactor = Charactor(self.event_manager)
        charactor.sector = sector
        map_state.occupied_sectors_by_actor_id[charactor.charactor_id] = charactor.sector
        self.event_manager.post(free_sector_action)
        self.assertFalse(self.actionExecuted)