Beispiel #1
0
    def setUp(self):
        '''Prepare the graphic test, with:
            - Window size fixed to 320x240
            - Default kivy configuration
            - Without any kivy input
        '''

        # use default kivy configuration (don't load user file.)
        from os import environ
        environ['KIVY_USE_DEFAULTCONFIG'] = '1'

        # force window size + remove all inputs
        from kivy.config import Config
        Config.set('graphics', 'width', '320')
        Config.set('graphics', 'height', '240')
        for items in Config.items('input'):
            Config.remove_option('input', items[0])

        # bind ourself for the later screenshot
        from kivy.core.window import Window
        self.Window = Window
        Window.bind(on_flip=self.on_window_flip)

        # ensure our window is correctly created
        Window.create_window()
        Window.register()
        Window.initialized = True
        Window.canvas.clear()
        Window.close = lambda *s: True
Beispiel #2
0
    def setUp(self):
        '''Prepare the graphic test, with:
            - Window size fixed to 320x240
            - Default kivy configuration
            - Without any kivy input
        '''

        # use default kivy configuration (don't load user file.)
        from os import environ
        environ['KIVY_USE_DEFAULTCONFIG'] = '1'

        # force window size + remove all inputs
        from kivy.config import Config
        Config.set('graphics', 'width', '320')
        Config.set('graphics', 'height', '240')
        for items in Config.items('input'):
            Config.remove_option('input', items[0])

        # bind ourself for the later screenshot
        from kivy.core.window import Window
        self.Window = Window
        Window.bind(on_flip=self.on_window_flip)

        # ensure our window is correctly created
        Window.create_window()
        Window.register()
        Window.initialized = True
        Window.canvas.clear()
        Window.close = lambda *s: True
    def _start_mc(self):
        from mpfmc.core.mc import MpfMc

        # prevent sleep in clock
        Clock._max_fps = 0

        mpf_config = ConfigProcessor.load_config_file(
            os.path.abspath(
                os.path.join(mpfmc.__path__[0], os.pardir,
                             self.get_options()['mcconfigfile'])), 'machine')

        machine_path = self.getAbsoluteMachinePath()

        mpf_config = load_machine_config(
            Util.string_to_list(self.getConfigFile()), machine_path,
            mpf_config['mpf-mc']['paths']['config'], mpf_config)
        self.preprocess_config(mpf_config)

        self.mc = MpfMc(options=self.get_options(),
                        config=mpf_config,
                        machine_path=machine_path)

        from kivy.core.window import Window
        Window.create_window()
        Window.canvas.clear()

        self._start_app_as_slave()
Beispiel #4
0
async def media_app(request, nursery, tmp_path):
    ts0 = time.perf_counter()
    from kivy.core.window import Window
    from kivy.context import Context
    from kivy.clock import ClockBase
    from kivy.base import stopTouchApp
    from kivy.logger import LoggerHistory

    context = Context(init=False)
    context['Clock'] = ClockBase(async_lib='trio')
    context.push()

    Window.create_window()
    Window.register()
    Window.initialized = True
    Window.canvas.clear()

    from more_kivy_app.app import report_exception_in_app
    import cpl_media
    cpl_media.error_callback = report_exception_in_app

    app = DemoTestApp(yaml_config_path=str(tmp_path / 'config.yaml'),
                      ini_file=str(tmp_path / 'config.ini'))

    try:
        app.set_async_lib('trio')
        nursery.start_soon(app.async_run)

        ts = time.perf_counter()
        while not app.app_has_started:
            await trio.sleep(.1)
            if time.perf_counter() - ts >= 10:
                raise TimeoutError()

        await app.wait_clock_frames(5)

        ts1 = time.perf_counter()
        yield app
        ts2 = time.perf_counter()

        stopTouchApp()

        ts = time.perf_counter()
        while not app.app_has_stopped:
            await trio.sleep(.1)
            if time.perf_counter() - ts >= 10:
                raise TimeoutError()
    finally:
        stopTouchApp()
        app.clean_up()
        for child in Window.children[:]:
            Window.remove_widget(child)

        context.pop()
        del context
        LoggerHistory.clear_history()

    ts3 = time.perf_counter()
    print(ts1 - ts0, ts2 - ts1, ts3 - ts2)
