summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:44:16 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:44:20 +0900
commitdf54f0de0e94c4e39273b175eab134878b0dc1a6 (patch)
tree9232900f002b75c69fb5fbe2d3f24f21ae0fcbb7 /tests
parent3adbc715171ea3d98e808544bc59c69a9f0f991e (diff)
downloadpygobject2-df54f0de0e94c4e39273b175eab134878b0dc1a6.tar.gz
pygobject2-df54f0de0e94c4e39273b175eab134878b0dc1a6.tar.bz2
pygobject2-df54f0de0e94c4e39273b175eab134878b0dc1a6.zip
Imported Upstream version 3.19.2
Change-Id: I30002988caf9b0cc811bd5291d095817127a7eea Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/Makefile.in30
-rw-r--r--tests/test_error.py22
-rw-r--r--tests/test_gi.py74
-rw-r--r--tests/test_import_machinery.py13
-rw-r--r--tests/test_overrides_gdk.py6
-rw-r--r--tests/test_overrides_gtk.py1
-rw-r--r--tests/test_repository.py10
-rw-r--r--tests/test_resulttuple.py87
9 files changed, 220 insertions, 24 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b36ff51..9d5db5e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -116,6 +116,7 @@ EXTRA_DIST = \
test_generictreemodel.py \
test_docstring.py \
test_repository.py \
+ test_resulttuple.py \
compat_test_pygtk.py \
gi/__init__.py \
gi/overrides/__init__.py \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 0fc5f40..35f370f 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.15 from Makefile.am.
+# Makefile.in generated by automake 1.13.4 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -14,17 +14,7 @@
@SET_MAKE@
VPATH = @srcdir@
-am__is_gnu_make = { \
- if test -z '$(MAKELEVEL)'; then \
- false; \
- elif test -n '$(MAKE_HOST)'; then \
- true; \
- elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
- true; \
- else \
- false; \
- fi; \
-}
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
@@ -92,6 +82,8 @@ host_triplet = @host@
@ENABLE_CAIRO_TRUE@am__append_1 = libregress.la
@ENABLE_CAIRO_TRUE@am__append_2 = Regress-1.0.typelib
subdir = tests
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/depcomp
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 \
@@ -100,7 +92,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
$(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
-DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
@@ -196,7 +187,6 @@ am__define_uniq_tagged_files = \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
-am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
@@ -233,7 +223,6 @@ EXEEXT = @EXEEXT@
FFI_CFLAGS = @FFI_CFLAGS@
FFI_LIBS = @FFI_LIBS@
FGREP = @FGREP@
-GCOV = @GCOV@
GENHTML = @GENHTML@
GIO_CFLAGS = @GIO_CFLAGS@
GIO_LIBS = @GIO_LIBS@
@@ -357,7 +346,6 @@ program_transform_name = @program_transform_name@
psdir = @psdir@
pyexecdir = @pyexecdir@
pythondir = @pythondir@
-runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@@ -429,6 +417,7 @@ EXTRA_DIST = \
test_generictreemodel.py \
test_docstring.py \
test_repository.py \
+ test_resulttuple.py \
compat_test_pygtk.py \
gi/__init__.py \
gi/overrides/__init__.py \
@@ -462,6 +451,7 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign tests/Makefile
+.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
@@ -512,14 +502,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -782,8 +772,6 @@ uninstall-am:
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags tags-am uninstall uninstall-am
-.PRECIOUS: Makefile
-
# This is a hack to make sure a shared library is built
libgimarshallingtests.la: $(libgimarshallingtests_la_OBJECTS) $(libgimarshallingtests_la_DEPENDENCIES)
diff --git a/tests/test_error.py b/tests/test_error.py
index baccef5..f5a89ce 100644
--- a/tests/test_error.py
+++ b/tests/test_error.py
@@ -64,6 +64,14 @@ class TestType(unittest.TestCase):
self.assertTrue(issubclass(GLib.Error, RuntimeError))
+class ObjectWithVFuncException(GIMarshallingTests.Object):
+ def do_vfunc_meth_with_err(self, x):
+ if x == 42:
+ return True
+
+ raise GLib.Error('unexpected value %d' % x, 'mydomain', 42)
+
+
class TestMarshalling(unittest.TestCase):
def test_array_in_crash(self):
# Previously there was a bug in invoke, in which C arrays were unwrapped
@@ -111,6 +119,20 @@ class TestMarshalling(unittest.TestCase):
self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
+ def test_vfunc_no_exception(self):
+ obj = ObjectWithVFuncException()
+ self.assertTrue(obj.vfunc_meth_with_error(42))
+
+ def test_vfunc_gerror_exception(self):
+ obj = ObjectWithVFuncException()
+ with self.assertRaises(GLib.Error) as context:
+ obj.vfunc_meth_with_error(-1)
+
+ e = context.exception
+ self.assertEqual(e.message, 'unexpected value -1')
+ self.assertEqual(e.domain, 'mydomain')
+ self.assertEqual(e.code, 42)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 4cdd1a4..1fbc216 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1544,6 +1544,16 @@ class TestEnum(unittest.TestCase):
gi._gi.enum_add,
GIMarshallingTests.NoTypeFlags.__gtype__)
+ def test_type_module_name(self):
+ self.assertEqual(GIMarshallingTests.Enum.__name__, "Enum")
+ self.assertEqual(GIMarshallingTests.Enum.__module__,
+ "gi.repository.GIMarshallingTests")
+
+ def test_repr(self):
+ self.assertEqual(repr(GIMarshallingTests.Enum.VALUE3),
+ "<enum GI_MARSHALLING_TESTS_ENUM_VALUE3 of type "
+ "GIMarshallingTests.Enum>")
+
class TestEnumVFuncResults(unittest.TestCase):
class EnumTester(GIMarshallingTests.Object):
@@ -1604,6 +1614,16 @@ class TestGEnum(unittest.TestCase):
self.assertTrue(isinstance(genum, GIMarshallingTests.GEnum))
self.assertEqual(genum, GIMarshallingTests.GEnum.VALUE1)
+ def test_type_module_name(self):
+ self.assertEqual(GIMarshallingTests.GEnum.__name__, "GEnum")
+ self.assertEqual(GIMarshallingTests.GEnum.__module__,
+ "gi.repository.GIMarshallingTests")
+
+ def test_repr(self):
+ self.assertEqual(repr(GIMarshallingTests.GEnum.VALUE3),
+ "<enum GI_MARSHALLING_TESTS_GENUM_VALUE3 of type "
+ "GIMarshallingTests.GEnum>")
+
class TestGFlags(unittest.TestCase):
@@ -1657,6 +1677,16 @@ class TestGFlags(unittest.TestCase):
self.assertTrue(isinstance(flags, GIMarshallingTests.Flags))
self.assertEqual(flags, GIMarshallingTests.Flags.VALUE1)
+ def test_type_module_name(self):
+ self.assertEqual(GIMarshallingTests.Flags.__name__, "Flags")
+ self.assertEqual(GIMarshallingTests.Flags.__module__,
+ "gi.repository.GIMarshallingTests")
+
+ def test_repr(self):
+ self.assertEqual(repr(GIMarshallingTests.Flags.VALUE2),
+ "<flags GI_MARSHALLING_TESTS_FLAGS_VALUE2 of type "
+ "GIMarshallingTests.Flags>")
+
class TestNoTypeFlags(unittest.TestCase):
@@ -1706,6 +1736,17 @@ class TestNoTypeFlags(unittest.TestCase):
self.assertEqual(GIMarshallingTests.NoTypeFlags.__gtype__.name,
'PyGIMarshallingTestsNoTypeFlags')
+ def test_type_module_name(self):
+ self.assertEqual(GIMarshallingTests.NoTypeFlags.__name__,
+ "NoTypeFlags")
+ self.assertEqual(GIMarshallingTests.NoTypeFlags.__module__,
+ "gi.repository.GIMarshallingTests")
+
+ def test_repr(self):
+ self.assertEqual(repr(GIMarshallingTests.NoTypeFlags.VALUE2),
+ "<flags GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2 of "
+ "type GIMarshallingTests.NoTypeFlags>")
+
class TestStructure(unittest.TestCase):
@@ -1930,6 +1971,27 @@ class TestStructure(unittest.TestCase):
self.assertRaises(TypeError, GIMarshallingTests.Union.method)
+ def test_repr(self):
+ self.assertRegexpMatches(
+ repr(GIMarshallingTests.PointerStruct()),
+ "<GIMarshallingTests.PointerStruct object at 0x[^\s]+ "
+ "\(void at 0x[^\s]+\)>")
+
+ self.assertRegexpMatches(
+ repr(GIMarshallingTests.SimpleStruct()),
+ "<GIMarshallingTests.SimpleStruct object at 0x[^\s]+ "
+ "\(void at 0x[^\s]+\)>")
+
+ self.assertRegexpMatches(
+ repr(GIMarshallingTests.Union()),
+ "<GIMarshallingTests.Union object at 0x[^\s]+ "
+ "\(GIMarshallingTestsUnion at 0x[^\s]+\)>")
+
+ self.assertRegexpMatches(
+ repr(GIMarshallingTests.BoxedStruct()),
+ "<GIMarshallingTests.BoxedStruct object at 0x[^\s]+ "
+ "\(GIMarshallingTestsBoxedStruct at 0x[^\s]+\)>")
+
class TestGObject(unittest.TestCase):
@@ -2060,6 +2122,18 @@ class TestGObject(unittest.TestCase):
self.assertEqual(object_.__grefcount__, 1)
self.assertEqual(new_object.__grefcount__, 1)
+ def test_repr(self):
+ self.assertRegexpMatches(
+ repr(GIMarshallingTests.Object(int=42)),
+ "<GIMarshallingTests.Object object at 0x[^\s]+ "
+ "\(GIMarshallingTestsObject at 0x[^\s]+\)>")
+
+ def test_nongir_repr(self):
+ self.assertRegexpMatches(
+ repr(Gio.File.new_for_path("")),
+ "<__gi__.GLocalFile object at 0x[^\s]+ "
+ "\(GLocalFile at 0x[^\s]+\)>")
+
# FIXME: Doesn't actually return the same object.
# def test_object_inout_same(self):
# object_ = GIMarshallingTests.Object()
diff --git a/tests/test_import_machinery.py b/tests/test_import_machinery.py
index de9f1e9..e1432b1 100644
--- a/tests/test_import_machinery.py
+++ b/tests/test_import_machinery.py
@@ -77,6 +77,19 @@ class TestModule(unittest.TestCase):
# Restore the previous cache
gi.module._introspection_modules = old_modules
+ def test_module_dependency_loading(self):
+ # Difficult to because this generally need to run in isolation to make
+ # sure GIMarshallingTests has not yet been loaded. But we can do this with:
+ # make check TEST_NAMES=test_import_machinery.TestModule.test_module_dependency_loading
+ if 'gi.repository.Gio' in sys.modules:
+ return
+
+ from gi.repository import GIMarshallingTests
+ GIMarshallingTests # PyFlakes
+
+ self.assertIn('gi.repository.Gio', sys.modules)
+ self.assertIn('gi.repository.GIMarshallingTests', sys.modules)
+
def test_static_binding_protection(self):
# Importing old static bindings once gi has been imported should not
# crash but instead give back a dummy module which produces RuntimeErrors
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
index 9559a09..a0ffac4 100644
--- a/tests/test_overrides_gdk.py
+++ b/tests/test_overrides_gdk.py
@@ -157,16 +157,16 @@ class TestGdk(unittest.TestCase):
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>')
+ '<flags GDK_META_MASK of type Gdk.ModifierType>')
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>')
+ '<flags GDK_RELEASE_MASK of type Gdk.ModifierType>')
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>')
+ '<flags GDK_META_MASK | GDK_RELEASE_MASK of type Gdk.ModifierType>')
def test_color_parse(self):
with capture_glib_deprecation_warnings():
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 44f2f6e..9aa592c 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -692,6 +692,7 @@ class TestSignals(unittest.TestCase):
with realized(win):
win.show()
+ win.get_preferred_size()
win.size_allocate(rect)
self.assertTrue(win._alloc_called)
self.assertIsInstance(win._alloc_value, Gdk.Rectangle)
diff --git a/tests/test_repository.py b/tests/test_repository.py
index 4c83acd..f59f86b 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -74,6 +74,16 @@ class Test(unittest.TestCase):
self.assertFalse(repo.is_registered("GIRepository", "99.0"))
self.assertFalse(repo.is_registered("GIRepository", "1.0"))
+ def test_repo_get_immediate_dependencies(self):
+ self.assertRaises(TypeError, repo.get_immediate_dependencies)
+ self.assertEqual(repo.get_immediate_dependencies("GLib"), [])
+ self.assertEqual(
+ repo.get_immediate_dependencies("GObject"), ["GLib-2.0"])
+ self.assertEqual(
+ repo.get_immediate_dependencies(namespace="GObject"), ["GLib-2.0"])
+ self.assertEqual(
+ repo.get_immediate_dependencies("GIMarshallingTests"), ["Gio-2.0"])
+
def test_arg_info(self):
func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct')
args = func_info.get_arguments()
diff --git a/tests/test_resulttuple.py b/tests/test_resulttuple.py
new file mode 100644
index 0000000..20f80f3
--- /dev/null
+++ b/tests/test_resulttuple.py
@@ -0,0 +1,87 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2015 Christoph Reiter <reiter.christoph@gmail.com>
+#
+# 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
+import pickle
+
+import gi
+from gi.repository import GIMarshallingTests
+from gi.repository import Regress
+
+
+ResultTuple = gi._gi.ResultTuple
+
+
+class TestResultTuple(unittest.TestCase):
+
+ def test_base(self):
+ self.assertTrue(issubclass(ResultTuple, tuple))
+
+ def test_create(self):
+ new = ResultTuple._new_type([None, "foo", None, "bar"])
+ self.assertTrue(issubclass(new, ResultTuple))
+
+ def test_repr_dir(self):
+ new = ResultTuple._new_type([None, "foo", None, "bar"])
+ inst = new([1, 2, 3, "a"])
+
+ self.assertEqual(repr(inst), "(1, foo=2, 3, bar='a')")
+ self.assertTrue("foo" in dir(inst))
+
+ def test_repr_dir_empty(self):
+ new = ResultTuple._new_type([])
+ inst = new()
+ self.assertEqual(repr(inst), "()")
+ dir(inst)
+
+ def test_getatttr(self):
+ new = ResultTuple._new_type([None, "foo", None, "bar"])
+ inst = new([1, 2, 3, "a"])
+
+ self.assertTrue(hasattr(inst, "foo"))
+ self.assertEqual(inst.foo, inst[1])
+ self.assertRaises(AttributeError, getattr, inst, "nope")
+
+ def test_pickle(self):
+ new = ResultTuple._new_type([None, "foo", None, "bar"])
+ inst = new([1, 2, 3, "a"])
+
+ inst2 = pickle.loads(pickle.dumps(inst))
+ self.assertEqual(inst2, inst)
+ self.assertTrue(isinstance(inst2, tuple))
+ self.assertFalse(isinstance(inst2, new))
+
+ def test_gi(self):
+ res = GIMarshallingTests.init_function([])
+ self.assertEqual(repr(res), "(True, argv=[])")
+
+ res = GIMarshallingTests.array_return_etc(5, 9)
+ self.assertEqual(repr(res), "([5, 0, 1, 9], sum=14)")
+
+ res = GIMarshallingTests.array_out_etc(-5, 9)
+ self.assertEqual(repr(res), "(ints=[-5, 0, 1, 9], sum=4)")
+
+ cb = lambda: (1, 2)
+ res = GIMarshallingTests.callback_multiple_out_parameters(cb)
+ self.assertEqual(repr(res), "(a=1.0, b=2.0)")
+
+ def test_regress(self):
+ res = Regress.TestObj().skip_return_val(50, 42.0, 60, 2, 3)
+ self.assertEqual(repr(res), "(out_b=51, inout_d=61, out_sum=32)")