diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:47:05 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:47:08 +0900 |
commit | e49df4afb1654f59a39d02e6ec0ecdf537ce9351 (patch) | |
tree | 000154f278704965f45c9ae9a7ed8475e4b10ca1 /tests | |
parent | 3a2fe8f548bb171295a989bf143f8c7a75715e6e (diff) | |
download | pygobject2-e49df4afb1654f59a39d02e6ec0ecdf537ce9351.tar.gz pygobject2-e49df4afb1654f59a39d02e6ec0ecdf537ce9351.tar.bz2 pygobject2-e49df4afb1654f59a39d02e6ec0ecdf537ce9351.zip |
Imported Upstream version 3.3.5
Change-Id: Ib5961d5ca7c3b6c41650123a60433cb2ca0ebd58
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/Makefile.in | 26 | ||||
-rw-r--r-- | tests/test-unknown.c | 2 | ||||
-rw-r--r-- | tests/test_atoms.py | 7 | ||||
-rw-r--r-- | tests/test_everything.py | 9 | ||||
-rw-r--r-- | tests/test_gi.py | 81 | ||||
-rw-r--r-- | tests/test_overrides.py | 90 | ||||
-rw-r--r-- | tests/test_properties.py | 55 | ||||
-rw-r--r-- | tests/test_pygtkcompat.py | 36 | ||||
-rw-r--r-- | tests/testhelpermodule.c | 4 |
10 files changed, 250 insertions, 62 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 38bfce0..950385e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -120,5 +120,3 @@ check.nemiver: 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 - --include $(top_srcdir)/git.mk diff --git a/tests/Makefile.in b/tests/Makefile.in index 5432107..d12cc85 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11.5 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -16,23 +16,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -122,11 +105,6 @@ am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(nodist_libgimarshallingtests_la_SOURCES) \ $(nodist_libregress_la_SOURCES) $(testhelper_la_SOURCES) DIST_SOURCES = $(testhelper_la_SOURCES) -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -739,8 +717,6 @@ check.nemiver: 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 --include $(top_srcdir)/git.mk - # 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. .NOEXPORT: diff --git a/tests/test-unknown.c b/tests/test-unknown.c index 85aba73..f1c3139 100644 --- a/tests/test-unknown.c +++ b/tests/test-unknown.c @@ -53,7 +53,7 @@ test_interface_get_type (void) return gtype; } -void test_unknown_iface_method (TestInterface *iface) +static void test_unknown_iface_method (TestInterface *iface) { } diff --git a/tests/test_atoms.py b/tests/test_atoms.py index 851368f..a59d15a 100644 --- a/tests/test_atoms.py +++ b/tests/test_atoms.py @@ -1,8 +1,13 @@ import unittest -from gi.repository import Gdk, Gtk +try: + from gi.repository import Atk, Gdk, Gtk + (Atk, Gdk) # pyflakes +except: + Gdk = None +@unittest.skipUnless(Gdk, 'Gdk not available') class TestGdkAtom(unittest.TestCase): def test_create(self): atom = Gdk.Atom.intern('my_string', False) diff --git a/tests/test_everything.py b/tests/test_everything.py index 728d58a..3cf98fa 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -15,12 +15,18 @@ try: except ImportError: has_cairo = False +#import gi from gi.repository import GObject from gi.repository import GLib from gi.repository import Gio -from gi.repository import Gtk from gi.repository import Regress as Everything +try: + from gi.repository import Gtk + Gtk # pyflakes +except: + Gtk = None + if sys.version_info < (3, 0): UNICHAR = "\xe2\x99\xa5" PY2_UNICODE_UNICHAR = unicode(UNICHAR, 'UTF-8') @@ -676,6 +682,7 @@ class TestSignals(unittest.TestCase): class TestPango(unittest.TestCase): + @unittest.skipUnless(Gtk, 'Gtk not available') def test_cairo_font_options(self): screen = Gtk.Window().get_screen() font_opts = screen.get_font_options() diff --git a/tests/test_gi.py b/tests/test_gi.py index 4348c29..3862334 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -12,7 +12,8 @@ import locale import subprocess from io import StringIO, BytesIO -from gi.repository import GObject, GLib +import gi +from gi.repository import GObject, GLib, Gio from gi.repository import GIMarshallingTests @@ -1873,6 +1874,69 @@ class TestInterfaces(unittest.TestCase): GIMarshallingTests.Interface2): pass + def test_type_mismatch(self): + obj = GIMarshallingTests.Object() + + # wrong type for first argument: interface + enum = Gio.File.new_for_path('.').enumerate_children( + '', Gio.FileQueryInfoFlags.NONE, None) + try: + enum.next_file(obj) + self.fail('call with wrong type argument unexpectedly succeeded') + except TypeError as e: + # should have argument name + self.assertTrue('cancellable' in str(e), e) + # should have expected type + self.assertTrue('xpected Gio.Cancellable' in str(e), e) + # should have actual type + self.assertTrue('GIMarshallingTests.Object' in str(e), e) + + # wrong type for self argument: interface + try: + Gio.FileEnumerator.next_file(obj, None) + self.fail('call with wrong type argument unexpectedly succeeded') + except TypeError as e: + if sys.version_info < (3, 0): + self.assertTrue('FileEnumerator' in str(e), e) + self.assertTrue('Object' in str(e), e) + else: + # should have argument name + self.assertTrue('self' in str(e), e) + # should have expected type + self.assertTrue('xpected Gio.FileEnumerator' in str(e), e) + # should have actual type + self.assertTrue('GIMarshallingTests.Object' in str(e), e) + + # wrong type for first argument: GObject + var = GLib.Variant('s', 'mystring') + action = Gio.SimpleAction.new('foo', var.get_type()) + try: + action.activate(obj) + self.fail('call with wrong type argument unexpectedly succeeded') + except TypeError as e: + # should have argument name + self.assertTrue('parameter' in str(e), e) + # should have expected type + self.assertTrue('xpected GLib.Variant' in str(e), e) + # should have actual type + self.assertTrue('GIMarshallingTests.Object' in str(e), e) + + # wrong type for self argument: GObject + try: + Gio.SimpleAction.activate(obj, obj) + self.fail('call with wrong type argument unexpectedly succeeded') + except TypeError as e: + if sys.version_info < (3, 0): + self.assertTrue('SimpleAction' in str(e), e) + self.assertTrue('Object' in str(e), e) + else: + # should have argument name + self.assertTrue('self' in str(e), e) + # should have expected type + self.assertTrue('xpected Gio.Action' in str(e), e) + # should have actual type + self.assertTrue('GIMarshallingTests.Object' in str(e), e) + class TestInterfaceClash(unittest.TestCase): @@ -2292,3 +2356,18 @@ class TestModule(unittest.TestCase): self.assertTrue('SimpleStruct' in output, output) self.assertTrue('Interface2' in output, output) self.assertTrue('method_array_inout' in output, output) + + +class TestProjectVersion(unittest.TestCase): + def test_version_str(self): + self.assertGreaterEqual(gi.__version__, "3.3.5") + + def test_version_info(self): + self.assertEqual(len(gi.version_info), 3) + self.assertGreaterEqual(gi.version_info, (3, 3, 5)) + + def test_check_version(self): + self.assertRaises(ValueError, gi.check_version, (99, 0, 0)) + self.assertRaises(ValueError, gi.check_version, "99.0.0") + gi.check_version((3, 3, 5)) + gi.check_version("3.3.5") diff --git a/tests/test_overrides.py b/tests/test_overrides.py index 73b17a5..3990454 100644 --- a/tests/test_overrides.py +++ b/tests/test_overrides.py @@ -8,15 +8,32 @@ sys.path.insert(0, "../") from compathelper import _long, _unicode, _bytes +import gi.overrides as overrides +import gi.types from gi.repository import GLib from gi.repository import GObject -from gi.repository import Gdk -from gi.repository import Gtk from gi.repository import Gio -from gi.repository import Pango -from gi.repository import GdkPixbuf -import gi.overrides as overrides -import gi.types + +try: + from gi.repository import GdkPixbuf + GdkPixbuf # pyflakes +except ImportError: + GdkPixbuf = None + +try: + from gi.repository import Atk, Pango + (Atk, Pango) # pyflakes +except ImportError: + Pango = None + +Gtk = None +if Pango: + try: + from gi.repository import Gdk + from gi.repository import Gtk + Gtk # pyflakes + except ImportError: + Gtk = None class TestRegistry(unittest.TestCase): @@ -470,6 +487,7 @@ class TestGLib(unittest.TestCase): self.assertEqual(repr(v), "GLib.Variant('(is)', (1, 'somestring'))") +@unittest.skipUnless(Pango, 'Pango not available') class TestPango(unittest.TestCase): def test_default_font_description(self): @@ -491,6 +509,7 @@ class TestPango(unittest.TestCase): self.assertEqual(layout.get_text(), "Foobar") +@unittest.skipUnless(Gtk, 'Gtk not available') class TestGdk(unittest.TestCase): def test_constructor(self): @@ -598,6 +617,7 @@ class TestGdk(unittest.TestCase): self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3) +@unittest.skipUnless(Gtk, 'Gtk not available') class TestGtk(unittest.TestCase): def test_container(self): @@ -1392,6 +1412,10 @@ class TestGtk(unittest.TestCase): self.assertFalse(p1 <= None) self.assertEqual(tuple(p1), (1, 2, 3)) + self.assertEqual(p1[0], 1) + self.assertEqual(p1[1], 2) + self.assertEqual(p1[2], 3) + self.assertRaises(IndexError, p1.__getitem__, 3) def test_tree_model(self): tree_store = Gtk.TreeStore(int, str) @@ -1566,6 +1590,15 @@ class TestGtk(unittest.TestCase): self.assertRaises(IndexError, tree_store.__delitem__, -101) self.assertRaises(IndexError, tree_store.__delitem__, 101) + def test_tree_model_get_iter_fail(self): + # TreeModel class with a failing get_iter() + class MyTreeModel(GObject.GObject, Gtk.TreeModel): + def do_get_iter(self, iter): + return (False, None) + + tm = MyTreeModel() + self.assertEqual(tm.get_iter_first(), None) + def test_tree_model_edit(self): model = Gtk.ListStore(int, str, float) model.append([1, "one", -0.1]) @@ -1648,6 +1681,32 @@ class TestGtk(unittest.TestCase): text=0, style=2) + def test_tree_view_column_set_attributes(self): + store = Gtk.ListStore(int, str) + directors = ['Fellini', 'Tarantino', 'Tarkovskiy'] + for i, director in enumerate(directors): + store.append([i, director]) + + treeview = Gtk.TreeView() + treeview.set_model(store) + + column = Gtk.TreeViewColumn() + treeview.append_column(column) + + cell = Gtk.CellRendererText() + column.pack_start(cell, expand=True) + column.set_attributes(cell, text=1) + + # might cause a Pango warning, do not break on this + old_mask = GLib.log_set_always_fatal( + GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) + # This will make cell.props.text receive a value, otherwise it + # will be None. + treeview.get_preferred_size() + GLib.log_set_always_fatal(old_mask) + + self.assertTrue(cell.props.text in directors) + def test_tree_selection(self): store = Gtk.ListStore(int, str) for i in range(10): @@ -1751,6 +1810,25 @@ class TestGtk(unittest.TestCase): self.assertFalse(start.ends_tag()) self.assertFalse(start.toggles_tag()) + def test_text_buffer_search(self): + buffer = Gtk.TextBuffer() + buffer.set_text('Hello World Hello GNOME') + + i = buffer.get_iter_at_offset(0) + self.assertTrue(isinstance(i, Gtk.TextIter)) + + self.assertEqual(i.forward_search('world', 0, None), None) + + (start, end) = i.forward_search('World', 0, None) + self.assertEqual(start.get_offset(), 6) + self.assertEqual(end.get_offset(), 11) + + (start, end) = i.forward_search('world', + Gtk.TextSearchFlags.CASE_INSENSITIVE, + None) + self.assertEqual(start.get_offset(), 6) + self.assertEqual(end.get_offset(), 11) + def test_buttons(self): self.assertEqual(Gtk.Button, overrides.Gtk.Button) diff --git a/tests/test_properties.py b/tests/test_properties.py index f81ed4f..2b77d28 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -2,6 +2,7 @@ import sys import struct +import types import unittest from gi.repository import GObject @@ -9,7 +10,11 @@ from gi.repository.GObject import GType, new, PARAM_READWRITE, \ PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY from gi.repository.GObject import \ TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, \ - TYPE_UINT64, TYPE_GTYPE, TYPE_INVALID, TYPE_NONE, TYPE_STRV + TYPE_UINT64, TYPE_GTYPE, TYPE_INVALID, TYPE_NONE, TYPE_STRV, \ + TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_BOOLEAN, TYPE_FLOAT, \ + TYPE_DOUBLE, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \ + TYPE_STRING, TYPE_PYOBJECT + from gi.repository.GObject import \ G_MININT, G_MAXINT, G_MAXUINT, G_MINLONG, G_MAXLONG, G_MAXULONG @@ -312,22 +317,22 @@ class TestProperties(unittest.TestCase): minint64 = -maxint64 - 1 maxuint64 = umax('Q') - types = dict(int=(TYPE_INT, minint, maxint), - uint=(TYPE_UINT, 0, maxuint), - long=(TYPE_LONG, minlong, maxlong), - ulong=(TYPE_ULONG, 0, maxulong), - int64=(TYPE_INT64, minint64, maxint64), - uint64=(TYPE_UINT64, 0, maxuint64)) + types_ = dict(int=(TYPE_INT, minint, maxint), + uint=(TYPE_UINT, 0, maxuint), + long=(TYPE_LONG, minlong, maxlong), + ulong=(TYPE_ULONG, 0, maxulong), + int64=(TYPE_INT64, minint64, maxint64), + uint64=(TYPE_UINT64, 0, maxuint64)) - def build_gproperties(types): + def build_gproperties(types_): d = {} - for key, (gtype, min, max) in types.items(): + for key, (gtype, min, max) in types_.items(): d[key] = (gtype, 'blurb', 'desc', min, max, 0, PARAM_READABLE | PARAM_WRITABLE) return d class RangeCheck(GObject.GObject): - __gproperties__ = build_gproperties(types) + __gproperties__ = build_gproperties(types_) def __init__(self): self.values = {} @@ -353,7 +358,7 @@ class TestProperties(unittest.TestCase): self.assertEqual(RangeCheck.props.uint64.maximum, maxuint64) obj = RangeCheck() - for key, (gtype, min, max) in types.items(): + for key, (gtype, min, max) in types_.items(): self.assertEqual(obj.get_property(key), getattr(RangeCheck.props, key).default_value) @@ -494,7 +499,7 @@ class TestProperty(unittest.TestCase): minint64 = -2 ** 62 - 1 maxuint64 = 2 ** 63 - 1 - types = [ + types_ = [ (TYPE_INT, G_MININT, G_MAXINT), (TYPE_UINT, 0, G_MAXUINT), (TYPE_LONG, G_MINLONG, G_MAXLONG), @@ -503,7 +508,7 @@ class TestProperty(unittest.TestCase): (TYPE_UINT64, 0, maxuint64), ] - for gtype, min, max in types: + for gtype, min, max in types_: # Normal, everything is alright prop = GObject.Property(type=gtype, minimum=min, maximum=max) subtype = type('', (GObject.GObject,), dict(prop=prop)) @@ -680,6 +685,30 @@ class TestProperty(unittest.TestCase): self.assertEqual(C.blurbed.blurb, 'blurbed doc string') + def testPythonToGLibTypeMapping(self): + tester = GObject.Property() + self.assertEqual(tester._type_from_python(int), GObject.TYPE_INT) + if sys.version_info < (3, 0): + self.assertEqual(tester._type_from_python(long), GObject.TYPE_LONG) + self.assertEqual(tester._type_from_python(bool), GObject.TYPE_BOOLEAN) + self.assertEqual(tester._type_from_python(float), GObject.TYPE_DOUBLE) + self.assertEqual(tester._type_from_python(str), GObject.TYPE_STRING) + self.assertEqual(tester._type_from_python(object), GObject.TYPE_PYOBJECT) + + self.assertEqual(tester._type_from_python(GObject.GObject), GObject.GObject.__gtype__) + self.assertEqual(tester._type_from_python(GObject.GEnum), GObject.GEnum.__gtype__) + self.assertEqual(tester._type_from_python(GObject.GFlags), GObject.GFlags.__gtype__) + self.assertEqual(tester._type_from_python(GObject.GBoxed), GObject.GBoxed.__gtype__) + + for type_ in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, + TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG, + TYPE_ULONG, TYPE_INT64, TYPE_UINT64, + TYPE_FLOAT, TYPE_DOUBLE, TYPE_POINTER, + TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_STRING, + TYPE_PYOBJECT, TYPE_GTYPE, TYPE_STRV]: + self.assertEqual(tester._type_from_python(type_), type_) + + self.assertRaises(TypeError, tester._type_from_python, types.CodeType) if __name__ == '__main__': unittest.main() diff --git a/tests/test_pygtkcompat.py b/tests/test_pygtkcompat.py index 245ee67..926910b 100644 --- a/tests/test_pygtkcompat.py +++ b/tests/test_pygtkcompat.py @@ -6,36 +6,48 @@ import unittest import sys sys.path.insert(0, "../") -from gi.repository import Gdk -from gi.repository import Gtk +from gi.repository import GLib -import gi.pygtkcompat +try: + from gi.repository import Pango + from gi.repository import Atk + from gi.repository import Gdk + from gi.repository import Gtk + (Atk, Gtk, Pango) # pyflakes -gi.pygtkcompat.enable() -gi.pygtkcompat.enable_gtk(version='3.0') + import gi.pygtkcompat -import atk -import pango -import pangocairo -import gtk -import gtk.gdk + gi.pygtkcompat.enable() + gi.pygtkcompat.enable_gtk(version='3.0') + import atk + import pango + import pangocairo + import gtk + import gtk.gdk +except ImportError: + Gtk = None + +@unittest.skipUnless(Gtk, 'Gtk not available') class TestATKCompat(unittest.TestCase): def testObject(self): self.assertTrue(hasattr(atk, 'Object')) +@unittest.skipUnless(Gtk, 'Gtk not available') class TestPangoCompat(unittest.TestCase): def testLayout(self): self.assertTrue(hasattr(pango, 'Layout')) +@unittest.skipUnless(Gtk, 'Gtk not available') class TestPangoCairoCompat(unittest.TestCase): def testErrorUnderlinePath(self): self.assertTrue(hasattr(pangocairo, 'error_underline_path')) +@unittest.skipUnless(Gtk, 'Gtk not available') class TestGTKCompat(unittest.TestCase): def testButtons(self): self.assertEqual(Gdk._2BUTTON_PRESS, 5) @@ -90,7 +102,11 @@ class TestGTKCompat(unittest.TestCase): liststore.append((1, 'One')) liststore.append((2, 'Two')) liststore.append((3, 'Three')) + # might cause a Pango warning, do not break on this + old_mask = GLib.log_set_always_fatal( + GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) combo = gtk.ComboBoxEntry(model=liststore) + GLib.log_set_always_fatal(old_mask) combo.set_text_column(1) combo.set_active(0) self.assertEqual(combo.get_text_column(), 1) diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c index 592c503..d26ec9f 100644 --- a/tests/testhelpermodule.c +++ b/tests/testhelpermodule.c @@ -14,7 +14,7 @@ static PyObject * _wrap_TestInterface__do_iface_method(PyObject *cls, PyObject *args, PyObject *kwargs); -GType +static GType test_type_get_type(void) { static GType gtype = 0; @@ -339,7 +339,7 @@ test_object_callback (GObject *object, GObject *o) return o; } -void +static void connectcallbacks (GObject *object) { |