diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.in | 7 | ||||
-rwxr-xr-x | tests/runtests.py | 2 | ||||
-rw-r--r-- | tests/test-thread.c | 3 | ||||
-rw-r--r-- | tests/test_everything.py | 1 | ||||
-rw-r--r-- | tests/test_gi.py | 4 | ||||
-rw-r--r-- | tests/test_gobject.py | 18 | ||||
-rw-r--r-- | tests/test_overrides_glib.py | 23 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 16 | ||||
-rw-r--r-- | tests/test_properties.py | 13 | ||||
-rw-r--r-- | tests/test_signal.py | 54 |
10 files changed, 120 insertions, 21 deletions
diff --git a/tests/Makefile.in b/tests/Makefile.in index 8e4e802..a29792b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -59,10 +59,8 @@ 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/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 + $(top_srcdir)/m4/jhflags.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 @@ -243,6 +241,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ THREADING_CFLAGS = @THREADING_CFLAGS@ VERSION = @VERSION@ +WARN_CFLAGS = @WARN_CFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ diff --git a/tests/runtests.py b/tests/runtests.py index 1bd1be0..d3a4f47 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -23,7 +23,7 @@ if sys.version_info[:2] == (2, 6): sys.stderr.write('[expected failure] ') return lambda obj: obj - unittest.skipIf = skipUnless + unittest.skipIf = skipIf def assertGreater(self, a, b, msg=None): if not a > b: diff --git a/tests/test-thread.c b/tests/test-thread.c index 0f5b909..438cb97 100644 --- a/tests/test-thread.c +++ b/tests/test-thread.c @@ -43,8 +43,7 @@ other_thread_cb (TestThread *self) static void test_thread_emit_signal (TestThread *self) { - self->thread = g_thread_create ((GThreadFunc)other_thread_cb, - self, TRUE, NULL); + self->thread = g_thread_new ("t", (GThreadFunc)other_thread_cb, self); } static void test_thread_init (TestThread *self) {} diff --git a/tests/test_everything.py b/tests/test_everything.py index dcc61e8..3c820d7 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -218,7 +218,6 @@ class TestEverything(unittest.TestCase): GObject.G_MAXDOUBLE) self.assertEqual(Everything.test_double(GObject.G_MINDOUBLE), GObject.G_MINDOUBLE) - self.assertRaises(ValueError, Everything.test_double, GObject.G_MAXDOUBLE * 2) (two, three) = Everything.test_multi_double_args(2.5) self.assertAlmostEqual(two, 5.0) diff --git a/tests/test_gi.py b/tests/test_gi.py index 29a69d0..ee2f3de 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -1475,7 +1475,7 @@ class TestEnum(unittest.TestCase): def test_enum_gtype_name_is_namespaced(self): self.assertEqual(GIMarshallingTests.Enum.__gtype__.name, - 'GIMarshallingTestsEnum') + 'PyGIMarshallingTestsEnum') def test_enum_double_registration_error(self): # a warning is printed for double registration and pygobject will @@ -1627,7 +1627,7 @@ class TestNoTypeFlags(unittest.TestCase): def test_flags_gtype_name_is_namespaced(self): self.assertEqual(GIMarshallingTests.NoTypeFlags.__gtype__.name, - 'GIMarshallingTestsNoTypeFlags') + 'PyGIMarshallingTestsNoTypeFlags') def test_flags_double_registration_error(self): # a warning is printed for double registration and pygobject will diff --git a/tests/test_gobject.py b/tests/test_gobject.py index 9b4f5f7..ec4cb44 100644 --- a/tests/test_gobject.py +++ b/tests/test_gobject.py @@ -597,6 +597,10 @@ class TestPropertyBindings(unittest.TestCase): class TestGValue(unittest.TestCase): + def test_type_constant(self): + self.assertEqual(GObject.TYPE_VALUE, GObject.Value.__gtype__) + self.assertEqual(GObject.type_name(GObject.TYPE_VALUE), 'GValue') + def test_no_type(self): value = GObject.Value() self.assertEqual(value.g_type, GObject.TYPE_INVALID) @@ -620,10 +624,24 @@ class TestGValue(unittest.TestCase): # python float is G_TYPE_DOUBLE value = GObject.Value(float, 23.4) self.assertEqual(value.g_type, GObject.TYPE_DOUBLE) + value.set_value(1e50) + self.assertAlmostEqual(value.get_value(), 1e50) value = GObject.Value(GObject.TYPE_FLOAT, 23.4) self.assertEqual(value.g_type, GObject.TYPE_FLOAT) self.assertRaises(TypeError, value.set_value, 'string') + self.assertRaises(ValueError, value.set_value, 1e50) + + def test_float_inf_nan(self): + nan = float('nan') + for type_ in [GObject.TYPE_FLOAT, GObject.TYPE_DOUBLE]: + for x in [float('inf'), float('-inf'), nan]: + value = GObject.Value(type_, x) + # assertEqual() is False for (nan, nan) + if x is nan: + self.assertEqual(str(value.get_value()), 'nan') + else: + self.assertEqual(value.get_value(), x) def test_enum(self): value = GObject.Value(GLib.FileError, GLib.FileError.FAILED) diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py index 3799454..4d7e63a 100644 --- a/tests/test_overrides_glib.py +++ b/tests/test_overrides_glib.py @@ -272,6 +272,14 @@ class TestGVariant(unittest.TestCase): res = GLib.Variant('a{si}', {'key1': 1, 'key2': 2}).unpack() self.assertEqual(res, {'key1': 1, 'key2': 2}) + # maybe + v = GLib.Variant.new_maybe(GLib.VariantType.new('i'), GLib.Variant('i', 1)) + res = v.unpack() + self.assertEqual(res, 1) + v = GLib.Variant.new_maybe(GLib.VariantType.new('i'), None) + res = v.unpack() + self.assertEqual(res, None) + def test_iteration(self): # array index access vb = GLib.VariantBuilder.new(gi._gi.variant_type_from_string('ai')) @@ -463,6 +471,19 @@ class TestGVariant(unittest.TestCase): assert_equals_bool('v', GLib.Variant('i', 1)) def test_repr(self): + # with C constructor + v = GLib.Variant.new_uint32(42) + self.assertEqual(repr(v), "GLib.Variant('u', 42)") + + # with override constructor v = GLib.Variant('(is)', (1, 'somestring')) - self.assertEqual(str(v), "(1, 'somestring')") self.assertEqual(repr(v), "GLib.Variant('(is)', (1, 'somestring'))") + + def test_str(self): + # with C constructor + v = GLib.Variant.new_uint32(42) + self.assertEqual(str(v), 'uint32 42') + + # with override constructor + v = GLib.Variant('(is)', (1, 'somestring')) + self.assertEqual(str(v), "(1, 'somestring')") diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index d429d4d..9315019 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -1407,9 +1407,11 @@ class TestTreeView(unittest.TestCase): old_mask = GLib.log_set_always_fatal( GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) try: - # causes the widget to get realized and cellN.props.text receive a - # value, otherwise it will be None. - tree.get_preferred_size() + # We must realize the TreeView for cell.props.text to receive a value + dialog = Gtk.Dialog() + dialog.get_action_area().add(tree) + dialog.show_all() + dialog.hide() finally: GLib.log_set_always_fatal(old_mask) @@ -1444,9 +1446,11 @@ class TestTreeView(unittest.TestCase): old_mask = GLib.log_set_always_fatal( GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) try: - # This will make cell.props.text receive a value, otherwise it - # will be None. - treeview.get_preferred_size() + # We must realize the TreeView for cell.props.text to receive a value + dialog = Gtk.Dialog() + dialog.get_action_area().add(treeview) + dialog.show_all() + dialog.hide() finally: GLib.log_set_always_fatal(old_mask) diff --git a/tests/test_properties.py b/tests/test_properties.py index d19970f..d0552e0 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -715,7 +715,7 @@ class TestProperty(unittest.TestCase): self.assertEqual(b.prop1, 20) def test_property_subclass_c(self): - class A(GIMarshallingTests.PropertiesObject): + class A(Regress.TestSubObj): prop1 = GObject.Property(type=int) a = A() @@ -723,8 +723,15 @@ class TestProperty(unittest.TestCase): self.assertEqual(a.prop1, 10) # also has parent properties - a.props.some_int = 20 - self.assertEqual(a.props.some_int, 20) + a.props.int = 20 + self.assertEqual(a.props.int, 20) + + # Some of which are unusable without introspection + a.props.list = ("str1", "str2") + self.assertEqual(a.props.list, ["str1", "str2"]) + + a.set_property("list", ("str3", "str4")) + self.assertEqual(a.props.list, ["str3", "str4"]) def test_property_subclass_custom_setter(self): # test for #523352 diff --git a/tests/test_signal.py b/tests/test_signal.py index 8f31c35..afa9926 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -165,6 +165,9 @@ class E(GObject.GObject): __gsignals__ = {'signal': (GObject.SignalFlags.RUN_FIRST, None, ())} + # Property used to test detailed signal + prop = GObject.Property(type=int, default=0) + def __init__(self): GObject.GObject.__init__(self) self.status = 0 @@ -257,17 +260,66 @@ class TestEmissionHook(unittest.TestCase): class TestClosures(unittest.TestCase): def setUp(self): self.count = 0 + self.emission_stopped = False + self.emission_error = False def _callback(self, e): self.count += 1 - def test_disconnect(self): + def _callback_stop_emission(self, obj, prop, stop_it): + if stop_it: + obj.stop_emission_by_name('notify::prop') + self.emission_stopped = True + else: + self.count += 1 + + def _callback_invalid_stop_emission_name(self, obj, prop): + # We expect a GLib warning but there currently is no way to test that + # This can at least make sure we don't crash + old_mask = GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL | + GLib.LogLevelFlags.LEVEL_ERROR) + try: + obj.stop_emission_by_name('notasignal::baddetail') + finally: + GLib.log_set_always_fatal(old_mask) + self.emission_error = True + + def test_disconnect_by_func(self): e = E() e.connect('signal', self._callback) e.disconnect_by_func(self._callback) e.emit('signal') self.assertEqual(self.count, 0) + def test_disconnect(self): + e = E() + handler_id = e.connect('signal', self._callback) + self.assertTrue(e.handler_is_connected(handler_id)) + e.disconnect(handler_id) + e.emit('signal') + self.assertEqual(self.count, 0) + self.assertFalse(e.handler_is_connected(handler_id)) + + def test_stop_emission_by_name(self): + e = E() + + # Sandwich a callback that stops emission in between a callback that increments + e.connect('notify::prop', self._callback_stop_emission, False) + e.connect('notify::prop', self._callback_stop_emission, True) + e.connect('notify::prop', self._callback_stop_emission, False) + + e.set_property('prop', 1234) + self.assertEqual(e.get_property('prop'), 1234) + self.assertEqual(self.count, 1) + self.assertTrue(self.emission_stopped) + + def test_stop_emission_by_name_error(self): + e = E() + + e.connect('notify::prop', self._callback_invalid_stop_emission_name) + e.set_property('prop', 1234) + self.assertTrue(self.emission_error) + def test_handler_block(self): e = E() e.connect('signal', self._callback) |