示例#1
0
    def test_add_main_option(self):
        stored_options = []

        def on_handle_local_options(app, options):
            stored_options.append(options)
            return 0  # Return 0 if options have been handled

        def on_activate(app):
            pass

        app = Gio.Application()
        app.add_main_option(long_name='string',
                            short_name=b's',
                            flags=0,
                            arg=GLib.OptionArg.STRING,
                            description='some string')

        app.connect('activate', on_activate)
        app.connect('handle-local-options', on_handle_local_options)
        app.run(['app', '-s', 'test string'])

        self.assertEqual(len(stored_options), 1)
        options = stored_options[0]
        self.assertTrue(options.contains('string'))
        self.assertEqual(
            options.lookup_value('string').unpack(), 'test string')
示例#2
0
 def test_cantRegisterTwice(self):
     """
     It is not possible to register more than one C{Application}.
     """
     reactor = gireactor.GIReactor(useGtk=False)
     self.addCleanup(self.unbuildReactor, reactor)
     app = Gio.Application(
         application_id='com.twistedmatrix.trial.gireactor',
         flags=Gio.ApplicationFlags.FLAGS_NONE)
     reactor.registerGApplication(app)
     app2 = Gio.Application(
         application_id='com.twistedmatrix.trial.gireactor2',
         flags=Gio.ApplicationFlags.FLAGS_NONE)
     exc = self.assertRaises(RuntimeError,
                                 reactor.registerGApplication, app2)
     self.assertEqual(exc.args[0],
                      "Can't register more than one application instance.")
示例#3
0
    def test_gio_application(self):
        app = Gio.Application()
        signal.signal(signal.SIGALRM, lambda *args: app.quit())
        GLib.idle_add(signal.setitimer, signal.ITIMER_REAL, 0.001)

        with self._run_with_timeout(2000, app.quit):
            app.hold()
            app.connect("activate", lambda *args: None)
            app.run()
示例#4
0
    def test_set_application(self, glib_loop):
        assert glib_loop._application is None
        assert glib_loop._policy._application is None

        app = Gio.Application()
        glib_loop.set_application(app)

        assert glib_loop._application == app
        assert glib_loop._policy._application == app
示例#5
0
    def test_stop(self, glib_loop):
        with mock.patch.object(glib_loop, '_mainloop') as ml:
            glib_loop.stop()
            ml.quit.assert_any_call()

        glib_loop.set_application(Gio.Application())

        with mock.patch.object(glib_loop, '_application') as app:
            glib_loop.stop()
            app.quit.assert_any_call()
示例#6
0
    def test_run(self, glib_loop):
        with mock.patch.object(glib_loop, "_mainloop") as ml:
            glib_loop.run()
            ml.run.assert_any_call()

        glib_loop.set_application(Gio.Application())

        with mock.patch.object(glib_loop, "_application") as app:
            glib_loop.run()
            app.run.assert_any_call(None)
示例#7
0
    def test_gApplicationActivate(self):
        """
        L{Gio.Application} instances can be registered with a gireactor.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.runReactor(app, reactor)
示例#8
0
 def test_portable(self):
     """
     L{gireactor.PortableGIReactor} doesn't support application
     registration at this time.
     """
     reactor = gireactor.PortableGIReactor()
     self.addCleanup(self.unbuildReactor, reactor)
     app = Gio.Application(
         application_id='com.twistedmatrix.trial.gireactor',
         flags=Gio.ApplicationFlags.FLAGS_NONE)
     self.assertRaises(NotImplementedError,
                       reactor.registerGApplication, app)
示例#9
0
def launch(_name, _version, _prefix, _libdir, _flags=0):
    args = _parseLaunchArgs(sys.argv,
                            _name=_name,
                            _version=_version,
                            _flags=_flags)

    if _runningFromSource():
        return start(args,
                     _name=_name,
                     _version=_version,
                     _flags=_flags,
                     _prefix=_prefix,
                     _libdir=_libdir)
    else:
        _flags |= Gio.ApplicationFlags.IS_LAUNCHER

        app = Gio.Application(application_id=_name, flags=_flags)
        return app.run(args)
示例#10
0
    def test_cantRegisterAfterRun(self):
        """
        It is not possible to register a C{Application} after the reactor has
        already started.
        """
        reactor = gireactor.GIReactor(useGtk=False)
        self.addCleanup(self.unbuildReactor, reactor)
        app = Gio.Application(
            application_id='com.twistedmatrix.trial.gireactor',
            flags=Gio.ApplicationFlags.FLAGS_NONE)

        def tryRegister():
            exc = self.assertRaises(ReactorAlreadyRunning,
                                    reactor.registerGApplication, app)
            self.assertEqual(exc.args[0],
                             "Can't register application after reactor was started.")
            reactor.stop()
        reactor.callLater(0, tryRegister)
        ReactorBuilder.runReactor(self, reactor)
示例#11
0
    def test_set_application_invalid_when_running(self, glib_loop):
        app = Gio.Application()

        with pytest.raises(RuntimeError):
            with mock.patch.object(glib_loop, 'is_running', return_value=True):
                glib_loop.set_application(app)
示例#12
0
    def test_set_application_invalid_repeat_calls(self, glib_loop):
        app = Gio.Application()
        glib_loop.set_application(app)

        with pytest.raises(ValueError):
            glib_loop.set_application(app)
示例#13
0
    def test_new_event_loop_application(self, glib_policy):
        a = glib_policy.new_event_loop()
        a.set_application(Gio.Application())
        b = glib_policy.new_event_loop()

        assert b._application is None