Example #1
0
 def test_hook(self):
     events = []
     self.press()
     Invader.hook(events.append)
     self.press()
     Invader.unhook(events.append)
     self.press()
     self.assertEqual(len(events), 1)
Example #2
0
    def test_is_pressed(self):
        self.assertFalse(Invader.is_pressed())
        self.press()
        self.assertTrue(Invader.is_pressed())
        self.release()
        self.press(X2)
        self.assertFalse(Invader.is_pressed())

        self.assertTrue(Invader.is_pressed(X2))
        self.press(X2)
        self.assertTrue(Invader.is_pressed(X2))
        self.release(X2)
        self.release(X2)
        self.assertFalse(Invader.is_pressed(X2))
Example #3
0
 def t():
     self.recorded = Invader.record(RIGHT)
     lock.release()
Example #4
0
 def tearDown(self):
     Invader.unhook_all()
     # Make sure there's no spill over between tests.
     self.wait_for_events_queue()
Example #5
0
    def test_record_play(self):
        from threading import Thread, Lock
        lock = Lock()
        lock.acquire()

        def t():
            self.recorded = Invader.record(RIGHT)
            lock.release()

        Thread(target=t).start()
        self.click()
        self.wheel(5)
        self.move(100, 50)
        self.press(RIGHT)
        lock.acquire()

        self.assertEqual(len(self.recorded), 5)
        self.assertEqual(self.recorded[0]._replace(time=None),
                         ButtonEvent(DOWN, LEFT, None))
        self.assertEqual(self.recorded[1]._replace(time=None),
                         ButtonEvent(UP, LEFT, None))
        self.assertEqual(self.recorded[2]._replace(time=None),
                         WheelEvent(5, None))
        self.assertEqual(self.recorded[3]._replace(time=None),
                         MoveEvent(100, 50, None))
        self.assertEqual(self.recorded[4]._replace(time=None),
                         ButtonEvent(DOWN, RIGHT, None))

        Invader.play(self.recorded, speed_factor=0)
        events = self.flush_events()
        self.assertEqual(len(events), 5)
        self.assertEqual(events[0], (DOWN, LEFT))
        self.assertEqual(events[1], (UP, LEFT))
        self.assertEqual(events[2], ('wheel', 5))
        self.assertEqual(events[3], ('move', (100, 50)))
        self.assertEqual(events[4], (DOWN, RIGHT))

        Invader.play(self.recorded)
        events = self.flush_events()
        self.assertEqual(len(events), 5)
        self.assertEqual(events[0], (DOWN, LEFT))
        self.assertEqual(events[1], (UP, LEFT))
        self.assertEqual(events[2], ('wheel', 5))
        self.assertEqual(events[3], ('move', (100, 50)))
        self.assertEqual(events[4], (DOWN, RIGHT))

        Invader.play(self.recorded, include_clicks=False)
        events = self.flush_events()
        self.assertEqual(len(events), 2)
        self.assertEqual(events[0], ('wheel', 5))
        self.assertEqual(events[1], ('move', (100, 50)))

        Invader.play(self.recorded, include_moves=False)
        events = self.flush_events()
        self.assertEqual(len(events), 4)
        self.assertEqual(events[0], (DOWN, LEFT))
        self.assertEqual(events[1], (UP, LEFT))
        self.assertEqual(events[2], ('wheel', 5))
        self.assertEqual(events[3], (DOWN, RIGHT))

        Invader.play(self.recorded, include_wheel=False)
        events = self.flush_events()
        self.assertEqual(len(events), 4)
        self.assertEqual(events[0], (DOWN, LEFT))
        self.assertEqual(events[1], (UP, LEFT))
        self.assertEqual(events[2], ('move', (100, 50)))
        self.assertEqual(events[3], (DOWN, RIGHT))
Example #6
0
 def t():
     Invader.wait()
     lock.release()
Example #7
0
    def test_move(self):
        Invader.move(0, 0)
        self.assertEqual(Invader._os_Invader.get_position(), (0, 0))
        Invader.move(100, 500)
        self.assertEqual(Invader._os_Invader.get_position(), (100, 500))
        Invader.move(1, 2, False)
        self.assertEqual(Invader._os_Invader.get_position(), (101, 502))

        Invader.move(0, 0)
        Invader.move(100, 499, True, duration=0.01)
        self.assertEqual(Invader._os_Invader.get_position(), (100, 499))
        Invader.move(100, 1, False, duration=0.01)
        self.assertEqual(Invader._os_Invader.get_position(), (200, 500))
        Invader.move(0, 0, False, duration=0.01)
        self.assertEqual(Invader._os_Invader.get_position(), (200, 500))
Example #8
0
 def test_position(self):
     self.assertEqual(Invader.get_position(),
                      Invader._os_Invader.get_position())
Example #9
0
 def test_buttons(self):
     Invader.press()
     self.assertEqual(self.flush_events(), [(DOWN, LEFT)])
     Invader.release()
     self.assertEqual(self.flush_events(), [(UP, LEFT)])
     Invader.click()
     self.assertEqual(self.flush_events(), [(DOWN, LEFT), (UP, LEFT)])
     Invader.double_click()
     self.assertEqual(self.flush_events(), [(DOWN, LEFT), (UP, LEFT),
                                            (DOWN, LEFT), (UP, LEFT)])
     Invader.right_click()
     self.assertEqual(self.flush_events(), [(DOWN, RIGHT), (UP, RIGHT)])
     Invader.click(RIGHT)
     self.assertEqual(self.flush_events(), [(DOWN, RIGHT), (UP, RIGHT)])
     Invader.press(X2)
     self.assertEqual(self.flush_events(), [(DOWN, X2)])