File: test_thread.py

package info (click to toggle)
pygobject 3.54.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,864 kB
  • sloc: ansic: 40,281; python: 26,363; sh: 477; makefile: 81; xml: 35; cpp: 1
file content (32 lines) | stat: -rw-r--r-- 804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import unittest

from gi.repository import GLib

import testhelper


class TestThread(unittest.TestCase):
    def setUp(self):
        self.main = GLib.MainLoop()
        self.called = False

    def from_thread_cb(self, test, enum):
        assert test == self.obj
        assert int(enum) == 0
        assert type(enum) is not int
        self.called = True
        GLib.idle_add(self.timeout_cb)

    def idle_cb(self):
        self.obj = testhelper.get_test_thread()
        self.obj.connect("from-thread", self.from_thread_cb)
        self.obj.emit("emit-signal")

    def test_extension_module(self):
        GLib.idle_add(self.idle_cb)
        GLib.timeout_add(2000, self.timeout_cb)
        self.main.run()
        self.assertTrue(self.called)

    def timeout_cb(self):
        self.main.quit()