Beispiel #5
0
    def _start_mc(self):
        from mpfmc.core.mc import MpfMc

        # prevent sleep in clock
        Clock._max_fps = 0

        machine_path = self.getAbsoluteMachinePath()

        self.mc = MpfMc(options=self.get_options(), machine_path=machine_path)

        from kivy.core.window import Window
        Window.create_window()
        Window.canvas.clear()

        self._start_app_as_slave()
Beispiel #6
0
    async def __aenter__(self):
        self.set_kivy_config()

        from kivy.core.window import Window
        from kivy.context import Context
        from kivy.clock import ClockBase
        from kivy.factory import FactoryBase, Factory
        from kivy.lang.builder import BuilderBase, Builder

        kivy_eventloop = self.async_lib
        if kivy_eventloop == 'asyncio':
            try:
                import pytest_asyncio
            except ImportError as e:
                raise TypeError(
                    'KIVY_EVENTLOOP is asyncio but "pytest_asyncio" is not '
                    'installed') from e
            async_lib = 'asyncio'
        elif kivy_eventloop == 'trio':
            try:
                import pytest_trio
            except ImportError as e:
                raise TypeError(
                    'KIVY_EVENTLOOP is trio but "pytest_trio" is not '
                    'installed') from e
            async_lib = 'trio'
        else:
            raise TypeError(f'unknown event loop {kivy_eventloop}')

        self._context = context = Context(init=False)
        context['Clock'] = ClockBase(async_lib=async_lib)
        # have to make sure all global kv files are loaded before this because
        # globally read kv files (e.g. on module import) will not be loaded
        # again in the new builder, except if manually loaded, which we don't
        # context['Factory'] = FactoryBase.create_from(Factory)
        # context['Builder'] = BuilderBase.create_from(Builder)
        context.push()

        Window.create_window()
        Window.register()
        Window.initialized = True
        Window.canvas.clear()
        Window.size = self.width, self.height

        from kivy.clock import Clock
        Clock._max_fps = 0
        Clock.init_async_lib(async_lib)
        return self
Beispiel #7
0
    def run(self, name):
        Clock._events = [[] for i in range(256)]
        self._test_started = time()
        self._test_name = self.id()
        self._test = name
        # This setup is done in run() because we need to give control to the
        # kivy event loop which we can only do by returning from the run()
        # that's called. So we override run() and setup mpf-mc and then call
        # our own run_test() on a callback. Then we can wait until the
        # environment is setup (which can take a few frames), then we call
        # super().run() to get the actual TestCase.run() method to run and
        # we return the results.

        # We have to do this in run() and not setUp() because run actually
        # calls setUp(), so since we were overriding it ours doesn't call it
        # so we just do our setup here since if we manually called setUp() then
        # it would be called again when we call super().run().

        from mpf.core.player import Player
        Player.monitor_enabled = False

        mpf_config = ConfigProcessor.load_config_file(
            os.path.abspath(
                os.path.join(mpfmc.__path__[0], os.pardir,
                             self.get_options()['mcconfigfile'])), 'machine')

        machine_path = os.path.abspath(
            os.path.join(mpfmc.__path__[0], os.pardir, 'mpfmc',
                         self.get_machine_path()))

        mpf_config = load_machine_config(
            Util.string_to_list(self.get_config_file()), machine_path,
            mpf_config['mpf-mc']['paths']['config'], mpf_config)
        self.preprocess_config(mpf_config)

        self.mc = MpfMc(options=self.get_options(),
                        config=mpf_config,
                        machine_path=machine_path)

        self.patch_bcp()

        from kivy.core.window import Window
        Window.create_window()
        Window.canvas.clear()

        Clock.schedule_once(self.run_test, 0)
        self.mc.run()
    def _start_mc(self):
        from mpfmc.core.mc import MpfMc

        # prevent sleep in clock
        Clock._max_fps = 0

        machine_path = self.get_absolute_machine_path()

        config_loader = UnitTestConfigLoader(machine_path, self.machine.options['configfile'], {}, {}, {})

        config = config_loader.load_mc_config()

        self.mc = MpfMc(config=config, options=self.get_options())

        from kivy.core.window import Window
        Window.create_window()
        Window.canvas.clear()

        self._start_app_as_slave()
