Commit f4acd6a9 authored by Simon Feltman's avatar Simon Feltman
Browse files

Make unitests for gobject functions moving to gi more strict

Add expected failure test for invalid SystemError's coming from
signal_lookup and signal_list_ids. Remove excessive type_name
tests and type_from_name tests.

https://bugzilla.gnome.org/show_bug.cgi?id=687487
parent 32678083
......@@ -2,7 +2,6 @@ import unittest
from gi.repository import GObject
from gi.repository import GIMarshallingTests
from gi._gobject import _gobject # pull in the python DSO directly
class CustomBase(GObject.GObject):
......@@ -16,60 +15,8 @@ class CustomChild(CustomBase, GIMarshallingTests.Interface):
class TestTypeModuleLevelFunctions(unittest.TestCase):
def test_type_name(self):
self.assertEqual(GObject.type_name(GObject.TYPE_NONE), 'void')
self.assertEqual(GObject.type_name(GObject.TYPE_INTERFACE), 'GInterface')
self.assertEqual(GObject.type_name(GObject.TYPE_CHAR), 'gchar')
self.assertEqual(GObject.type_name(GObject.TYPE_UCHAR), 'guchar')
self.assertEqual(GObject.type_name(GObject.TYPE_BOOLEAN), 'gboolean')
self.assertEqual(GObject.type_name(GObject.TYPE_INT), 'gint')
self.assertEqual(GObject.type_name(GObject.TYPE_UINT), 'guint')
self.assertEqual(GObject.type_name(GObject.TYPE_LONG), 'glong')
self.assertEqual(GObject.type_name(GObject.TYPE_ULONG), 'gulong')
self.assertEqual(GObject.type_name(GObject.TYPE_INT64), 'gint64')
self.assertEqual(GObject.type_name(GObject.TYPE_UINT64), 'guint64')
self.assertEqual(GObject.type_name(GObject.TYPE_ENUM), 'GEnum')
self.assertEqual(GObject.type_name(GObject.TYPE_FLAGS), 'GFlags')
self.assertEqual(GObject.type_name(GObject.TYPE_FLOAT), 'gfloat')
self.assertEqual(GObject.type_name(GObject.TYPE_DOUBLE), 'gdouble')
self.assertEqual(GObject.type_name(GObject.TYPE_STRING), 'gchararray')
self.assertEqual(GObject.type_name(GObject.TYPE_POINTER), 'gpointer')
self.assertEqual(GObject.type_name(GObject.TYPE_BOXED), 'GBoxed')
self.assertEqual(GObject.type_name(GObject.TYPE_PARAM), 'GParam')
self.assertEqual(GObject.type_name(GObject.TYPE_OBJECT), 'GObject')
self.assertEqual(GObject.type_name(GObject.TYPE_PYOBJECT), 'PyObject')
self.assertEqual(GObject.type_name(GObject.TYPE_GTYPE), 'GType')
self.assertEqual(GObject.type_name(GObject.TYPE_STRV), 'GStrv')
self.assertEqual(GObject.type_name(GObject.TYPE_VARIANT), 'GVariant')
self.assertEqual(GObject.type_name(GObject.TYPE_UNICHAR), 'guint')
def test_gi_types_equal_static_type_from_name(self):
# Note this test should be changed to use GObject.type_from_name
# if the _gobject.type_from_name binding is ever removed.
self.assertEqual(GObject.TYPE_NONE, _gobject.type_from_name('void'))
self.assertEqual(GObject.TYPE_INTERFACE, _gobject.type_from_name('GInterface'))
self.assertEqual(GObject.TYPE_CHAR, _gobject.type_from_name('gchar'))
self.assertEqual(GObject.TYPE_UCHAR, _gobject.type_from_name('guchar'))
self.assertEqual(GObject.TYPE_BOOLEAN, _gobject.type_from_name('gboolean'))
self.assertEqual(GObject.TYPE_INT, _gobject.type_from_name('gint'))
self.assertEqual(GObject.TYPE_UINT, _gobject.type_from_name('guint'))
self.assertEqual(GObject.TYPE_LONG, _gobject.type_from_name('glong'))
self.assertEqual(GObject.TYPE_ULONG, _gobject.type_from_name('gulong'))
self.assertEqual(GObject.TYPE_INT64, _gobject.type_from_name('gint64'))
self.assertEqual(GObject.TYPE_UINT64, _gobject.type_from_name('guint64'))
self.assertEqual(GObject.TYPE_ENUM, _gobject.type_from_name('GEnum'))
self.assertEqual(GObject.TYPE_FLAGS, _gobject.type_from_name('GFlags'))
self.assertEqual(GObject.TYPE_FLOAT, _gobject.type_from_name('gfloat'))
self.assertEqual(GObject.TYPE_DOUBLE, _gobject.type_from_name('gdouble'))
self.assertEqual(GObject.TYPE_STRING, _gobject.type_from_name('gchararray'))
self.assertEqual(GObject.TYPE_POINTER, _gobject.type_from_name('gpointer'))
self.assertEqual(GObject.TYPE_BOXED, _gobject.type_from_name('GBoxed'))
self.assertEqual(GObject.TYPE_PARAM, _gobject.type_from_name('GParam'))
self.assertEqual(GObject.TYPE_OBJECT, _gobject.type_from_name('GObject'))
self.assertEqual(GObject.TYPE_PYOBJECT, _gobject.type_from_name('PyObject'))
self.assertEqual(GObject.TYPE_GTYPE, _gobject.type_from_name('GType'))
self.assertEqual(GObject.TYPE_STRV, _gobject.type_from_name('GStrv'))
self.assertEqual(GObject.TYPE_VARIANT, _gobject.type_from_name('GVariant'))
self.assertEqual(GObject.TYPE_UNICHAR, _gobject.type_from_name('guint'))
def test_type_from_name(self):
# A complete test is not needed here since the TYPE_* defines are created
......
......@@ -735,26 +735,35 @@ class TestPython3Signals(unittest.TestCase):
class TestSignalModuleLevelFunctions(unittest.TestCase):
@unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=687492
def test_signal_list_ids_with_invalid_type(self):
self.assertRaises(TypeError, GObject.signal_list_ids, GObject.TYPE_INVALID)
@unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_list_ids(self):
# This should not raise a SystemError:
# https://bugzilla.gnome.org/show_bug.cgi?id=687492
self.assertRaises(SystemError, GObject.signal_list_ids, GObject.TYPE_INVALID)
with self.assertRaisesRegexp(TypeError, 'type must be instantiable or an interface.*'):
GObject.signal_list_ids(GObject.TYPE_INT)
C_ids = GObject.signal_list_ids(C)
self.assertEqual(len(C_ids), 1)
ids = GObject.signal_list_ids(C)
self.assertEqual(len(ids), 1)
# Note canonicalized names
self.assertEqual(GObject.signal_name(C_ids[0]), 'my-signal')
self.assertEqual(GObject.signal_name(-1), None)
self.assertEqual(GObject.signal_name(ids[0]), 'my-signal')
# There is no signal 0 in gobject
self.assertEqual(GObject.signal_name(0), None)
@unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=687492
def test_signal_lookup_with_invalid_type(self):
self.assertRaises(TypeError, GObject.signal_lookup,
'NOT_A_SIGNAL_NAME', GObject.TYPE_INVALID)
@unittest.skipIf(sys.version_info < (2, 7), 'Requires Python >= 2.7')
def test_signal_lookup(self):
C_ids = GObject.signal_list_ids(C)
self.assertEqual(C_ids[0], GObject.signal_lookup('my_signal', C))
self.assertEqual(C_ids[0], GObject.signal_lookup('my-signal', C))
ids = GObject.signal_list_ids(C)
self.assertEqual(ids[0], GObject.signal_lookup('my_signal', C))
self.assertEqual(ids[0], GObject.signal_lookup('my-signal', C))
# This should not raise a SystemError:
# https://bugzilla.gnome.org/show_bug.cgi?id=687492
self.assertRaises(SystemError, GObject.signal_lookup,
'NOT_A_SIGNAL_NAME', GObject.TYPE_INVALID)
with self.assertRaisesRegexp(TypeError, 'type must be instantiable or an interface.*'):
GObject.signal_lookup('NOT_A_SIGNAL_NAME', GObject.TYPE_INT)
# Invalid signal names return 0 instead of raising
self.assertEqual(GObject.signal_lookup('NOT_A_SIGNAL_NAME', C),
......@@ -769,10 +778,11 @@ class TestSignalModuleLevelFunctions(unittest.TestCase):
# signal_query(name, type)
self.assertSequenceEqual(GObject.signal_query('my-signal', C),
my_signal_expected_query_result)
# signal_query(signal_id)
self.assertSequenceEqual(GObject.signal_query(my_signal_id),
my_signal_expected_query_result)
# invalid query returns None instead of raising
self.assertEqual(GObject.signal_query(-1), None)
self.assertEqual(GObject.signal_query(0), None)
self.assertEqual(GObject.signal_query('NOT_A_SIGNAL', C),
None)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment