Пример #1
0
    def test_gtk_schedule_action_due(self):
        scheduler = GtkScheduler()
        starttime = datetime.utcnow()
        endtime = [None]

        def action(scheduler, state):
            endtime[0] = datetime.utcnow()

        scheduler.schedule_relative(200, action)

        def done(data):
            Gtk.main_quit()
            assert endtime[0]
            diff = endtime[0] - starttime
            assert diff > timedelta(milliseconds=180)
            return False

        GLib.timeout_add(300, done, None)
        Gtk.main()
Пример #2
0
    def test_gtk_schedule_action_relative(self):
        scheduler = GtkScheduler()
        gate = threading.Semaphore(0)
        starttime = datetime.utcnow()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = datetime.utcnow()

        scheduler.schedule_relative(0.1, action)

        def done(data):
            Gtk.main_quit()
            gate.release()

        GLib.timeout_add(200, done, None)
        Gtk.main()

        gate.acquire()
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(milliseconds=80)
Пример #3
0
    def test_gtk_schedule_action_relative(self):
        scheduler = GtkScheduler()
        gate = threading.Semaphore(0)
        starttime = default_now()
        endtime = None

        def action(scheduler, state):
            nonlocal endtime
            endtime = default_now()

        scheduler.schedule_relative(0.1, action)

        def done(data):
            Gtk.main_quit()
            gate.release()
            return False

        GLib.timeout_add(200, done, None)
        Gtk.main()

        gate.acquire()
        assert endtime is not None
        diff = endtime - starttime
        assert diff > timedelta(milliseconds=80)
Пример #4
0
    def test_gtk_schedule_action_cancel(self):
        ran = [False]
        scheduler = GtkScheduler()

        def action(scheduler, state):
            ran[0] = True
        d = scheduler.schedule_relative(100, action)
        d.dispose()

        def done(data):
            Gtk.main_quit()
            assert not ran[0]
            return False

        GLib.timeout_add(300, done, None)
        Gtk.main()
Пример #5
0
    def test_gtk_schedule_action_cancel(self):
        ran = False
        scheduler = GtkScheduler()
        gate = threading.Semaphore(0)

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()

        def done(data):
            Gtk.main_quit()
            gate.release()

        GLib.timeout_add(200, done, None)
        Gtk.main()

        gate.acquire()
        assert ran is False
Пример #6
0
    def test_gtk_schedule_action_cancel(self):
        ran = False
        scheduler = GtkScheduler()
        gate = threading.Semaphore(0)

        def action(scheduler, state):
            nonlocal ran
            ran = True

        d = scheduler.schedule_relative(0.1, action)
        d.dispose()

        def done(data):
            Gtk.main_quit()
            gate.release()
            return False

        GLib.timeout_add(200, done, None)
        Gtk.main()

        gate.acquire()
        assert ran is False