Beispiel #9
0
    def setUp(self):
        # Most of the setup is done in run(). Explanation is there.
        Config._named_configs.pop('app', None)

        self._start_time = time()
        self._current_time = self._start_time
        Clock._start_tick = self._start_time
        Clock._last_tick = self._start_time
        Clock.time = self._mc_time

        # prevent sleep in clock
        Clock._max_fps = 0
        # reset clock
        Clock._root_event = None

        from mpf.core.player import Player
        Player.monitor_enabled = False

        machine_path = self.get_absolute_machine_path()

        # load config
        config_loader = UnitTestConfigLoader(machine_path,
                                             [self.get_config_file()], {}, {},
                                             {})

        config = config_loader.load_mc_config()

        try:
            self.mc = MpfMc(options=self.get_options(), config=config)

            self.patch_bcp()

            from kivy.core.window import Window
            Window.create_window()
            Window.canvas.clear()

            self._start_app_as_slave()
        except Exception:
            if hasattr(self, "mc") and self.mc:
                # prevent dead locks with two asset manager threads
                self.mc.stop()
            raise
Beispiel #10
0
    def setUp(self):
        # Most of the setup is done in run(). Explanation is there.
        Config._named_configs.pop('app', None)

        self._start_time = time()
        self._current_time = self._start_time
        Clock._start_tick = self._start_time
        Clock._last_tick = self._start_time
        Clock.time = self._mc_time

        # prevent sleep in clock
        Clock._max_fps = 0
        Clock._events = [[] for i in range(256)]
        self._test_started = self._start_time

        from mpf.core.player import Player
        Player.monitor_enabled = False

        mpf_config = ConfigProcessor.load_config_file(
            os.path.abspath(
                os.path.join(mpfmc.__path__[0], os.pardir,
                             self.get_options()['mcconfigfile'])), 'machine')

        machine_path = self.getAbsoluteMachinePath()

        mpf_config = load_machine_config(
            Util.string_to_list(self.get_config_file()), machine_path,
            mpf_config['mpf-mc']['paths']['config'], mpf_config)
        self.preprocess_config(mpf_config)

        self.mc = MpfMc(options=self.get_options(),
                        config=mpf_config,
                        machine_path=machine_path)

        self.patch_bcp()

        from kivy.core.window import Window
        Window.create_window()
        Window.canvas.clear()

        self._start_app_as_slave()
Beispiel #11
0
    def setUp(self):
        # Most of the setup is done in run(). Explanation is there.
        Config._named_configs.pop('app', None)

        self._start_time = time()
        self._current_time = self._start_time
        Clock._start_tick = self._start_time
        Clock._last_tick = self._start_time
        Clock.time = self._mc_time

        # prevent sleep in clock
        Clock._max_fps = 0
        Clock._events = [[] for i in range(256)]
        self._test_started = self._start_time

        from mpf.core.player import Player
        Player.monitor_enabled = False

        machine_path = self.getAbsoluteMachinePath()

        try:
            self.mc = MpfMc(options=self.get_options(),
                            machine_path=machine_path)

            self.patch_bcp()

            from kivy.core.window import Window
            Window.create_window()
            Window.canvas.clear()

            self._start_app_as_slave()
        except Exception:
            if self.mc:
                # prevent dead locks with two asset manager threads
                self.mc.stop()
            raise
