summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:49 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:52 +0900
commited14d55c2e6e867dceed5b50d601d4d83a838619 (patch)
tree5c86789730b159290064228379a48aa47781d52d /tests
parent265684897ba0b24e28710a988cab901acbec1775 (diff)
downloadpygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.gz
pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.bz2
pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.zip
Imported Upstream version 3.7.91.1
Change-Id: I3dcc605b8af37b73443f8f89d884b7b9659959c8 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/Makefile.in11
-rw-r--r--tests/test_gi.py69
-rw-r--r--tests/test_gio.py18
-rw-r--r--tests/test_overrides_gdk.py22
-rw-r--r--tests/test_overrides_gtk.py29
-rw-r--r--tests/test_signal.py121
-rw-r--r--tests/test_source.py31
8 files changed, 264 insertions, 42 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 287542d..140fa2b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -126,6 +126,7 @@ RUN_TESTS_ENV_VARS= \
XDG_DATA_DIRS=$$XDG_DATA_DIRS:/usr/share \
MALLOC_PERTURB_=85 \
MALLOC_CHECK_=3 \
+ G_SLICE=debug-blocks \
TESTS_BUILDDIR=$(builddir)
# pygtkcompat tests need to be run in a separate process as they
@@ -138,7 +139,7 @@ check-local: $(LTLIBRARIES:.la=.so) $(test_typelibs) gschemas.compiled
if type pep8 >/dev/null 2>&1; then pep8 --ignore=E501,E123,E124 --repeat --show-source $(top_srcdir); else echo "skipped, pep8 not installed"; fi; \
fi
export `$(DBUS_LAUNCH)` && \
- $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; \
+ $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd $(srcdir)/runtests.py; rc=$$?; \
[ "$$rc" -ne 0 ] || [ -n "$$TEST_NAMES" ] || { TEST_NAMES=compat_test_pygtk $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; }; \
kill $$DBUS_SESSION_BUS_PID; \
exit $$rc
@@ -150,4 +151,4 @@ check.nemiver:
EXEC_NAME="nemiver" $(MAKE) check
check.valgrind:
- EXEC_NAME="valgrind --leak-check=full --show-possibly-lost=no --suppressions=python.supp" G_SLICE=always-malloc G_DEBUG=gc-friendly $(MAKE) check
+ EXEC_NAME="valgrind --leak-check=full --show-possibly-lost=no --suppressions=python.supp" G_DEBUG=gc-friendly $(MAKE) check
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 5c8f709..6f3cd5e 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -59,8 +59,10 @@ subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -368,6 +370,7 @@ RUN_TESTS_ENV_VARS = \
XDG_DATA_DIRS=$$XDG_DATA_DIRS:/usr/share \
MALLOC_PERTURB_=85 \
MALLOC_CHECK_=3 \
+ G_SLICE=debug-blocks \
TESTS_BUILDDIR=$(builddir)
all: all-am
@@ -759,7 +762,7 @@ check-local: $(LTLIBRARIES:.la=.so) $(test_typelibs) gschemas.compiled
if type pep8 >/dev/null 2>&1; then pep8 --ignore=E501,E123,E124 --repeat --show-source $(top_srcdir); else echo "skipped, pep8 not installed"; fi; \
fi
export `$(DBUS_LAUNCH)` && \
- $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; \
+ $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd $(srcdir)/runtests.py; rc=$$?; \
[ "$$rc" -ne 0 ] || [ -n "$$TEST_NAMES" ] || { TEST_NAMES=compat_test_pygtk $(RUN_TESTS_ENV_VARS) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; }; \
kill $$DBUS_SESSION_BUS_PID; \
exit $$rc
@@ -771,7 +774,7 @@ check.nemiver:
EXEC_NAME="nemiver" $(MAKE) check
check.valgrind:
- EXEC_NAME="valgrind --leak-check=full --show-possibly-lost=no --suppressions=python.supp" G_SLICE=always-malloc G_DEBUG=gc-friendly $(MAKE) check
+ EXEC_NAME="valgrind --leak-check=full --show-possibly-lost=no --suppressions=python.supp" G_DEBUG=gc-friendly $(MAKE) check
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 4545539..e51d7cf 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,6 +12,7 @@ import locale
import subprocess
import gc
import weakref
+import warnings
from io import StringIO, BytesIO
import gi
@@ -1350,13 +1351,15 @@ class TestGValue(unittest.TestCase):
class TestGClosure(unittest.TestCase):
- def test_gclosure_in(self):
+ def test_in(self):
GIMarshallingTests.gclosure_in(lambda: 42)
+ def test_pass(self):
# test passing a closure between two C calls
closure = GIMarshallingTests.gclosure_return()
GIMarshallingTests.gclosure_in(closure)
+ def test_type_error(self):
self.assertRaises(TypeError, GIMarshallingTests.gclosure_in, 42)
self.assertRaises(TypeError, GIMarshallingTests.gclosure_in, None)
@@ -2227,21 +2230,8 @@ class TestMultiOutputArgs(unittest.TestCase):
self.assertEqual((6, 7), GIMarshallingTests.int_return_out())
-class TestGErrorException(unittest.TestCase):
- def test_gerror_exception(self):
- self.assertRaises(GObject.GError, GIMarshallingTests.gerror)
- try:
- GIMarshallingTests.gerror()
- except Exception:
- etype, e = sys.exc_info()[:2]
- self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
- self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
- self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
-
-
# Interface
-
class TestInterfaces(unittest.TestCase):
class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
@@ -2451,19 +2441,17 @@ class TestDir(unittest.TestCase):
# self.assertTrue('DoNotImportDummyTests' in list)
-class TestGErrorArrayInCrash(unittest.TestCase):
- # Previously there was a bug in invoke, in which C arrays were unwrapped
- # from inside GArrays to be passed to the C function. But when a GError was
- # set, invoke would attempt to free the C array as if it were a GArray.
- # This crash is only for C arrays. It does not happen for C functions which
- # take in GArrays. See https://bugzilla.gnome.org/show_bug.cgi?id=642708
- def test_gerror_array_in_crash(self):
+class TestGError(unittest.TestCase):
+ def test_array_in_crash(self):
+ # Previously there was a bug in invoke, in which C arrays were unwrapped
+ # from inside GArrays to be passed to the C function. But when a GError was
+ # set, invoke would attempt to free the C array as if it were a GArray.
+ # This crash is only for C arrays. It does not happen for C functions which
+ # take in GArrays. See https://bugzilla.gnome.org/show_bug.cgi?id=642708
self.assertRaises(GObject.GError, GIMarshallingTests.gerror_array_in, [1, 2, 3])
-
-class TestGErrorOut(unittest.TestCase):
- # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
- def test_gerror_out(self):
+ def test_out(self):
+ # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
error, debug = GIMarshallingTests.gerror_out()
self.assertIsInstance(error, GObject.GError)
@@ -2472,10 +2460,8 @@ class TestGErrorOut(unittest.TestCase):
self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
self.assertEqual(debug, GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE)
-
-class TestGErrorOutTransferNone(unittest.TestCase):
- # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
- def test_gerror_out_transfer_none(self):
+ def test_out_transfer_none(self):
+ # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
error, debug = GIMarshallingTests.gerror_out_transfer_none()
self.assertIsInstance(error, GObject.GError)
@@ -2484,10 +2470,8 @@ class TestGErrorOutTransferNone(unittest.TestCase):
self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug)
-
-class TestGErrorReturn(unittest.TestCase):
- # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
- def test_return_gerror(self):
+ def test_return(self):
+ # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
error = GIMarshallingTests.gerror_return()
self.assertIsInstance(error, GObject.GError)
@@ -2495,6 +2479,16 @@ class TestGErrorReturn(unittest.TestCase):
self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
+ def test_exception(self):
+ self.assertRaises(GObject.GError, GIMarshallingTests.gerror)
+ try:
+ GIMarshallingTests.gerror()
+ except Exception:
+ etype, e = sys.exc_info()[:2]
+ self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
+ self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
+ self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
+
class TestParamSpec(unittest.TestCase):
# https://bugzilla.gnome.org/show_bug.cgi?id=682355
@@ -2907,3 +2901,12 @@ class TestSignatureArgs(unittest.TestCase):
def test_overridden_doc_is_not_clobbered(self):
self.assertEqual(GIMarshallingTests.OverridesObject.method.__doc__,
'Overridden doc string.')
+
+
+class TestDeprecation(unittest.TestCase):
+ def test_method(self):
+ d = GLib.Date.new()
+ with warnings.catch_warnings(record=True) as warn:
+ warnings.simplefilter('always')
+ d.set_time(1)
+ self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 942ee00..57ab013 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -120,6 +120,24 @@ class TestGSettings(unittest.TestCase):
self.assertEqual(bool(empty), True)
self.assertEqual(empty.keys(), [])
+ def test_change_event(self):
+ changed_log = []
+ change_event_log = []
+
+ def on_changed(settings, key):
+ changed_log.append((settings, key))
+
+ def on_change_event(settings, keys, n_keys):
+ change_event_log.append((settings, keys, n_keys))
+
+ self.settings.connect('changed', on_changed)
+ self.settings.connect('change-event', on_change_event)
+ self.settings['test-string'] = 'Moo'
+ self.assertEqual(changed_log, [(self.settings, 'test-string')])
+ self.assertEqual(change_event_log, [(self.settings,
+ [GLib.quark_from_static_string('test-string')],
+ 1)])
+
class TestGFile(unittest.TestCase):
def setUp(self):
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
index 070acb8..46f0a38 100644
--- a/tests/test_overrides_gdk.py
+++ b/tests/test_overrides_gdk.py
@@ -117,3 +117,25 @@ class TestGdk(unittest.TestCase):
self.assertNotEqual(c, None)
self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
+
+ def test_flags(self):
+ self.assertEqual(Gdk.ModifierType.META_MASK | 0, 0x10000000)
+ self.assertEqual(hex(Gdk.ModifierType.META_MASK), '0x10000000')
+ self.assertEqual(str(Gdk.ModifierType.META_MASK),
+ '<flags GDK_META_MASK of type GdkModifierType>')
+
+ self.assertEqual(Gdk.ModifierType.RELEASE_MASK | 0, 0x40000000)
+ self.assertEqual(hex(Gdk.ModifierType.RELEASE_MASK), '0x40000000')
+ self.assertEqual(str(Gdk.ModifierType.RELEASE_MASK),
+ '<flags GDK_RELEASE_MASK of type GdkModifierType>')
+
+ self.assertEqual(Gdk.ModifierType.RELEASE_MASK | Gdk.ModifierType.META_MASK, 0x50000000)
+ self.assertEqual(str(Gdk.ModifierType.RELEASE_MASK | Gdk.ModifierType.META_MASK),
+ '<flags GDK_META_MASK | GDK_RELEASE_MASK of type GdkModifierType>')
+
+ def test_color_parse(self):
+ c = Gdk.color_parse('#00FF80')
+ self.assertEqual(c.red, 0)
+ self.assertEqual(c.green, 65535)
+ self.assertEqual(c.blue, 32896)
+ self.assertEqual(Gdk.color_parse('bogus'), None)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 69f0d38..fdb3ccb 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -4,6 +4,8 @@
import contextlib
import unittest
+import time
+import sys
from compathelper import _unicode, _bytes
@@ -638,6 +640,21 @@ class TestGtk(unittest.TestCase):
self.assertEqual(viewport.props.vadjustment, vadjustment)
self.assertEqual(viewport.props.hadjustment, hadjustment)
+ def test_stock_lookup(self):
+ l = Gtk.stock_lookup('gtk-ok')
+ self.assertEqual(type(l), Gtk.StockItem)
+ self.assertEqual(l.stock_id, 'gtk-ok')
+ self.assertEqual(Gtk.stock_lookup('nosuchthing'), None)
+
+ def test_gtk_main(self):
+ # with no arguments
+ GLib.timeout_add(100, Gtk.main_quit)
+ Gtk.main()
+
+ # overridden function ignores its arguments
+ GLib.timeout_add(100, Gtk.main_quit, 'hello')
+ Gtk.main()
+
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestTreeModel(unittest.TestCase):
@@ -1420,6 +1437,18 @@ class TestTreeModel(unittest.TestCase):
filtered[0][1] = 'ONE'
self.assertEqual(filtered[0][1], 'ONE')
+ def test_list_store_performance(self):
+ model = Gtk.ListStore(int, str)
+
+ iterations = 2000
+ start = time.clock()
+ i = iterations
+ while i > 0:
+ model.append([1, 'hello'])
+ i -= 1
+ end = time.clock()
+ sys.stderr.write('[%.0f µs/append] ' % ((end - start) * 1000000 / iterations))
+
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestTreeView(unittest.TestCase):
diff --git a/tests/test_signal.py b/tests/test_signal.py
index afa9926..776ad7a 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -120,7 +120,9 @@ class Foo(GObject.GObject):
'my-acc-signal': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_INT,
(), my_accumulator, "accum data"),
'my-other-acc-signal': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
- (), GObject.signal_accumulator_true_handled)
+ (), GObject.signal_accumulator_true_handled),
+ 'my-acc-first-wins': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
+ (), GObject.signal_accumulator_first_wins)
}
@@ -148,6 +150,16 @@ class TestAccumulator(unittest.TestCase):
inst.emit("my-other-acc-signal")
self.assertEqual(self.__true_val, 2)
+ def test_accumulator_first_wins(self):
+ # First signal hit will always win
+ inst = Foo()
+ inst.connect("my-acc-first-wins", self._true_handler3)
+ inst.connect("my-acc-first-wins", self._true_handler1)
+ inst.connect("my-acc-first-wins", self._true_handler2)
+ self.__true_val = None
+ inst.emit("my-acc-first-wins")
+ self.assertEqual(self.__true_val, 3)
+
def _true_handler1(self, obj):
self.__true_val = 1
return False
@@ -257,11 +269,88 @@ class TestEmissionHook(unittest.TestCase):
self.assertEqual(obj.status, 3)
+class TestMatching(unittest.TestCase):
+ class Object(GObject.Object):
+ status = 0
+ prop = GObject.Property(type=int, default=0)
+
+ @GObject.Signal()
+ def my_signal(self):
+ pass
+
+ @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=692918
+ def test_signal_handler_block_matching(self):
+ def dummy(*args):
+ "Hack to work around: "
+
+ def foo(obj):
+ obj.status += 1
+
+ obj = self.Object()
+ handler_id = GObject.signal_connect_closure(obj, 'my-signal', foo, after=False)
+ handler_id
+
+ self.assertEqual(obj.status, 0)
+ obj.emit('my-signal')
+ self.assertEqual(obj.status, 1)
+
+ # Blocking by match criteria disables the foo callback
+ signal_id, detail = GObject.signal_parse_name('my-signal', obj, True)
+ count = GObject.signal_handlers_block_matched(obj,
+ GObject.SignalMatchType.ID | GObject.SignalMatchType.CLOSURE,
+ signal_id=signal_id, detail=detail,
+ closure=foo, func=dummy, data=dummy)
+ self.assertEqual(count, 1)
+ obj.emit('my-signal')
+ self.assertEqual(obj.status, 1)
+
+ # Unblocking by the same match criteria allows callback to work again
+ count = GObject.signal_handlers_unblock_matched(obj,
+ GObject.SignalMatchType.ID | GObject.SignalMatchType.CLOSURE,
+ signal_id=signal_id, detail=detail,
+ closure=foo, func=dummy, data=dummy)
+ self.assertEqual(count, 1)
+ obj.emit('my-signal')
+ self.assertEqual(obj.status, 2)
+
+ # Disconnecting by match criteria completely removes the handler
+ count = GObject.signal_handlers_disconnect_matched(obj,
+ GObject.SignalMatchType.ID | GObject.SignalMatchType.CLOSURE,
+ signal_id=signal_id, detail=detail,
+ closure=foo, func=dummy, data=dummy)
+ self.assertEqual(count, 1)
+ obj.emit('my-signal')
+ self.assertEqual(obj.status, 2)
+
+ def test_signal_handler_find(self):
+ def dummy(*args):
+ "Hack to work around: "
+
+ def foo(obj):
+ obj.status += 1
+
+ obj = self.Object()
+ handler_id = GObject.signal_connect_closure(obj, 'my-signal', foo, after=False)
+
+ signal_id, detail = GObject.signal_parse_name('my-signal', obj, True)
+ found_id = GObject.signal_handler_find(obj,
+ GObject.SignalMatchType.ID,
+ signal_id=signal_id, detail=detail,
+ closure=None, func=dummy, data=dummy)
+ self.assertEqual(handler_id, found_id)
+
+
class TestClosures(unittest.TestCase):
def setUp(self):
self.count = 0
self.emission_stopped = False
self.emission_error = False
+ self.handler_pending = False
+
+ def _callback_handler_pending(self, e):
+ signal_id, detail = GObject.signal_parse_name('signal', e, True)
+ self.handler_pending = GObject.signal_has_handler_pending(e, signal_id, detail,
+ may_be_blocked=False)
def _callback(self, e):
self.count += 1
@@ -329,8 +418,8 @@ class TestClosures(unittest.TestCase):
def test_handler_unblock(self):
e = E()
- signal_id = e.connect('signal', self._callback)
- e.handler_block(signal_id)
+ handler_id = e.connect('signal', self._callback)
+ e.handler_block(handler_id)
e.handler_unblock_by_func(self._callback)
e.emit('signal')
self.assertEqual(self.count, 1)
@@ -369,6 +458,32 @@ class TestClosures(unittest.TestCase):
data = c.emit("my_signal", "\01\00\02")
self.assertEqual(data, "\02\00\01")
+ def test_handler_pending(self):
+ obj = F()
+ obj.connect('signal', self._callback_handler_pending)
+ obj.connect('signal', self._callback)
+
+ self.assertEqual(self.count, 0)
+ self.assertEqual(self.handler_pending, False)
+
+ obj.emit('signal')
+ self.assertEqual(self.count, 1)
+ self.assertEqual(self.handler_pending, True)
+
+ def test_signal_handlers_destroy(self):
+ obj = F()
+ obj.connect('signal', self._callback)
+ obj.connect('signal', self._callback)
+ obj.connect('signal', self._callback)
+
+ obj.emit('signal')
+ self.assertEqual(self.count, 3)
+
+ # count should remain at 3 after all handlers are destroyed
+ GObject.signal_handlers_destroy(obj)
+ obj.emit('signal')
+ self.assertEqual(self.count, 3)
+
class SigPropClass(GObject.GObject):
__gsignals__ = {'my_signal': (GObject.SignalFlags.RUN_FIRST, None,
diff --git a/tests/test_source.py b/tests/test_source.py
index dda492a..5b3b51b 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -183,6 +183,37 @@ class TestSource(unittest.TestCase):
GLib.Timeout(20)
GLib.Idle()
+ def test_finalize(self):
+ self.dispatched = False
+ self.finalized = False
+
+ class S(GLib.Source):
+ def prepare(s):
+ return (True, 1)
+
+ def dispatch(s, callback, args):
+ self.dispatched = True
+ return False
+
+ def finalize(s):
+ self.finalized = True
+
+ source = S()
+ id = source.attach()
+ print('source id:', id)
+ self.assertFalse(self.finalized)
+ self.assertFalse(source.is_destroyed())
+
+ while source.get_context().iteration(False):
+ pass
+
+ source.destroy()
+ self.assertTrue(self.dispatched)
+ self.assertFalse(self.finalized)
+ self.assertTrue(source.is_destroyed())
+ del source
+ self.assertTrue(self.finalized)
+
class TestUserData(unittest.TestCase):
def test_idle_no_data(self):