Exemple #1
0
class TestGameStateMainMenu(unittest.TestCase):
    def setUp(self):
        self.manager = GameStateManager()
        self.manager.state = "MainMenu"

    def test_handle_events_exits(self):
        events = [pygame.event.Event(pygame.locals.QUIT)]
        res = self.manager.handle_events(events)
        self.assertEqual(res, False)  # Game doesn't exit from main menu
Exemple #2
0
 def test_update_and_get_image_is_called(self):
     # holds all mock objects
     mocker = Controller()
     # mock object to be used in tested routine instead of real thing
     mocked_game_state = mocker.mock()
     # record exactly how mock object should be used in tested routine
     mocked_game_state.update()
     mocked_game_state.get_image((500, 500))
     # prepare it for real use
     mocker.replay()
     # init states
     manager = GameStateManager()
     manager.state = "Mock"
     manager._states["Mock"] = mocked_game_state
     # call tested routine
     screen = manager.get_rendered_screen((500, 500))
     # test if it was used right
     mocker.verify()
Exemple #3
0
class TestGameStateGame(unittest.TestCase):
    def setUp(self):
        pygame.init()
        self.manager = GameStateManager()
        self.manager.state = "Game"

    def test_get_rendered_screen_surface(self):
        screen = self.manager.get_rendered_screen()
        self.assertTrue(isinstance(screen, pygame.Surface))  # Not valid pygame.Surface returned

    def test_get_rendered_screen_correct_size(self):
        screen = self.manager.get_rendered_screen((500, 500))
        self.assertEqual(screen.get_size(), (500, 500))  # Returned image should be of correct size

    def test_handle_events_changes_state(self):
        events = [pygame.event.Event(pygame.locals.QUIT)]
        res = self.manager.handle_events(events)
        self.assertEqual(res, True, "Game exit from game state")
        self.assertEqual(self.manager.state, "InGameMenu")  # Game doesn't exit to ingame menu
Exemple #4
0
 def setUp(self):
     pygame.init()
     self.manager = GameStateManager()
     self.manager.state = "Game"
Exemple #5
0
 def setUp(self):
     self.manager = GameStateManager()
     self.manager.state = "MainMenu"
Exemple #6
0
 def test_get_rendered_screen_surface(self):
     manager = GameStateManager()
     screen = manager.get_rendered_screen()
     self.assertTrue(isinstance(screen, pygame.Surface))  # Not valid pygame.Surface returned