Esempio n. 1
0
        def internal_checks(screen):
            # First check that Effects are always drawn at Scene start
            test_effect = MockEffect(count=101, stop_frame=101, frame_rate=100)
            screen.set_scenes([Scene([test_effect], 0)])
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)

            # Now check that the Screen honours the long frame rate...
            test_effect.update_called = False
            for _ in range(90):
                screen.draw_next_frame()
            self.assertFalse(test_effect.update_called)

            # Now check that the forced update works as expected.
            screen.force_update()
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)
Esempio n. 2
0
        def internal_checks(screen):
            # First check that Effects are always drawn at Scene start
            test_effect = MockEffect(count=101, stop_frame=101, frame_rate=100)
            screen.set_scenes([Scene([test_effect], 0)])
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)

            # Now check that the Screen honours the long frame rate...
            test_effect.update_called = False
            for _ in range(90):
                screen.draw_next_frame()
            self.assertFalse(test_effect.update_called)

            # Now check that the forced update works as expected.
            screen.force_update()
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)
Esempio n. 3
0
 def internal_checks(screen):
     screen.play([
         Scene([
             MockEffect(count=5),
             Print(screen, FigletText("hello"), 2),
             Cycle(screen, FigletText("world"), 6),
             BannerText(screen, FigletText("world"), 10, 3),
             Mirage(screen, FigletText("huh?"), 14, 2)], 0)])
Esempio n. 4
0
 def test_resize(self):
     """
     Check that we can create a ResizeScreenError
     """
     scene = Scene([MockEffect()])
     message = "Test message"
     error = ResizeScreenError(message, scene)
     self.assertEqual(error.scene, scene)
     self.assertEqual(str(error), message)
Esempio n. 5
0
 def test_properties(self):
     """
     Check properties work as expected.
     """
     effect = MockEffect()
     scene = Scene([effect], duration=10, clear=False, name="blah")
     self.assertEqual(scene.name, "blah")
     self.assertEqual(scene.duration, 10)
     self.assertFalse(scene.clear)
Esempio n. 6
0
 def test_save(self):
     """
     Check scene will save data on exit if needed.
     """
     effect = MockEffect()
     scene = Scene([effect], duration=10)
     self.assertFalse(effect.save_called)
     scene.exit()
     self.assertTrue(effect.save_called)
Esempio n. 7
0
    def test_events(self):
        """
        Check event processing is queued correctly.
        """
        # Check that the scene passes events through to the effects
        effect1 = MockEffect()
        effect2 = MockEffect()
        scene = Scene([effect1, effect2], duration=10)
        scene.process_event(MouseEvent(10, 5, 0))
        self.assertTrue(effect1.event_called)
        self.assertTrue(effect2.event_called)

        # Check that the scene passes stops event processing when required
        effect1 = MockEffect()
        effect2 = MockEffect(swallow=True)
        scene = Scene([effect1, effect2], duration=10)
        scene.process_event(MouseEvent(10, 5, 0))
        self.assertFalse(effect1.event_called)
        self.assertTrue(effect2.event_called)
Esempio n. 8
0
        def internal_checks(screen):
            # First check that Effects are always drawn at Scene start
            test_effect = MockEffect(count=101, stop_frame=101, frame_rate=100)
            screen.set_scenes([Scene([test_effect], 0)])
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)

            # Now check that the Screen honours the long frame rate...
            test_effect.update_called = False
            for _ in range(90):
                screen.draw_next_frame()
            self.assertFalse(test_effect.update_called)

            # Now check that the forced update works as expected.
            screen.force_update()
            screen.draw_next_frame()
            self.assertTrue(test_effect.update_called)

            # Now check that a full refresh works.
            self.assertEqual(len(list(screen._buffer.deltas(0, 100))), 0)
            screen.force_update(full_refresh=True)
            self.assertGreater(len(list(screen._buffer.deltas(0, 100))), 0)
Esempio n. 9
0
        def internal_checks(screen):
            # First check that we can move between screens.
            test_effect1 = MockEffect(stop=False)
            test_effect2 = MockEffect(count=5)
            screen.play([
                Scene([test_effect1], 5),
                Scene([test_effect2], 0)])
            self.assertTrue(test_effect1.update_called)
            self.assertTrue(test_effect2.update_called)

            # Now check that we can start at the second scene.
            test_effect1 = MockEffect(stop=False)
            scene1 = Scene([test_effect1], 5, name="1")
            test_effect2 = MockEffect(count=3)
            scene2 = Scene([test_effect2], 0, name="2")
            screen.play([scene1, scene2], start_scene=scene2)
            self.assertFalse(test_effect1.update_called)
            self.assertTrue(test_effect2.update_called)

            # Now check that we can move to named scenes.
            test_effect1 = MockEffect(stop=False, next_scene="B")
            test_effect2 = MockEffect(count=5)
            screen.play([
                Scene([test_effect1], 15, name="A"),
                Scene([test_effect2], 0, name="B")])
            self.assertTrue(test_effect1.update_called)
            self.assertTrue(test_effect2.update_called)

            # Now check that bad names cause an exception.
            with self.assertRaises(RuntimeError):
                test_effect1 = MockEffect(stop=False, next_scene="C")
                test_effect2 = MockEffect(count=5)
                screen.play([
                    Scene([test_effect1], 15, name="A"),
                    Scene([test_effect2], 0, name="B")])
            self.assertTrue(test_effect1.update_called)
            self.assertFalse(test_effect2.update_called)

            # Now check that play stops at the end when repeat=False
            test_effect1 = MockEffect(stop=False)
            scene1 = Scene([test_effect1], 5, name="1")
            screen.play([scene1], repeat=False)
            self.assertTrue(test_effect1.update_called)
Esempio n. 10
0
        def internal_checks(screen):
            # Since the Screen draws things, there's not too much we can do
            # to genuinely verify this without verifying all Scene and Effect
            # function too.  Just play a dummy Effect for now.
            test_effect = MockEffect()
            screen.play([Scene([test_effect], 0)])
            self.assertTrue(test_effect.stop_called)
            self.assertTrue(test_effect.reset_called)

            # Now check that the desired duration is used.
            test_effect = MockEffect(count=6)
            screen.play([Scene([test_effect], 15)])
            self.assertFalse(test_effect.stop_called)
            self.assertTrue(test_effect.reset_called)

            # Now check that delete_count works.
            test_effect = MockEffect(count=6)
            test_effect2 = MockEffect(delete_count=3)
            scene = Scene([test_effect, test_effect2], 15)
            self.assertEqual(len(scene.effects), 2)
            screen.play([scene])
            self.assertEqual(len(scene.effects), 1)
            self.assertEqual(scene.effects[0], test_effect)
Esempio n. 11
0
    def test_dynamic_effects(self):
        """
        Check adding and removing effects works.
        """
        # Start with no effects
        effect = MockEffect()
        scene = Scene([], duration=10)
        self.assertEqual(scene.effects, [])

        # Add one - check internals for presence
        scene.add_effect(effect)
        self.assertEqual(scene.effects, [effect])

        # Remove it - check it's gone
        scene.remove_effect(effect)
        self.assertEqual(scene.effects, [])