Beispiel #12
0
async def kivy_app(request, nursery):
    gc.collect()
    if apps:
        last_app, last_request = apps.pop()
        assert last_app() is None, \
            'Memory leak: failed to release app for test ' + repr(last_request)

    from os import environ
    environ['KIVY_USE_DEFAULTCONFIG'] = '1'

    # force window size + remove all inputs
    from kivy.config import Config
    Config.set('graphics', 'width', '320')
    Config.set('graphics', 'height', '240')
    for items in Config.items('input'):
        Config.remove_option('input', items[0])

    from kivy.core.window import Window
    from kivy.context import Context
    from kivy.clock import ClockBase
    from kivy.factory import FactoryBase, Factory
    from kivy.app import App
    from kivy.lang.builder import BuilderBase, Builder
    from kivy.base import stopTouchApp
    from kivy import kivy_data_dir
    from kivy.logger import LoggerHistory

    kivy_eventloop = environ.get('KIVY_EVENTLOOP', 'asyncio')
    if kivy_eventloop == 'asyncio':
        pytest.importorskip(
            'pytest_asyncio',
            reason='KIVY_EVENTLOOP == "asyncio" but '
                   '"pytest_asyncio" is not installed')
        async_lib = 'asyncio'
    elif kivy_eventloop == 'trio':
        pytest.importorskip(
            'pytest_trio',
            reason='KIVY_EVENTLOOP == "trio" but '
                   '"pytest_trio" is not installed')
        async_lib = 'trio'
    else:
        pytest.skip(
            'KIVY_EVENTLOOP must be set to either of "asyncio" or '
            '"trio" to run async tests')

    context = Context(init=False)
    context['Clock'] = ClockBase(async_lib=async_lib)

    # have to make sure all global kv files are loaded before this because
    # globally read kv files (e.g. on module import) will not be loaded again
    # in the new builder, except if manually loaded, which we don't do
    context['Factory'] = FactoryBase.create_from(Factory)
    context['Builder'] = BuilderBase.create_from(Builder)
    context.push()

    Window.create_window()
    Window.register()
    Window.initialized = True
    Window.canvas.clear()

    app = request.param[0]()
    app.set_async_lib(async_lib)

    if async_lib == 'asyncio':
        import asyncio
        loop = asyncio.get_event_loop()
        loop.create_task(app.async_run())
    else:
        nursery.start_soon(app.async_run)
    from kivy.clock import Clock
    Clock._max_fps = 0

    ts = time.perf_counter()
    while not app.app_has_started:
        await app.async_sleep(.1)
        if time.perf_counter() - ts >= 10:
            raise TimeoutError()

    await app.wait_clock_frames(5)

    yield app

    stopTouchApp()

    ts = time.perf_counter()
    while not app.app_has_stopped:
        await app.async_sleep(.1)
        if time.perf_counter() - ts >= 10:
            raise TimeoutError()

    for child in Window.children[:]:
        Window.remove_widget(child)
    context.pop()

    # release all the resources
    del context
    LoggerHistory.clear_history()
    apps.append((weakref.ref(app), request))
    del app
    gc.collect()
