diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/Makefile.in | 3 | ||||
-rw-r--r-- | tests/test_cairo.py | 141 | ||||
-rw-r--r-- | tests/test_error.py | 116 | ||||
-rw-r--r-- | tests/test_everything.py | 44 | ||||
-rw-r--r-- | tests/test_gi.py | 59 | ||||
-rw-r--r-- | tests/test_gio.py | 6 | ||||
-rw-r--r-- | tests/test_iochannel.py | 2 | ||||
-rw-r--r-- | tests/test_option.py | 2 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 92 | ||||
-rw-r--r-- | tests/test_repository.py | 25 | ||||
-rw-r--r-- | tests/test_signal.py | 28 | ||||
-rw-r--r-- | tests/test_typeclass.py | 80 |
13 files changed, 480 insertions, 121 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 3468740..c0f34f8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,6 +84,8 @@ EXTRA_DIST = \ test-unknown.h \ te_ST@nouppera \ org.gnome.test.gschema.xml \ + test_cairo.py \ + test_error.py \ test_gio.py \ test_glib.py \ test_gobject.py \ @@ -99,6 +101,7 @@ EXTRA_DIST = \ test_source.py \ test_subprocess.py \ test_thread.py \ + test_typeclass.py \ test_everything.py \ test_gi.py \ test_gdbus.py \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 5b94b34..cdadc6f 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -382,6 +382,8 @@ EXTRA_DIST = \ test-unknown.h \ te_ST@nouppera \ org.gnome.test.gschema.xml \ + test_cairo.py \ + test_error.py \ test_gio.py \ test_glib.py \ test_gobject.py \ @@ -397,6 +399,7 @@ EXTRA_DIST = \ test_source.py \ test_subprocess.py \ test_thread.py \ + test_typeclass.py \ test_everything.py \ test_gi.py \ test_gdbus.py \ diff --git a/tests/test_cairo.py b/tests/test_cairo.py new file mode 100644 index 0000000..fdf86a2 --- /dev/null +++ b/tests/test_cairo.py @@ -0,0 +1,141 @@ +# -*- Mode: Python; py-indent-offset: 4 -*- +# coding=utf-8 +# vim: tabstop=4 shiftwidth=4 expandtab + +import unittest + +import gi + +try: + gi.require_foreign('cairo') + import cairo + from gi.repository import Regress + has_cairo = True +except ImportError: + has_cairo = False + +try: + from gi.repository import Gtk + Gtk # pyflakes +except: + Gtk = None + +from gi.repository import GObject + + +@unittest.skipUnless(has_cairo, 'built without cairo support') +class Test(unittest.TestCase): + def test_cairo_context(self): + context = Regress.test_cairo_context_full_return() + self.assertTrue(isinstance(context, cairo.Context)) + + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) + context = cairo.Context(surface) + Regress.test_cairo_context_none_in(context) + + def test_cairo_surface(self): + surface = Regress.test_cairo_surface_none_return() + self.assertTrue(isinstance(surface, cairo.ImageSurface)) + self.assertTrue(isinstance(surface, cairo.Surface)) + self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) + self.assertEqual(surface.get_width(), 10) + self.assertEqual(surface.get_height(), 10) + + surface = Regress.test_cairo_surface_full_return() + self.assertTrue(isinstance(surface, cairo.ImageSurface)) + self.assertTrue(isinstance(surface, cairo.Surface)) + self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) + self.assertEqual(surface.get_width(), 10) + self.assertEqual(surface.get_height(), 10) + + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) + Regress.test_cairo_surface_none_in(surface) + + surface = Regress.test_cairo_surface_full_out() + self.assertTrue(isinstance(surface, cairo.ImageSurface)) + self.assertTrue(isinstance(surface, cairo.Surface)) + self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) + self.assertEqual(surface.get_width(), 10) + self.assertEqual(surface.get_height(), 10) + + def test_require_foreign(self): + self.assertEqual(gi.require_foreign('cairo'), None) + self.assertEqual(gi.require_foreign('cairo', 'Context'), None) + self.assertRaises(ImportError, gi.require_foreign, 'invalid_module') + self.assertRaises(ImportError, gi.require_foreign, 'invalid_module', 'invalid_symbol') + self.assertRaises(ImportError, gi.require_foreign, 'cairo', 'invalid_symbol') + + +@unittest.skipUnless(has_cairo, 'built without cairo support') +@unittest.skipUnless(Gtk, 'Gtk not available') +class TestPango(unittest.TestCase): + def test_cairo_font_options(self): + screen = Gtk.Window().get_screen() + font_opts = screen.get_font_options() + self.assertEqual(type(font_opts.get_subpixel_order()), int) + + +if has_cairo: + from gi.repository import cairo as CairoGObject + + # Use PyGI signals to test non-introspected foreign marshaling. + class CairoSignalTester(GObject.Object): + sig_context = GObject.Signal(arg_types=[CairoGObject.Context]) + sig_surface = GObject.Signal(arg_types=[CairoGObject.Surface]) + sig_font_face = GObject.Signal(arg_types=[CairoGObject.FontFace]) + sig_scaled_font = GObject.Signal(arg_types=[CairoGObject.ScaledFont]) + sig_pattern = GObject.Signal(arg_types=[CairoGObject.Pattern]) + + +@unittest.skipUnless(has_cairo, 'built without cairo support') +class TestSignalMarshaling(unittest.TestCase): + # Tests round tripping of cairo objects through non-introspected signals. + + def setUp(self): + self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) + self.context = cairo.Context(self.surface) + self.tester = CairoSignalTester() + + def pass_object_through_signal(self, obj, signal): + """Pass the given `obj` through the `signal` emission storing the + `obj` passed through the signal and returning it.""" + passthrough_result = [] + + def callback(instance, passthrough): + passthrough_result.append(passthrough) + + signal.connect(callback) + signal.emit(obj) + + return passthrough_result[0] + + def test_context(self): + result = self.pass_object_through_signal(self.context, self.tester.sig_context) + self.assertTrue(isinstance(result, cairo.Context)) + + def test_surface(self): + result = self.pass_object_through_signal(self.surface, self.tester.sig_surface) + self.assertTrue(isinstance(result, cairo.Surface)) + + def test_font_face(self): + font_face = self.context.get_font_face() + result = self.pass_object_through_signal(font_face, self.tester.sig_font_face) + self.assertTrue(isinstance(result, cairo.FontFace)) + + def test_scaled_font(self): + scaled_font = cairo.ScaledFont(self.context.get_font_face(), + cairo.Matrix(), + cairo.Matrix(), + self.context.get_font_options()) + result = self.pass_object_through_signal(scaled_font, self.tester.sig_scaled_font) + self.assertTrue(isinstance(result, cairo.ScaledFont)) + + def test_pattern(self): + pattern = cairo.SolidPattern(1, 1, 1, 1) + result = self.pass_object_through_signal(pattern, self.tester.sig_pattern) + self.assertTrue(isinstance(result, cairo.Pattern)) + self.assertTrue(isinstance(result, cairo.SolidPattern)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_error.py b/tests/test_error.py new file mode 100644 index 0000000..baccef5 --- /dev/null +++ b/tests/test_error.py @@ -0,0 +1,116 @@ +# -*- Mode: Python; py-indent-offset: 4 -*- +# vim: tabstop=4 shiftwidth=4 expandtab +# +# test_error.py: Tests for GError wrapper implementation +# +# Copyright (C) 2012 Will Thompson +# Copyright (C) 2013 Martin Pitt +# Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +# USA + +import unittest + +from gi.repository import GLib +from gi.repository import GIMarshallingTests + + +class TestType(unittest.TestCase): + def test_attributes(self): + e = GLib.Error('test message', 'mydomain', 42) + self.assertEqual(e.message, 'test message') + self.assertEqual(e.domain, 'mydomain') + self.assertEqual(e.code, 42) + + def test_new_literal(self): + mydomain = GLib.quark_from_string('mydomain') + e = GLib.Error.new_literal(mydomain, 'test message', 42) + self.assertEqual(e.message, 'test message') + self.assertEqual(e.domain, 'mydomain') + self.assertEqual(e.code, 42) + + def test_matches(self): + mydomain = GLib.quark_from_string('mydomain') + notmydomain = GLib.quark_from_string('notmydomain') + e = GLib.Error('test message', 'mydomain', 42) + self.assertTrue(e.matches(mydomain, 42)) + self.assertFalse(e.matches(notmydomain, 42)) + self.assertFalse(e.matches(mydomain, 40)) + + def test_str(self): + e = GLib.Error('test message', 'mydomain', 42) + self.assertEqual(str(e), + 'mydomain: test message (42)') + + def test_repr(self): + e = GLib.Error('test message', 'mydomain', 42) + self.assertEqual(repr(e), + "GLib.Error('test message', 'mydomain', 42)") + + def test_inheritance(self): + self.assertTrue(issubclass(GLib.Error, RuntimeError)) + + +class TestMarshalling(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(GLib.Error, GIMarshallingTests.gerror_array_in, [1, 2, 3]) + + def test_out(self): + # See https://bugzilla.gnome.org/show_bug.cgi?id=666098 + error, debug = GIMarshallingTests.gerror_out() + + self.assertIsInstance(error, GLib.Error) + self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) + self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE) + self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) + self.assertEqual(debug, GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE) + + 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, GLib.Error) + self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) + self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE) + self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) + self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug) + + def test_return(self): + # See https://bugzilla.gnome.org/show_bug.cgi?id=666098 + error = GIMarshallingTests.gerror_return() + + self.assertIsInstance(error, GLib.Error) + self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) + self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE) + self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) + + def test_exception(self): + with self.assertRaises(GLib.Error) as context: + GIMarshallingTests.gerror() + + e = context.exception + self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) + self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE) + self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_everything.py b/tests/test_everything.py index 0cd1804..f6017e4 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -10,12 +10,12 @@ import sys try: import cairo + cairo # Pyflakes has_cairo = True from gi.repository import Regress as Everything except ImportError: has_cairo = False -#import gi from gi.repository import GObject from gi.repository import GLib from gi.repository import Gio @@ -47,39 +47,6 @@ class RawGList(ctypes.Structure): @unittest.skipUnless(has_cairo, 'built without cairo support') class TestEverything(unittest.TestCase): - def test_cairo_context(self): - context = Everything.test_cairo_context_full_return() - self.assertTrue(isinstance(context, cairo.Context)) - - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) - context = cairo.Context(surface) - Everything.test_cairo_context_none_in(context) - - def test_cairo_surface(self): - surface = Everything.test_cairo_surface_none_return() - self.assertTrue(isinstance(surface, cairo.ImageSurface)) - self.assertTrue(isinstance(surface, cairo.Surface)) - self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) - self.assertEqual(surface.get_width(), 10) - self.assertEqual(surface.get_height(), 10) - - surface = Everything.test_cairo_surface_full_return() - self.assertTrue(isinstance(surface, cairo.ImageSurface)) - self.assertTrue(isinstance(surface, cairo.Surface)) - self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) - self.assertEqual(surface.get_width(), 10) - self.assertEqual(surface.get_height(), 10) - - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10) - Everything.test_cairo_surface_none_in(surface) - - surface = Everything.test_cairo_surface_full_out() - self.assertTrue(isinstance(surface, cairo.ImageSurface)) - self.assertTrue(isinstance(surface, cairo.Surface)) - self.assertEqual(surface.get_format(), cairo.FORMAT_ARGB32) - self.assertEqual(surface.get_width(), 10) - self.assertEqual(surface.get_height(), 10) - def test_bool(self): self.assertEqual(Everything.test_boolean(False), False) self.assertEqual(Everything.test_boolean(True), True) @@ -1347,12 +1314,3 @@ class TestSignals(unittest.TestCase): self.assertEqual(obj.callback_i, 42) self.assertEqual(type(rv), GLib.Array) self.assertEqual(rv.len, 2) - - -@unittest.skipUnless(has_cairo, 'built without cairo support') -@unittest.skipUnless(Gtk, 'Gtk not available') -class TestPango(unittest.TestCase): - def test_cairo_font_options(self): - screen = Gtk.Window().get_screen() - font_opts = screen.get_font_options() - self.assertEqual(type(font_opts.get_subpixel_order()), int) diff --git a/tests/test_gi.py b/tests/test_gi.py index 9846440..4a5d510 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -61,9 +61,8 @@ class Sequence(object): class TestConstant(unittest.TestCase): -# Blocked by https://bugzilla.gnome.org/show_bug.cgi?id=595773 -# def test_constant_utf8(self): -# self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.CONSTANT_UTF8) + def test_constant_utf8(self): + self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.CONSTANT_UTF8) def test_constant_number(self): self.assertEqual(CONSTANT_NUMBER, GIMarshallingTests.CONSTANT_NUMBER) @@ -2009,7 +2008,6 @@ class TestGObject(unittest.TestCase): GIMarshallingTests.Object.none_inout(GIMarshallingTests.SubObject(int=42)) - @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=709796 def test_object_full_inout(self): # Using gimarshallingtests.c from GI versions > 1.38.0 will show this # test as an "unexpected success" due to reference leak fixes in that file. @@ -2524,9 +2522,7 @@ class TestOverrides(unittest.TestCase): # not overridden self.assertEqual(GIMarshallingTests.SubObject.__module__, 'gi.repository.GIMarshallingTests') - # FIXME: does not work with TEST_NAMES='test_thread test_gi.TestOverrides', - # it is importlib._bootstrap then - #self.assertEqual(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject') + self.assertEqual(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject') class TestDir(unittest.TestCase): @@ -2554,55 +2550,6 @@ class TestDir(unittest.TestCase): # self.assertTrue('DoNotImportDummyTests' in list) -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]) - - def test_out(self): - # See https://bugzilla.gnome.org/show_bug.cgi?id=666098 - error, debug = GIMarshallingTests.gerror_out() - - self.assertIsInstance(error, GObject.GError) - self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) - self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE) - self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) - self.assertEqual(debug, GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE) - - 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) - self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) - self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE) - self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE) - self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug) - - def test_return(self): - # See https://bugzilla.gnome.org/show_bug.cgi?id=666098 - error = GIMarshallingTests.gerror_return() - - self.assertIsInstance(error, GObject.GError) - self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN) - 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 @unittest.expectedFailure diff --git a/tests/test_gio.py b/tests/test_gio.py index 57ab013..986d6dc 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -40,7 +40,7 @@ class TestGio(unittest.TestCase): class TestGSettings(unittest.TestCase): def setUp(self): - self.settings = Gio.Settings('org.gnome.test') + self.settings = Gio.Settings(schema='org.gnome.test') # we change the values in the tests, so set them to predictable start # value self.settings.reset('test-string') @@ -78,7 +78,7 @@ class TestGSettings(unittest.TestCase): self.assertEqual(self.settings.get_property('path'), '/tests/') # optional constructor arguments - with_path = Gio.Settings('org.gnome.nopathtest', path='/mypath/') + with_path = Gio.Settings(schema='org.gnome.nopathtest', path='/mypath/') self.assertEqual(with_path.get_property('path'), '/mypath/') self.assertEqual(with_path['np-int'], 42) @@ -115,7 +115,7 @@ class TestGSettings(unittest.TestCase): self.assertRaises(KeyError, self.settings.__setitem__, 'unknown', 'moo') def test_empty(self): - empty = Gio.Settings('org.gnome.empty', path='/tests/') + empty = Gio.Settings(schema='org.gnome.empty', path='/tests/') self.assertEqual(len(empty), 0) self.assertEqual(bool(empty), True) self.assertEqual(empty.keys(), []) diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py index 0cc1b4b..259171b 100644 --- a/tests/test_iochannel.py +++ b/tests/test_iochannel.py @@ -108,7 +108,7 @@ second line ch.seek(2, 2) # SEEK_END # FIXME: does not work currently - #self.assertEqual(ch.read(2), b'n!') + # self.assertEqual(ch.read(2), b'n!') # invalid whence value self.assertRaises(ValueError, ch.seek, 0, 3) diff --git a/tests/test_option.py b/tests/test_option.py index 2900edd..fe25746 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -71,7 +71,7 @@ class TestOption(unittest.TestCase): def test_parse_args_double_dash(self): options, args = self.parser.parse_args( ["test_option.py", "--", "-xxx"]) - #self.assertEqual(args, ["-xxx"]) + # self.assertEqual(args, ["-xxx"]) def test_parse_args_group(self): group = self._create_group() diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 2a0fd90..d339adf 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -632,6 +632,35 @@ class TestGtk(unittest.TestCase): @unittest.skipUnless(Gtk, 'Gtk not available') +class TestWidget(unittest.TestCase): + def test_style_get_property_gvalue(self): + button = Gtk.Button() + value = GObject.Value(int, -42) + button.style_get_property('focus-padding', value) + # Test only that the style property changed since we can't actuall + # set it. + self.assertNotEqual(value.get_int(), -42) + + def test_style_get_property_return_with_explicit_gvalue(self): + button = Gtk.Button() + value = GObject.Value(int, -42) + result = button.style_get_property('focus-padding', value) + self.assertIsInstance(result, int) + self.assertNotEqual(result, -42) + + def test_style_get_property_return_with_implicit_gvalue(self): + button = Gtk.Button() + result = button.style_get_property('focus-padding') + self.assertIsInstance(result, int) + self.assertNotEqual(result, -42) + + def test_style_get_property_error(self): + button = Gtk.Button() + with self.assertRaises(ValueError): + button.style_get_property('not-a-valid-style-property') + + +@unittest.skipUnless(Gtk, 'Gtk not available') class TestSignals(unittest.TestCase): def test_class_closure_override_with_aliased_type(self): class WindowWithSizeAllocOverride(Gtk.ScrolledWindow): @@ -1796,3 +1825,66 @@ class TestTextBuffer(unittest.TestCase): None) self.assertEqual(start.get_offset(), 6) self.assertEqual(end.get_offset(), 11) + + +@unittest.skipUnless(Gtk, 'Gtk not available') +class TestContainer(unittest.TestCase): + def test_child_set_property(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=False, fill=True, padding=0) + + box.child_set_property(child, 'padding', 42) + + value = GObject.Value(int) + box.child_get_property(child, 'padding', value) + self.assertEqual(value.get_int(), 42) + + def test_child_get_property_gvalue(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=False, fill=True, padding=42) + + value = GObject.Value(int) + box.child_get_property(child, 'padding', value) + self.assertEqual(value.get_int(), 42) + + def test_child_get_property_return_with_explicit_gvalue(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=False, fill=True, padding=42) + + value = GObject.Value(int) + result = box.child_get_property(child, 'padding', value) + self.assertEqual(result, 42) + + def test_child_get_property_return_with_implicit_gvalue(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=False, fill=True, padding=42) + + result = box.child_get_property(child, 'padding') + self.assertEqual(result, 42) + + def test_child_get_property_error(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=False, fill=True, padding=42) + with self.assertRaises(ValueError): + box.child_get_property(child, 'not-a-valid-child-property') + + def test_child_get_and_set(self): + box = Gtk.Box() + child = Gtk.Button() + box.pack_start(child, expand=True, fill=True, padding=42) + + expand, fill, padding = box.child_get(child, 'expand', 'fill', 'padding') + self.assertEqual(expand, True) + self.assertEqual(fill, True) + self.assertEqual(padding, 42) + + box.child_set(child, expand=False, fill=False, padding=21, pack_type=1) + expand, fill, padding, pack_type = box.child_get(child, 'expand', 'fill', 'padding', 'pack-type') + self.assertEqual(expand, False) + self.assertEqual(fill, False) + self.assertEqual(padding, 21) diff --git a/tests/test_repository.py b/tests/test_repository.py index c02581c..b73fbf9 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -100,6 +100,13 @@ class Test(unittest.TestCase): self.assertFalse(info.get_fundamental()) self.assertEqual(info.get_parent(), repo.find_by_name('GObject', 'Object')) + def test_callable_inheritance(self): + self.assertTrue(issubclass(GIRepository.CallableInfo, GIRepository.BaseInfo)) + self.assertTrue(issubclass(GIRepository.CallbackInfo, GIRepository.CallableInfo)) + self.assertTrue(issubclass(GIRepository.FunctionInfo, GIRepository.CallableInfo)) + self.assertTrue(issubclass(GIRepository.VFuncInfo, GIRepository.CallableInfo)) + self.assertTrue(issubclass(GIRepository.SignalInfo, GIRepository.CallableInfo)) + def test_registered_type_info(self): info = repo.find_by_name('GIMarshallingTests', 'Object') # Call these from the class because GIObjectInfo overrides them @@ -213,7 +220,6 @@ class Test(unittest.TestCase): self.assertEqual(func_info.get_return_type().get_tag(), GIRepository.TypeTag.VOID) self.assertRaises(AttributeError, func_info.get_return_attribute, '_not_an_attr') - @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=709462 @unittest.skipUnless(has_cairo, 'Regress needs cairo') def test_signal_info(self): repo.require('Regress') @@ -231,7 +237,6 @@ class Test(unittest.TestCase): self.assertFalse(sig_info.true_stops_emit()) self.assertEqual(sig_info.get_flags(), sig_flags) - @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=709462 @unittest.skipUnless(has_cairo, 'Regress needs cairo') def test_notify_signal_info_with_obj(self): repo.require('Regress') @@ -302,6 +307,22 @@ class Test(unittest.TestCase): self.assertEqual(vfunc.get_offset(), 0xFFFF) # unknown offset self.assertEqual(vfunc.get_signal(), None) + def test_callable_can_throw_gerror(self): + info = repo.find_by_name('GIMarshallingTests', 'Object') + invoker = find_child_info(info, 'get_methods', 'vfunc_meth_with_error') + vfunc = find_child_info(info, 'get_vfuncs', 'vfunc_meth_with_err') + + self.assertTrue(invoker.can_throw_gerror()) + self.assertTrue(vfunc.can_throw_gerror()) + + # Test that args do not include the GError** + self.assertEqual(len(invoker.get_arguments()), 1) + self.assertEqual(len(vfunc.get_arguments()), 1) + + # Sanity check method that does not throw. + invoker_no_throws = find_child_info(info, 'get_methods', 'method_int8_in') + self.assertFalse(invoker_no_throws.can_throw_gerror()) + def test_flags_double_registration_error(self): # a warning is printed for double registration and pygobject will # also raise a RuntimeError. diff --git a/tests/test_signal.py b/tests/test_signal.py index 429afc9..80d4ac5 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -136,9 +136,9 @@ class TestAccumulator(unittest.TestCase): inst = Foo() inst.my_acc_signal.connect(lambda obj: 1) inst.my_acc_signal.connect(lambda obj: 2) - ## the value returned in the following handler will not be - ## considered, because at this point the accumulator already - ## reached its limit. + # the value returned in the following handler will not be + # considered, because at this point the accumulator already + # reached its limit. inst.my_acc_signal.connect(lambda obj: 3) retval = inst.my_acc_signal.emit() self.assertEqual(retval, 3) @@ -147,8 +147,8 @@ class TestAccumulator(unittest.TestCase): inst = Foo() inst.my_other_acc_signal.connect(self._true_handler1) inst.my_other_acc_signal.connect(self._true_handler2) - ## the following handler will not be called because handler2 - ## returns True, so it should stop the emission. + # the following handler will not be called because handler2 + # returns True, so it should stop the emission. inst.my_other_acc_signal.connect(self._true_handler3) self.__true_val = None inst.my_other_acc_signal.emit() @@ -629,20 +629,20 @@ class _TestCMarshaller: rv = self.obj.emit("test-gvalue", v) self.assertEqual(rv, GObject.G_MAXINT64) - # implicit int64 - # does not work, see https://bugzilla.gnome.org/show_bug.cgi?id=683775 - #rv = self.obj.emit("test-gvalue", GObject.G_MAXINT64) - #self.assertEqual(rv, GObject.G_MAXINT64) - # explicit uint64 v = GObject.Value(GObject.TYPE_UINT64, GObject.G_MAXUINT64) rv = self.obj.emit("test-gvalue", v) self.assertEqual(rv, GObject.G_MAXUINT64) + @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=705291 + def test_gvalue_implicit_int64(self): + # implicit int64 + rv = self.obj.emit("test-gvalue", GObject.G_MAXINT64) + self.assertEqual(rv, GObject.G_MAXINT64) + # implicit uint64 - # does not work, see https://bugzilla.gnome.org/show_bug.cgi?id=683775 - #rv = self.obj.emit("test-gvalue", GObject.G_MAXUINT64) - #self.assertEqual(rv, GObject.G_MAXUINT64) + rv = self.obj.emit("test-gvalue", GObject.G_MAXUINT64) + self.assertEqual(rv, GObject.G_MAXUINT64) def test_gvalue_ret(self): self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT), @@ -705,7 +705,6 @@ class TestSignalDecorator(unittest.TestCase): @GObject.SignalOverride def notify(self, *args, **kargs): self.overridden_closure_called = True - #GObject.GObject.notify(self, *args, **kargs) def on_notify(self, obj, prop): self.notify_called = True @@ -763,7 +762,6 @@ class TestSignalDecorator(unittest.TestCase): obj = self.DecoratedOverride() obj.connect("notify", obj.on_notify) self.assertEqual(obj.value, 0) - #obj.notify.emit() obj.value = 1 self.assertEqual(obj.value, 1) self.assertTrue(obj.overridden_closure_called) diff --git a/tests/test_typeclass.py b/tests/test_typeclass.py new file mode 100644 index 0000000..3ece684 --- /dev/null +++ b/tests/test_typeclass.py @@ -0,0 +1,80 @@ +# -*- Mode: Python; py-indent-offset: 4 -*- +# vim: tabstop=4 shiftwidth=4 expandtab +# +# test_typeclass.py: Tests for GTypeClass related methods and marshalling. +# +# Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +# USA + +import unittest + +from gi.repository import GObject +from gi.repository import GIMarshallingTests + + +class TestCoercion(unittest.TestCase): + def test_coerce_from_class(self): + prop = GObject.ObjectClass.find_property(GIMarshallingTests.PropertiesObject, + 'some-int') + + self.assertIsInstance(prop, GObject.GParamSpec) + self.assertEqual(prop.name, 'some-int') + self.assertEqual(prop.value_type, GObject.TYPE_INT) + self.assertEqual(prop.owner_type, + GIMarshallingTests.PropertiesObject.__gtype__) + + def test_coerce_from_gtype(self): + gtype = GIMarshallingTests.PropertiesObject.__gtype__ + prop = GObject.ObjectClass.find_property(gtype, 'some-int') + + self.assertIsInstance(prop, GObject.GParamSpec) + self.assertEqual(prop.name, 'some-int') + self.assertEqual(prop.value_type, GObject.TYPE_INT) + self.assertEqual(prop.owner_type, gtype) + + def test_coerce_from_instance(self): + obj = GIMarshallingTests.PropertiesObject() + prop = GObject.ObjectClass.find_property(obj, 'some-int') + + self.assertIsInstance(prop, GObject.GParamSpec) + self.assertEqual(prop.name, 'some-int') + self.assertEqual(prop.value_type, GObject.TYPE_INT) + self.assertEqual(prop.owner_type, obj.__gtype__) + + def test_marshalling_error(self): + with self.assertRaises(TypeError): + GObject.ObjectClass.find_property(object, 'some-int') + + with self.assertRaises(TypeError): + GObject.ObjectClass.find_property(42, 'some-int') + + +class TestTypeClassMethodsMovedToClass(unittest.TestCase): + def test_list_child_properties(self): + pspecs = GIMarshallingTests.PropertiesObject.list_properties() + pnames = [pspec.name for pspec in pspecs] + self.assertTrue('some-int' in pnames) + self.assertTrue('some-float' in pnames) + self.assertTrue('some-char' in pnames) + + def test_find_child_property(self): + pspec = GIMarshallingTests.PropertiesObject.find_property('some-int') + self.assertEqual(pspec.name, 'some-int') + + +if __name__ == '__main__': + unittest.main() |