Example #1
0
    def setUp(self):
        global counter
        counter = 0

        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        self.clock = ClockBase()
        self.callback_order = []
Example #2
0
 def setUp(self):
     global counter
     counter = 0
     if not asyncio.get_event_loop:
         self.skipTest("Clock broken")
         return
     self.clock = ClockBase()
     self.callback_order = []
Example #3
0
    def setUp(self):
        global counter
        counter = 0

        try:
            import uvloop
        except ImportError:
            pass
        else:
            asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        self.clock = ClockBase(loop=self.loop)
        self.callback_order = []
Example #4
0
 def _load_clock(self) -> ClockBase:  # pragma: no cover
     """Load clock and loop."""
     clock = ClockBase(self)
     clock.loop.set_exception_handler(self._exception_handler)
     return clock
Example #5
0
class ClockTestCase(unittest.TestCase):
    def setUp(self):
        global counter
        counter = 0

        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        self.clock = ClockBase()
        self.callback_order = []

    def tearDown(self):
        self.loop.close()

    def advance_time_and_run(self, delta=1.0):
        self.loop.run_until_complete(asyncio.sleep(delay=delta,
                                                   loop=self.loop))

    def callback1(self, number):
        self.callback_order.append(number)

    def test_schedule_once(self):
        self.clock.schedule_once(callback)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 1)

    def test_schedule_once_with_timeout(self):
        self.clock.schedule_once(callback, .001)
        self.advance_time_and_run(0.002)
        self.assertEqual(counter, 1)

    def test_schedule_once_twice(self):
        self.clock.schedule_once(callback)
        self.clock.schedule_once(callback)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 2)

    def test_unschedule(self):
        cb1 = self.clock.schedule_once(callback)
        self.clock.schedule_once(callback)
        self.clock.unschedule(cb1)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 1)
Example #6
0
 def setUp(self):
     global counter
     counter = 0
     self.clock = ClockBase()
     self.callback_order = []
Example #7
0
    def __init__(self, mpf_path, machine_path, args, **kwargs):
        del mpf_path
        del machine_path
        del args
        super().__init__(**kwargs)

        self.config_validator = ConfigValidator(self, True, False)
        self.mpf_config_processor = MpfConfigProcessor(self.config_validator)
        files = [
            os.path.join(mpfmc.__path__[0],
                         'tools/interactive_mc/imcconfig.yaml')
        ]
        self.machine_config = self.mpf_config_processor.load_config_files_with_cache(
            files, "machine")
        self.machine_config['mpf'] = dict()
        self.machine_config['mpf']['allow_invalid_config_sections'] = True
        self.config = self.machine_config
        self._initialized = False
        self.options = dict(bcp=True, production=False)
        self.clock = ClockBase(self)

        # needed for bcp
        self.settings = Settings()
        self.machine_vars = {}
        self.modes = []

        self.events = EventManager(self)
        self.mode_controller = ModeController(self)
        self.bcp = Bcp(self)
        self.slide_player = MpfSlidePlayer(self)
        self.slide_player.instances['imc'] = dict()

        self.clock.loop.run_until_complete(
            self.events.post_queue_async("init_phase_1"))
        self.events.process_event_queue()
        self.clock.loop.run_until_complete(
            self.events.post_queue_async("init_phase_2"))
        self.events.process_event_queue()
        self.clock.loop.run_until_complete(
            self.events.post_queue_async("init_phase_3"))
        self.events.process_event_queue()
        self.clock.loop.run_until_complete(
            self.events.post_queue_async("init_phase_4"))
        self.events.process_event_queue()
        self.clock.loop.run_until_complete(
            self.events.post_queue_async("init_phase_5"))

        self.sm = ScreenManager()
        self.slide_screen = Screen(name="Slide Player")
        self.widget_screen = Screen(name="Widget Player")
        self.sm.add_widget(self.slide_screen)
        self.sm.add_widget(self.widget_screen)
        self.slide_player_code = YamlCodeInput(lexer=YamlLexer(), tab_width=4)
        self.slide_player_code.bind(on_triple_tap=self.send_slide_to_mc)

        self.slide_player_code.text = '''my_test_slide:
    widgets:
      - type: text
        text: iMC
        color: red
      - type: line
        points: 1, 1, 1, 32, 128, 32, 128, 1, 1, 1
        color: lime
      - type: rectangle
        width: 50
        height: 20
        color: yellow
'''

        self.send_button = Button(text='Send',
                                  size=(150, 60),
                                  size_hint=(None, None),
                                  background_normal='',
                                  background_color=(0, .6, 0, 1),
                                  pos=(0, 1),
                                  pos_hint={
                                      'top': 0.1,
                                      'right': 0.95
                                  })

        self.send_button.bind(on_press=self.send_slide_to_mc)

        self.slide_screen.add_widget(self.slide_player_code)
        self.slide_screen.add_widget(self.send_button)

        self.slide_player.register_player_events(dict())
Example #8
0
class ClockTestCase(unittest.TestCase):

    def setUp(self):
        global counter
        counter = 0
        if not asyncio.get_event_loop:
            self.skipTest("Clock broken")
            return
        self.clock = ClockBase()
        self.callback_order = []

    def advance_time_and_run(self, delta=1.0):
        asyncio.get_event_loop().run_until_complete(asyncio.sleep(delay=delta))

    def callback1(self, number):
        self.callback_order.append(number)

    def test_schedule_once(self):
        self.clock.schedule_once(callback)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 1)

    def test_schedule_once_with_timeout(self):
        self.clock.schedule_once(callback, .001)
        self.advance_time_and_run(0.002)
        self.assertEqual(counter, 1)

    def test_schedule_once_twice(self):
        self.clock.schedule_once(callback)
        self.clock.schedule_once(callback)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 2)

    def test_unschedule(self):
        cb1 = self.clock.schedule_once(callback)
        self.clock.schedule_once(callback)
        self.clock.unschedule(cb1)
        self.advance_time_and_run(0.001)
        self.assertEqual(counter, 1)
Example #9
0
 def _load_clock(self):  # pragma: no cover
     clock = ClockBase()
     clock.loop.set_exception_handler(self._exception_handler)
     return clock