Beispiel #13
0
async def ceed_app(request, nursery, temp_file, tmp_path, tmp_path_factory,
                   app_list):

    params = request.param if hasattr(request,
                                      'param') and request.param else {}
    ts0 = time.perf_counter()
    from kivy.core.window import Window
    from kivy.context import Context
    from kivy.clock import ClockBase
    from kivy.animation import Animation
    from kivy.base import stopTouchApp
    from kivy.factory import FactoryBase, Factory
    from kivy.lang.builder import BuilderBase, Builder
    from kivy.logger import LoggerHistory

    context = Context(init=False)
    context['Clock'] = ClockBase(async_lib='trio')
    # context['Factory'] = FactoryBase.create_from(Factory)
    # have to make sure all ceed files are imported before this because
    # globally read kv files will not be loaded again in the new builder,
    # except if manually loaded, which we don't do
    # context['Builder'] = BuilderBase.create_from(Builder)
    context.push()

    Window.create_window()
    Window.register()
    Window.initialized = True
    Window.canvas.clear()

    from kivy.clock import Clock
    Clock._max_fps = 0

    import ceed.view.controller
    ceed.view.controller.ignore_vpixx_import_error = True

    if params.get('persist_config'):
        base = str(tmp_path_factory.getbasetemp() / params['persist_config'])
        app = CeedTestApp(json_config_path=base + 'config.yaml',
                          ini_file=base + 'config.ini',
                          open_player_thread=False)
    else:
        app = CeedTestApp(json_config_path=temp_file('config.yaml'),
                          ini_file=temp_file('config.ini'),
                          open_player_thread=False)
    app.ceed_data.root_path = str(tmp_path)

    try:
        app.set_async_lib('trio')
        nursery.start_soon(app.async_run)

        ts = time.perf_counter()
        while not app.app_has_started:
            await trio.sleep(.1)
            if time.perf_counter() - ts >= 120:
                raise TimeoutError()

        await app.wait_clock_frames(5)

        ts1 = time.perf_counter()
        yield weakref.proxy(app)
        ts2 = time.perf_counter()

        stopTouchApp()

        ts = time.perf_counter()
        while not app.app_has_stopped:
            await trio.sleep(.1)
            if time.perf_counter() - ts >= 40:
                raise TimeoutError()

    finally:
        stopTouchApp()
        for anim in list(Animation._instances):
            anim._unregister()
        app.clean_up()
        for child in Window.children[:]:
            Window.remove_widget(child)

        context.pop()
        del context
        LoggerHistory.clear_history()

    app_list.append((weakref.ref(app), weakref.ref(request)))

    ts3 = time.perf_counter()
    print(ts1 - ts0, ts2 - ts1, ts3 - ts2)
Beispiel #14
0
async def kivy_app(request, nursery):
    from os import environ
    environ['KIVY_USE_DEFAULTCONFIG'] = '1'

    # force window size + remove all inputs
    from kivy.config import Config
    Config.set('graphics', 'width', '320')
    Config.set('graphics', 'height', '240')
    for items in Config.items('input'):
        Config.remove_option('input', items[0])

    from kivy.core.window import Window
    from kivy.context import Context
    from kivy.clock import ClockBase
    from kivy.lang.builder import BuilderBase, Builder
    from kivy.base import stopTouchApp
    from kivy import kivy_data_dir

    kivy_eventloop = environ.get('KIVY_EVENTLOOP', 'asyncio')
    if kivy_eventloop == 'asyncio':
        pytest.importorskip('pytest_asyncio',
                            reason='KIVY_EVENTLOOP == "asyncio" but '
                            '"pytest_asyncio" is not installed')
        async_lib = 'asyncio'
    elif kivy_eventloop == 'trio':
        pytest.importorskip('pytest_trio',
                            reason='KIVY_EVENTLOOP == "trio" but '
                            '"pytest_trio" is not installed')
        async_lib = 'trio'
    else:
        pytest.skip(
            reason='KIVY_EVENTLOOP must be set to either of "asyncio" or '
            '"trio" to run async tests')

    context = Context(init=False)
    context['Clock'] = ClockBase(async_lib=async_lib)
    # context['Builder'] = BuilderBase()
    context.push()
    # Builder.load_file(
    #     os.path.join(kivy_data_dir, 'style.kv'), rulesonly=True)

    Window.create_window()
    Window.register()
    Window.initialized = True
    Window.canvas.clear()

    app = request.param[0]()

    if async_lib == 'asyncio':
        import asyncio
        loop = asyncio.get_event_loop()
        loop.create_task(app.async_run())
    else:
        nursery.start_soon(app.async_run)

    ts = time.perf_counter()
    while not app.app_has_started:
        await async_sleep(.1)
        if time.perf_counter() - ts >= 10:
            raise TimeoutError()

    await app.wait_clock_frames(5)

    yield app

    stopTouchApp()

    ts = time.perf_counter()
    while not app.app_has_stopped:
        await async_sleep(.1)
        if time.perf_counter() - ts >= 10:
            raise TimeoutError()

    for child in Window.children[:]:
        Window.remove_widget(child)
    context.pop()
    gc.collect()