예제 #1
0
 def test_creation(self):
     game_obj = GameObject.min_init("game1", 0)
     game_obj2 = GameObject.min_init("game2", 1)
     settings = Settings(0, 1, [game_obj, game_obj2])
     self.assertEqual(game_obj, settings.tracking_games[0])
     self.assertEqual(game_obj2, settings.tracking_games[1])
     settings.extra_time = 0
     settings.loop_time = 1
예제 #2
0
 def test_eq(self):
     obj1 = GameObject.min_init("gameA", 0)
     obj2 = GameObject.min_init("gameB", 0)
     self.assertNotEqual(obj1, obj2)
     obj3 = GameObject.min_init("gameA", 0)
     self.assertEqual(obj1, obj3)
     obj4 = GameObject.min_init("gameA", 1)
     self.assertEqual(obj1, obj4)
예제 #3
0
    def test_update(self):
        obj1 = GameObject.min_init("game1", 0)
        obj1.PIDS = [1, 2, 3]

        obj2 = GameObject("game1", 10, 20, 5)
        obj1.update(obj2)
        self.assertEqual(obj1.name, "game1")
        self.assertEqual(obj1.start_time, 0)
        self.assertEqual(obj1.end_time, 20)
        self.assertEqual(obj1.max_time, 5)
        self.assertEqual(obj1.PIDS, [])
    def test_enforce_block(self):
        with patch("flask_app.TrackingThread.GameObject.kill") as mock_kill:
            game_obj = GameObject.min_init("game1", 1)
            game_obj2 = GameObject.min_init("game2", 1)

            settings = Settings(0, 1, [game_obj, game_obj2])
            current_state = CurrentState(settings)
            current_state.currently_running = [game_obj, game_obj2]

            self.manager.blocked_games = [game_obj]
            self.manager.enforce_block(current_state)

            self.assertEqual([game_obj2], current_state.currently_running)
예제 #5
0
 def test_creation(self):
     time = datetime.now()
     obj = GameObject("test", time, time + timedelta(seconds=5), 10)
     self.assertEqual(obj.start_time, time)
     self.assertEqual(obj.end_time, time + timedelta(seconds=5))
     self.assertEqual(obj.name, "test")
     self.assertEqual(obj.max_time, 10)
    def test_update_block(self):
        with patch(
                "flask_app.TrackingThread.GameObject.has_time") as mock_time:
            mock_time.return_value = True
            game_obj = GameObject.min_init("game1", 1)
            game_obj2 = GameObject.min_init("game2", 1)

            settings = Settings(0, 1, [game_obj, game_obj2])
            current_state = CurrentState(settings)
            current_state.currently_running = [game_obj, game_obj2]

            self.manager.update_block(current_state)
            self.assertEqual([], self.manager.blocked_games)

            mock_time.return_value = False
            self.manager.update_block(current_state)
            self.assertEqual([game_obj, game_obj2], self.manager.blocked_games)
예제 #7
0
    def test_kill_game_invalid_PID(self):
        # test when pids do exist
        pid_list = [1, 2, 3, 10, 4]
        game1 = GameObject.min_init('game1', 100)

        with patch(
                "flask_app.TrackingThread.psutil.Process.kill") as mocked_kill:
            mocked_kill.side_effect = psutil.NoSuchProcess(None)
            game1.kill()
    def test_add_to_blocked(self):
        game = GameObject.min_init("game1", 100)
        self.manager.blocked_games = [game]

        self.manager.block(game)
        self.assertEqual([game], self.manager.blocked_games)

        self.manager.blocked_games = []
        self.manager.block(game)
        self.assertEqual([game], self.manager.blocked_games)
예제 #9
0
    def test_kill_game(self):
        # test when pids do exist
        pid_list = [1, 2, 3, 10, 4]
        game1 = GameObject.min_init('game1', 100)

        with patch(
                "flask_app.TrackingThread.psutil.Process.kill") as mocked_kill:
            mocked_kill.return_value = None
            game1.kill()

        self.assertEqual([], game1.PIDS)
    def test_game_update(self):
        self.state.currently_running = [self.game_obj1, self.game_obj2]
        updated = GameObject("game1", 0, 30, 1)
        self.state.game_update(self.game_obj1, updated)
        self.assertEqual("game1", self.game_obj1.name)
        self.assertEqual(0, self.game_obj1.start_time)
        self.assertEqual(30, self.game_obj1.end_time)
        self.assertEqual(1, self.game_obj1.max_time)

        # Check that the reference in the list gets updated too
        index = self.state.get_game_index_running(self.game_obj1)
        self.assertTrue(
            self.game_obj1.deep_equal(self.state.currently_running[index]))
 def test_blocked_game_names(self):
     game_names = ["A", "B", "C"]
     self.manager.blocked_games = [
         GameObject.min_init(name, 100) for name in game_names
     ]
     self.assertEqual(game_names, self.manager.blocked_names())
 def setUp(self) -> None:
     self.game_obj1 = GameObject.min_init("game1", 0)
     self.game_obj2 = GameObject.min_init("game2", 0)
     self.settings = Settings(5, 1, [self.game_obj1, self.game_obj2])
     self.state = CurrentState(self.settings)
예제 #13
0
    def test_out_of_time(self):
        start_time = time.time()

        with patch("flask_app.TrackingThread.time.time") as mock_time:
            mock_time.return_value = start_time + 100
            game_obj = GameObject("game", start_time, None, 100)
            self.assertFalse(game_obj.has_time())

            mock_time.return_value = start_time + 100
            game_obj = GameObject("game", start_time, None, 99)
            self.assertFalse(game_obj.has_time())

            mock_time.return_value = start_time + 100
            game_obj = GameObject("game", start_time, None, 200)
            self.assertTrue(game_obj.has_time())

            mock_time.return_value = 100
            game_obj = GameObject("game", start_time, None, 300)
            self.assertTrue(game_obj.has_time())
예제 #14
0
 def test_end_now(self):
     obj = GameObject.min_init("game", 0)
     obj.end_now()
     self.assertNotEqual(obj.end_time, 0)
예제 #15
0
 def test_min_init(self):
     obj = GameObject.min_init("test", 5)
     self.assertEqual(obj.start_time, 0)
     self.assertEqual(obj.end_time, 0)
     self.assertEqual(obj.name, "test")
     self.assertEqual(obj.max_time, 5)
예제 #16
0
 def setUp(self) -> None:
     self.game_obj1 = GameObject.min_init("game1", 0)
     self.game_obj2 = GameObject.min_init("game2", 0)
     self.settings = Settings(0, 1, [self.game_obj1, self.game_obj2])
     self.tracker = Tracker(self.settings)