[pygobject] refactor tests to only use PyGObject 3 syntax



commit b8700451acd4a19b59b64fc8641fca748d2189e2
Author: John (J5) Palmieri <johnp redhat com>
Date:   Fri Jul 22 11:20:09 2011 -0400

    refactor tests to only use PyGObject 3 syntax
    
    * for PyGObject 3 we want to discourage the use of legacy
       interfaces
     * Using interfaces like from gi.repository import GObject makes
       sure that the internal _gobject module is loaded and not
       PyGObject 2's gobject module which would cause the application
       to not work correctly
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642048

 tests/runtests-windows.py |    4 +-
 tests/test_gdbus.py       |   12 ++--
 tests/test_gi.py          |    4 +-
 tests/test_gobject.py     |   31 ++++++------
 tests/test_interface.py   |   16 +++---
 tests/test_mainloop.py    |    3 +-
 tests/test_overrides.py   |    8 ++--
 tests/test_properties.py  |  124 ++++++++++++++++++++++----------------------
 tests/test_signal.py      |   98 ++++++++++++++++++------------------
 tests/test_source.py      |    5 +-
 tests/test_subprocess.py  |    3 +-
 tests/test_thread.py      |    5 +-
 tests/test_unknown.py     |    8 ++--
 tests/testhelpermodule.c  |    2 +-
 tests/testmodule.py       |   10 ++--
 15 files changed, 169 insertions(+), 164 deletions(-)
---
diff --git a/tests/runtests-windows.py b/tests/runtests-windows.py
index 6915a3c..ae81202 100644
--- a/tests/runtests-windows.py
+++ b/tests/runtests-windows.py
@@ -11,8 +11,8 @@ os.environ['PYGTK_USE_GIL_STATE_API'] = ''
 sys.path.insert(0, os.path.dirname(__file__))
 sys.argv.append('--g-fatal-warnings')
 
-import gobject
-gobject.threads_init()
+from gi.repository import GObject
+GObject.threads_init()
 
 
 SKIP_FILES = ['runtests',
diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py
index b5a8493..5db5d93 100644
--- a/tests/test_gdbus.py
+++ b/tests/test_gdbus.py
@@ -6,7 +6,7 @@ import unittest
 import sys
 sys.path.insert(0, "../")
 
-import gobject
+from gi.repository import GObject
 from gi.repository import GLib
 from gi.repository import Gio
 
@@ -67,7 +67,7 @@ class TestGDBusClient(unittest.TestCase):
             finally:
                 user_data['main_loop'].quit()
 
-        main_loop = gobject.MainLoop()
+        main_loop = GObject.MainLoop()
         data = {'main_loop': main_loop}
         self.dbus_proxy.call('ListNames', None, 
                 Gio.DBusCallFlags.NO_AUTO_START, 500, None,
@@ -89,7 +89,7 @@ class TestGDBusClient(unittest.TestCase):
             finally:
                 user_data['main_loop'].quit()
 
-        main_loop = gobject.MainLoop()
+        main_loop = GObject.MainLoop()
         data = {'main_loop': main_loop}
         self.dbus_proxy.call('UnknownMethod', None,
                 Gio.DBusCallFlags.NO_AUTO_START, 500, None, call_done, data)
@@ -159,7 +159,7 @@ class TestGDBusClient(unittest.TestCase):
             user_data['result'] = result
             user_data['main_loop'].quit()
 
-        main_loop = gobject.MainLoop()
+        main_loop = GObject.MainLoop()
         data = {'main_loop': main_loop}
         self.dbus_proxy.ListNames('()', result_handler=call_done,
                 user_data=data)
@@ -176,7 +176,7 @@ class TestGDBusClient(unittest.TestCase):
             user_data['result'] = result
             user_data['main_loop'].quit()
 
-        main_loop = gobject.MainLoop()
+        main_loop = GObject.MainLoop()
         data = {'main_loop': main_loop}
         self.dbus_proxy.ListNames('(s)', 'invalid_argument',
                 result_handler=call_done, user_data=data)
@@ -195,7 +195,7 @@ class TestGDBusClient(unittest.TestCase):
             user_data['error'] = error
             user_data['main_loop'].quit()
 
-        main_loop = gobject.MainLoop()
+        main_loop = GObject.MainLoop()
         data = {'main_loop': main_loop}
         self.dbus_proxy.ListNames('(s)', 'invalid_argument',
                 result_handler=call_done, error_handler=call_error,
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 0436a6e..e2822a9 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,7 +12,6 @@ import locale
 import subprocess
 from gi.repository import GObject
 
-import gobject
 from gi.repository import GIMarshallingTests
 
 from compathelper import _bytes
@@ -1587,7 +1586,8 @@ class TestPythonGObject(unittest.TestCase):
         # compare the same enum from both the pygobject attrs and gi GObject attrs
         self.assertEquals(GObject.SIGNAL_ACTION, GObject.SignalFlags.ACTION)
         # compare a static gobject attr with a dynamic GObject attr
-        self.assertEquals(GObject.GObject, gobject.GObject)
+        import gi._gobject
+        self.assertEquals(GObject.GObject, gi._gobject.GObject)
 
     def test_subobject_non_vfunc_do_method(self):
         class PythonObjectWithNonVFuncDoMethod:
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index d628b0e..dbbc5b7 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -2,38 +2,39 @@
 
 import unittest
 
-import gobject
+from gi.repository import GObject
 import sys
 import testhelper
 
 
 class TestGObjectAPI(unittest.TestCase):
     def testGObjectModule(self):
-        obj = gobject.GObject()
+        obj = GObject.GObject()
+
         self.assertEquals(obj.__module__,
-                          'gobject._gobject')
+                          'gi._gobject._gobject')
 
 
 class TestReferenceCounting(unittest.TestCase):
     def testRegularObject(self):
-        obj = gobject.GObject()
+        obj = GObject.GObject()
         self.assertEquals(obj.__grefcount__, 1)
 
-        obj = gobject.new(gobject.GObject)
+        obj = GObject.new(GObject.GObject)
         self.assertEquals(obj.__grefcount__, 1)
 
     def testFloatingWithSinkFunc(self):
         obj = testhelper.FloatingWithSinkFunc()
         self.assertEquals(obj.__grefcount__, 1)
 
-        obj = gobject.new(testhelper.FloatingWithSinkFunc)
+        obj = GObject.new(testhelper.FloatingWithSinkFunc)
         self.assertEquals(obj.__grefcount__, 1)
 
     def testFloatingWithoutSinkFunc(self):
         obj = testhelper.FloatingWithoutSinkFunc()
         self.assertEquals(obj.__grefcount__, 1)
 
-        obj = gobject.new(testhelper.FloatingWithoutSinkFunc)
+        obj = GObject.new(testhelper.FloatingWithoutSinkFunc)
         self.assertEquals(obj.__grefcount__, 1)
 
     def testOwnedByLibrary(self):
@@ -71,7 +72,7 @@ class TestReferenceCounting(unittest.TestCase):
         # Upon creation, the refcount of the object should be 2:
         # - someone already has a reference on the new object.
         # - the python wrapper should hold its own reference.
-        obj = gobject.new(testhelper.OwnedByLibrary)
+        obj = GObject.new(testhelper.OwnedByLibrary)
         self.assertEquals(obj.__grefcount__, 2)
 
         # We ask the library to release its reference, so the only
@@ -81,7 +82,7 @@ class TestReferenceCounting(unittest.TestCase):
         self.assertEquals(obj.__grefcount__, 1)
 
     def testOwnedByLibraryOutOfScopeUsingGobjectNew(self):
-        obj = gobject.new(testhelper.OwnedByLibrary)
+        obj = GObject.new(testhelper.OwnedByLibrary)
         self.assertEquals(obj.__grefcount__, 2)
 
         # We are manually taking the object out of scope. This means
@@ -134,7 +135,7 @@ class TestReferenceCounting(unittest.TestCase):
         # Upon creation, the refcount of the object should be 2:
         # - someone already has a reference on the new object.
         # - the python wrapper should hold its own reference.
-        obj = gobject.new(testhelper.FloatingAndSunk)
+        obj = GObject.new(testhelper.FloatingAndSunk)
         self.assertEquals(obj.__grefcount__, 2)
 
         # We ask the library to release its reference, so the only
@@ -144,7 +145,7 @@ class TestReferenceCounting(unittest.TestCase):
         self.assertEquals(obj.__grefcount__, 1)
 
     def testFloatingAndSunkOutOfScopeUsingGObjectNew(self):
-        obj = gobject.new(testhelper.FloatingAndSunk)
+        obj = GObject.new(testhelper.FloatingAndSunk)
         self.assertEquals(obj.__grefcount__, 2)
 
         # We are manually taking the object out of scope. This means
@@ -161,7 +162,7 @@ class TestReferenceCounting(unittest.TestCase):
         obj.release()
         self.assertEquals(obj.__grefcount__, 1)
 
-class A(gobject.GObject):
+class A(GObject.GObject):
     def __init__(self):
         super(A, self).__init__()
 
@@ -170,11 +171,11 @@ class TestPythonReferenceCounting(unittest.TestCase):
     # the GC, and one for the bound variable in the local scope.
 
     def testNewInstanceHasTwoRefs(self):
-        obj = gobject.GObject()
+        obj = GObject.GObject()
         self.assertEquals(sys.getrefcount(obj), 2)
 
     def testNewInstanceHasTwoRefsUsingGObjectNew(self):
-        obj = gobject.new(gobject.GObject)
+        obj = GObject.new(GObject.GObject)
         self.assertEquals(sys.getrefcount(obj), 2)
 
     def testNewSubclassInstanceHasTwoRefs(self):
@@ -182,5 +183,5 @@ class TestPythonReferenceCounting(unittest.TestCase):
         self.assertEquals(sys.getrefcount(obj), 2)
 
     def testNewSubclassInstanceHasTwoRefsUsingGObjectNew(self):
-        obj = gobject.new(A)
+        obj = GObject.new(A)
         self.assertEquals(sys.getrefcount(obj), 2)
diff --git a/tests/test_interface.py b/tests/test_interface.py
index fbc0586..7893c85 100644
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -2,16 +2,16 @@
 
 import unittest
 
-import gobject
+from gi.repository import GObject
 import testhelper
 
 
-GUnknown = gobject.type_from_name("TestUnknown")
+GUnknown = GObject.type_from_name("TestUnknown")
 Unknown = GUnknown.pytype
 
 
 class MyUnknown(Unknown, testhelper.Interface):
-    some_property = gobject.property(type=str)
+    some_property = GObject.property(type=str)
 
     def __init__(self):
         Unknown.__init__(self)
@@ -20,19 +20,19 @@ class MyUnknown(Unknown, testhelper.Interface):
     def do_iface_method(self):
         self.called = True
         Unknown.do_iface_method(self)
-gobject.type_register(MyUnknown)
+GObject.type_register(MyUnknown)
 
 
-class MyObject(gobject.GObject, testhelper.Interface):
-    some_property = gobject.property(type=str)
+class MyObject(GObject.GObject, testhelper.Interface):
+    some_property = GObject.property(type=str)
 
     def __init__(self):
-        gobject.GObject.__init__(self)
+        GObject.GObject.__init__(self)
         self.called = False
 
     def do_iface_method(self):
         self.called = True
-gobject.type_register(MyObject)
+GObject.type_register(MyObject)
 
 
 class TestIfaceImpl(unittest.TestCase):
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 80e2aec..9ca5727 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -6,6 +6,7 @@ import select
 import unittest
 
 import glib
+from gi.repository import GObject
 
 from compathelper import _bytes
 
@@ -24,7 +25,7 @@ class TestMainLoop(unittest.TestCase):
             loop.quit()
             raise Exception("deadbabe")
 
-        loop = glib.MainLoop()
+        loop = GObject.MainLoop()
         glib.child_watch_add(pid, child_died, loop)
 
         os.close(pipe_r)
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 3e46b33..d6b09bd 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -534,8 +534,8 @@ class TestGtk(unittest.TestCase):
         class SignalTest(GObject.GObject):
             __gtype_name__ = "GIOverrideSignalTest"
             __gsignals__ = {
-                "test-signal": (GObject.SIGNAL_RUN_FIRST,
-                                GObject.TYPE_NONE,
+                "test-signal": (GObject.SignalFlags.RUN_FIRST,
+                                None,
                                 []),
             }
 
@@ -1293,7 +1293,7 @@ class TestGtk(unittest.TestCase):
         self.assertEquals('Hello World', text)
 
     def test_label(self):
-        label = Gtk.Label('Hello')
+        label = Gtk.Label(label='Hello')
         self.assertEquals(label.get_text(), 'Hello')
 
     def adjustment_check(self, adjustment, value=0.0, lower=0.0, upper=0.0,
@@ -1344,7 +1344,7 @@ class TestGtk(unittest.TestCase):
         self.assertEquals(table.get_size(), (2,3))
         self.assertEquals(table.get_homogeneous(), True)
 
-        label = Gtk.Label('Hello')
+        label = Gtk.Label(label='Hello')
         table.attach(label, 0, 1, 0, 1)
         self.assertEquals(label, table.get_children()[0])
 
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 3930671..d02dac9 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -4,13 +4,13 @@ import sys
 import struct
 import unittest
 
-import gobject
-from gobject import GObject, GType, GEnum, new, PARAM_READWRITE, \
+from gi.repository import GObject
+from  gi.repository.GObject import GType, GEnum, new, PARAM_READWRITE, \
      PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY
-from gobject.constants import \
+from gi.repository.GObject import \
      TYPE_INT, TYPE_UINT, TYPE_LONG, \
      TYPE_ULONG, TYPE_INT64, TYPE_UINT64
-from gobject.constants import \
+from gi.repository.GObject import \
      G_MININT, G_MAXINT, G_MAXUINT, G_MINLONG, G_MAXLONG, \
      G_MAXULONG
 
@@ -25,18 +25,18 @@ else:
 
 from compathelper import _long
 
-class PropertyObject(GObject):
-    normal = gobject.property(type=str)
-    construct = gobject.property(
+class PropertyObject(GObject.GObject):
+    normal = GObject.property(type=str)
+    construct = GObject.property(
         type=str,
         flags=PARAM_READWRITE|PARAM_CONSTRUCT, default='default')
-    construct_only = gobject.property(
+    construct_only = GObject.property(
         type=str,
         flags=PARAM_READWRITE|PARAM_CONSTRUCT_ONLY)
-    uint64 = gobject.property(
+    uint64 = GObject.property(
         type=TYPE_UINT64, flags=PARAM_READWRITE|PARAM_CONSTRUCT)
 
-    enum = gobject.property(
+    enum = GObject.property(
         type=Gio.SocketType, default=Gio.SocketType.STREAM)
 
 class TestProperties(unittest.TestCase):
@@ -123,7 +123,7 @@ class TestProperties(unittest.TestCase):
 
     def testUInt64DefaultValue(self):
         try:
-            class TimeControl(GObject):
+            class TimeControl(GObject.GObject):
                 __gproperties__ = {
                     'time': (TYPE_UINT64, 'Time', 'Time',
                              _long(0), (1<<64) - 1, _long(0),
@@ -153,12 +153,12 @@ class TestProperties(unittest.TestCase):
         self.assertRaises(TypeError, setattr, obj, 'enum', 'foo')
         self.assertRaises(TypeError, setattr, obj, 'enum', object())
 
-        self.assertRaises(TypeError, gobject.property, type=Gio.SocketType)
-        self.assertRaises(TypeError, gobject.property, type=Gio.SocketType,
+        self.assertRaises(TypeError, GObject.property, type=Gio.SocketType)
+        self.assertRaises(TypeError, GObject.property, type=Gio.SocketType,
                           default=Gio.SocketProtocol.TCP)
-        self.assertRaises(TypeError, gobject.property, type=Gio.SocketType,
+        self.assertRaises(TypeError, GObject.property, type=Gio.SocketType,
                           default=object())
-        self.assertRaises(TypeError, gobject.property, type=Gio.SocketType,
+        self.assertRaises(TypeError, GObject.property, type=Gio.SocketType,
                           default=1)
 
     def testRange(self):
@@ -192,12 +192,12 @@ class TestProperties(unittest.TestCase):
                           PARAM_READABLE | PARAM_WRITABLE)
             return d
 
-        class RangeCheck(GObject):
+        class RangeCheck(GObject.GObject):
             __gproperties__ = build_gproperties(types)
 
             def __init__(self):
                 self.values = {}
-                GObject.__init__(self)
+                GObject.GObject.__init__(self)
 
             def do_set_property(self, pspec, value):
                 self.values[pspec.name] = value
@@ -240,11 +240,11 @@ class TestProperties(unittest.TestCase):
 
 class TestProperty(unittest.TestCase):
     def testSimple(self):
-        class C(gobject.GObject):
-            str = gobject.property(type=str)
-            int = gobject.property(type=int)
-            float = gobject.property(type=float)
-            long = gobject.property(type=_long)
+        class C(GObject.GObject):
+            str = GObject.property(type=str)
+            int = GObject.property(type=int)
+            float = GObject.property(type=float)
+            long = GObject.property(type=_long)
 
         self.failUnless(hasattr(C.props, 'str'))
         self.failUnless(hasattr(C.props, 'int'))
@@ -269,24 +269,24 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(o.long, _long(100))
 
     def testCustomGetter(self):
-        class C(gobject.GObject):
+        class C(GObject.GObject):
             def get_prop(self):
                 return 'value'
-            prop = gobject.property(getter=get_prop)
+            prop = GObject.property(getter=get_prop)
 
         o = C()
         self.assertEqual(o.prop, 'value')
         self.assertRaises(TypeError, setattr, o, 'prop', 'xxx')
 
     def testCustomSetter(self):
-        class C(gobject.GObject):
+        class C(GObject.GObject):
             def set_prop(self, value):
                 self._value = value
-            prop = gobject.property(setter=set_prop)
+            prop = GObject.property(setter=set_prop)
 
             def __init__(self):
                 self._value = None
-                gobject.GObject.__init__(self)
+                GObject.GObject.__init__(self)
 
         o = C()
         self.assertEquals(o._value, None)
@@ -295,26 +295,26 @@ class TestProperty(unittest.TestCase):
         self.assertRaises(TypeError, getattr, o, 'prop')
 
     def testErrors(self):
-        self.assertRaises(TypeError, gobject.property, type='str')
-        self.assertRaises(TypeError, gobject.property, nick=False)
-        self.assertRaises(TypeError, gobject.property, blurb=False)
+        self.assertRaises(TypeError, GObject.property, type='str')
+        self.assertRaises(TypeError, GObject.property, nick=False)
+        self.assertRaises(TypeError, GObject.property, blurb=False)
         # this never fail while bool is a subclass of int
         # >>> bool.__bases__
         # (<type 'int'>,)
-        # self.assertRaises(TypeError, gobject.property, type=bool, default=0)
-        self.assertRaises(TypeError, gobject.property, type=bool, default='ciao mamma')
-        self.assertRaises(TypeError, gobject.property, type=bool)
-        self.assertRaises(TypeError, gobject.property, type=object, default=0)
-        self.assertRaises(TypeError, gobject.property, type=complex)
-        self.assertRaises(TypeError, gobject.property, flags=-10)
+        # self.assertRaises(TypeError, GObject.property, type=bool, default=0)
+        self.assertRaises(TypeError, GObject.property, type=bool, default='ciao mamma')
+        self.assertRaises(TypeError, GObject.property, type=bool)
+        self.assertRaises(TypeError, GObject.property, type=object, default=0)
+        self.assertRaises(TypeError, GObject.property, type=complex)
+        self.assertRaises(TypeError, GObject.property, flags=-10)
 
     def testDefaults(self):
-        p1 = gobject.property(type=bool, default=True)
-        p2 = gobject.property(type=bool, default=False)
+        p1 = GObject.property(type=bool, default=True)
+        p2 = GObject.property(type=bool, default=False)
 
     def testNameWithUnderscore(self):
-        class C(gobject.GObject):
-            prop_name = gobject.property(type=int)
+        class C(GObject.GObject):
+            prop_name = GObject.property(type=int)
         o = C()
         o.prop_name = 10
         self.assertEqual(o.prop_name, 10)
@@ -335,25 +335,25 @@ class TestProperty(unittest.TestCase):
 
         for gtype, min, max in types:
             # Normal, everything is alright
-            prop = gobject.property(type=gtype, minimum=min, maximum=max)
-            subtype = type('', (gobject.GObject,),
+            prop = GObject.property(type=gtype, minimum=min, maximum=max)
+            subtype = type('', (GObject.GObject,),
                          dict(prop=prop))
             self.assertEqual(subtype.props.prop.minimum, min)
             self.assertEqual(subtype.props.prop.maximum, max)
 
             # Lower than minimum
             self.assertRaises(TypeError,
-                              gobject.property, type=gtype, minimum=min-1,
+                              GObject.property, type=gtype, minimum=min-1,
                               maximum=max)
 
             # Higher than maximum
             self.assertRaises(TypeError,
-                              gobject.property, type=gtype, minimum=min,
+                              GObject.property, type=gtype, minimum=min,
                               maximum=max+1)
 
     def testMultipleInstances(self):
-        class C(gobject.GObject):
-            prop = gobject.property(type=str, default='default')
+        class C(GObject.GObject):
+            prop = GObject.property(type=str, default='default')
 
         o1 = C()
         o2 = C()
@@ -364,8 +364,8 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(o2.prop, 'default')
 
     def testObjectProperty(self):
-        class PropertyObject(GObject):
-            obj = gobject.property(type=GObject)
+        class PropertyObject(GObject.GObject):
+            obj = GObject.property(type=GObject.GObject)
 
         pobj1 = PropertyObject()
         obj1_hash = hash(pobj1)
@@ -377,21 +377,21 @@ class TestProperty(unittest.TestCase):
         self.assertEqual(hash(pobj1), obj1_hash)
 
     def testObjectSubclassProperty(self):
-        class ObjectSubclass(GObject):
+        class ObjectSubclass(GObject.GObject):
             __gtype_name__ = 'ObjectSubclass'
 
-        class PropertyObjectSubclass(GObject):
-            obj = gobject.property(type=ObjectSubclass)
+        class PropertyObjectSubclass(GObject.GObject):
+            obj = GObject.property(type=ObjectSubclass)
 
         obj1 = PropertyObjectSubclass(obj=ObjectSubclass())
 
     def testPropertySubclass(self):
         # test for #470718
-        class A(GObject):
-            prop1 = gobject.property(type=int)
+        class A(GObject.GObject):
+            prop1 = GObject.property(type=int)
 
         class B(A):
-            prop2 = gobject.property(type=int)
+            prop2 = GObject.property(type=int)
 
         b = B()
         b.prop2 = 10
@@ -401,15 +401,15 @@ class TestProperty(unittest.TestCase):
 
     def testPropertySubclassCustomSetter(self):
         # test for #523352
-        class A(GObject):
+        class A(GObject.GObject):
             def get_first(self):
                 return 'first'
-            first = gobject.property(type=str, getter=get_first)
+            first = GObject.property(type=str, getter=get_first)
 
         class B(A):
             def get_second(self):
                 return 'second'
-            second = gobject.property(type=str, getter=get_second)
+            second = GObject.property(type=str, getter=get_second)
 
         a = A()
         self.assertEquals(a.first, 'first')
@@ -423,10 +423,10 @@ class TestProperty(unittest.TestCase):
 
     def testPropertySubclassCustomSetterError(self):
         try:
-            class A(GObject):
+            class A(GObject.GObject):
                 def get_first(self):
                     return 'first'
-                first = gobject.property(type=str, getter=get_first)
+                first = GObject.property(type=str, getter=get_first)
 
                 def do_get_property(self, pspec):
                     pass
@@ -437,9 +437,9 @@ class TestProperty(unittest.TestCase):
 
     # Bug 587637.
     def test_float_min(self):
-        gobject.property(type=float, minimum=-1)
-        gobject.property(type=gobject.TYPE_FLOAT, minimum=-1)
-        gobject.property(type=gobject.TYPE_DOUBLE, minimum=-1)
+        GObject.property(type=float, minimum=-1)
+        GObject.property(type=GObject.TYPE_FLOAT, minimum=-1)
+        GObject.property(type=GObject.TYPE_DOUBLE, minimum=-1)
 
     # Bug 644039
     def testReferenceCount(self):
diff --git a/tests/test_signal.py b/tests/test_signal.py
index d68cb5b..8486adb 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -4,13 +4,13 @@ import gc
 import unittest
 import sys
 
-import gobject
+from gi.repository import GObject
 import testhelper
 from compathelper import _long
 
-class C(gobject.GObject):
-    __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                                   (gobject.TYPE_INT,)) }
+class C(GObject.GObject):
+    __gsignals__ = { 'my_signal': (GObject.SignalFlags.RUN_FIRST, None,
+                                   (GObject.TYPE_INT,)) }
     def do_my_signal(self, arg):
         self.arg = arg
 
@@ -22,11 +22,11 @@ class D(C):
 class TestSignalCreation(unittest.TestCase):
     # Bug 540376.
     def test_illegals(self):
-        self.assertRaises(TypeError, lambda: gobject.signal_new('test',
+        self.assertRaises(TypeError, lambda: GObject.signal_new('test',
                                                                 None,
                                                                 0,
-                                                                gobject.TYPE_NONE,
-                                                                (gobject.TYPE_LONG,)))
+                                                                None,
+                                                                (GObject.TYPE_LONG,)))
 
 
 class TestChaining(unittest.TestCase):
@@ -58,14 +58,14 @@ class TestChaining(unittest.TestCase):
 class TestGSignalsError(unittest.TestCase):
     def testInvalidType(self, *args):
         def foo():
-            class Foo(gobject.GObject):
+            class Foo(GObject.GObject):
                 __gsignals__ = None
         self.assertRaises(TypeError, foo)
         gc.collect()
 
     def testInvalidName(self, *args):
         def foo():
-            class Foo(gobject.GObject):
+            class Foo(GObject.GObject):
                 __gsignals__ = {'not-exists' : 'override'}
         self.assertRaises(TypeError, foo)
         gc.collect()
@@ -73,14 +73,14 @@ class TestGSignalsError(unittest.TestCase):
 class TestGPropertyError(unittest.TestCase):
     def testInvalidType(self, *args):
         def foo():
-            class Foo(gobject.GObject):
+            class Foo(GObject.GObject):
                 __gproperties__ = None
         self.assertRaises(TypeError, foo)
         gc.collect()
 
     def testInvalidName(self, *args):
         def foo():
-            class Foo(gobject.GObject):
+            class Foo(GObject.GObject):
                 __gproperties__ = { None: None }
 
         self.assertRaises(TypeError, foo)
@@ -88,7 +88,7 @@ class TestGPropertyError(unittest.TestCase):
 
 class TestList(unittest.TestCase):
     def testListObject(self):
-        self.assertEqual(gobject.signal_list_names(C), ('my-signal',))
+        self.assertEqual(GObject.signal_list_names(C), ('my-signal',))
 
 
 def my_accumulator(ihint, return_accu, handler_return, user_data):
@@ -99,12 +99,12 @@ def my_accumulator(ihint, return_accu, handler_return, user_data):
         return False, return_accu
     return True, return_accu + handler_return
 
-class Foo(gobject.GObject):
+class Foo(GObject.GObject):
     __gsignals__ = {
-        'my-acc-signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_INT,
+        'my-acc-signal': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_INT,
                                    (), my_accumulator, "accum data"),
-        'my-other-acc-signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_BOOLEAN,
-                                (), gobject.signal_accumulator_true_handled)
+        'my-other-acc-signal': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
+                                (), GObject.signal_accumulator_true_handled)
         }
 
 class TestAccumulator(unittest.TestCase):
@@ -141,22 +141,22 @@ class TestAccumulator(unittest.TestCase):
         self.__true_val = 3
         return False
 
-class E(gobject.GObject):
-    __gsignals__ = { 'signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+class E(GObject.GObject):
+    __gsignals__ = { 'signal': (GObject.SignalFlags.RUN_FIRST, None,
                                 ()) }
     def __init__(self):
-        gobject.GObject.__init__(self)
+        GObject.GObject.__init__(self)
         self.status = 0
 
     def do_signal(self):
         assert self.status == 0
         self.status = 1
 
-class F(gobject.GObject):
-    __gsignals__ = { 'signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+class F(GObject.GObject):
+    __gsignals__ = { 'signal': (GObject.SignalFlags.RUN_FIRST, None,
                                 ()) }
     def __init__(self):
-        gobject.GObject.__init__(self)
+        GObject.GObject.__init__(self)
         self.status = 0
 
     def do_signal(self):
@@ -167,7 +167,7 @@ class TestEmissionHook(unittest.TestCase):
         self.hook = True
         e = E()
         e.connect('signal', self._callback)
-        gobject.add_emission_hook(E, "signal", self._emission_hook)
+        GObject.add_emission_hook(E, "signal", self._emission_hook)
         e.emit('signal')
         self.assertEqual(e.status, 3)
 
@@ -175,8 +175,8 @@ class TestEmissionHook(unittest.TestCase):
         self.hook = False
         e = E()
         e.connect('signal', self._callback)
-        hook_id = gobject.add_emission_hook(E, "signal", self._emission_hook)
-        gobject.remove_emission_hook(E, "signal", hook_id)
+        hook_id = GObject.add_emission_hook(E, "signal", self._emission_hook)
+        GObject.remove_emission_hook(E, "signal", hook_id)
         e.emit('signal')
         self.assertEqual(e.status, 3)
 
@@ -197,7 +197,7 @@ class TestEmissionHook(unittest.TestCase):
         def _emission_hook(obj):
             obj.status += 1
             return False
-        hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook)
+        hook_id = GObject.add_emission_hook(obj, "signal", _emission_hook)
         obj.emit('signal')
         obj.emit('signal')
         self.assertEqual(obj.status, 3)
@@ -208,10 +208,10 @@ class TestEmissionHook(unittest.TestCase):
         def _emission_hook(obj):
             obj.status += 1
             return True
-        hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook)
+        hook_id = GObject.add_emission_hook(obj, "signal", _emission_hook)
         obj.emit('signal')
         obj.emit('signal')
-        gobject.remove_emission_hook(obj, "signal", hook_id)
+        GObject.remove_emission_hook(obj, "signal", hook_id)
         self.assertEqual(obj.status, 4)
 
     def testCallbackReturnTrueButRemove(self):
@@ -220,9 +220,9 @@ class TestEmissionHook(unittest.TestCase):
         def _emission_hook(obj):
             obj.status += 1
             return True
-        hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook)
+        hook_id = GObject.add_emission_hook(obj, "signal", _emission_hook)
         obj.emit('signal')
-        gobject.remove_emission_hook(obj, "signal", hook_id)
+        GObject.remove_emission_hook(obj, "signal", hook_id)
         obj.emit('signal')
         self.assertEqual(obj.status, 3)
 
@@ -273,11 +273,11 @@ class TestClosures(unittest.TestCase):
         gc.collect()
 
     def testGString(self):
-        class C(gobject.GObject):
-            __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_GSTRING,
-                                           (gobject.TYPE_GSTRING,)) }
+        class C(GObject.GObject):
+            __gsignals__ = { 'my_signal': (GObject.SignalFlags.RUN_LAST, GObject.TYPE_GSTRING,
+                                           (GObject.TYPE_GSTRING,)) }
             def __init__(self, test):
-                gobject.GObject.__init__(self)
+                GObject.GObject.__init__(self)
                 self.test = test
             def do_my_signal(self, data):
                 self.data = data
@@ -287,12 +287,12 @@ class TestClosures(unittest.TestCase):
         data = c.emit("my_signal", "\01\00\02")
         self.assertEqual(data, "\02\00\01")
 
-class SigPropClass(gobject.GObject):
-    __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                                   (gobject.TYPE_INT,)) }
+class SigPropClass(GObject.GObject):
+    __gsignals__ = { 'my_signal': (GObject.SignalFlags.RUN_FIRST, None,
+                                   (GObject.TYPE_INT,)) }
 
     __gproperties__ = {
-        'foo': (str, None, None, '', gobject.PARAM_WRITABLE|gobject.PARAM_CONSTRUCT),
+        'foo': (str, None, None, '', GObject.PARAM_WRITABLE|GObject.PARAM_CONSTRUCT),
         }
 
     signal_emission_failed = False
@@ -316,14 +316,14 @@ class TestSigProp(unittest.TestCase):
         obj = SigPropClass()
         self.failIf(obj.signal_emission_failed)
 
-f = gobject.SIGNAL_RUN_FIRST
-l = gobject.SIGNAL_RUN_LAST
-float = gobject.TYPE_FLOAT
-double = gobject.TYPE_DOUBLE
-uint = gobject.TYPE_UINT
-ulong = gobject.TYPE_ULONG
+f = GObject.SignalFlags.RUN_FIRST
+l = GObject.SignalFlags.RUN_LAST
+float = GObject.TYPE_FLOAT
+double = GObject.TYPE_DOUBLE
+uint = GObject.TYPE_UINT
+ulong = GObject.TYPE_ULONG
 
-class CM(gobject.GObject):
+class CM(GObject.GObject):
     __gsignals__ = dict(
         test1=(f, None, ()),
         test2=(l, None, (str,)),
@@ -369,7 +369,7 @@ class _TestCMarshaller:
         rv = self.obj.emit("test-object", self)
         self.assertEqual(rv, self)
 
-if 'generic-c-marshaller' in gobject.features:
+if 'generic-c-marshaller' in GObject.features:
     class TestCMarshaller(_TestCMarshaller, unittest.TestCase):
         pass
 else:
@@ -380,10 +380,10 @@ else:
 # Test for 374653
 class TestPyGValue(unittest.TestCase):
     def testNoneNULLBoxedConversion(self):
-        class C(gobject.GObject):
+        class C(GObject.GObject):
             __gsignals__ = dict(my_boxed_signal=(
-                gobject.SIGNAL_RUN_LAST,
-                gobject.type_from_name('GStrv'), ()))
+                GObject.SignalFlags.RUN_LAST,
+                GObject.type_from_name('GStrv'), ()))
 
         obj = C()
         obj.connect('my-boxed-signal', lambda obj: None)
diff --git a/tests/test_source.py b/tests/test_source.py
index 339fb32..f4e4644 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -4,6 +4,7 @@ import unittest
 
 import glib
 
+from gi.repository import GObject
 
 class Idle(glib.Idle):
     def __init__(self, loop):
@@ -44,7 +45,7 @@ class TestSource(unittest.TestCase):
         timeout.attach()
 
     def testSources(self):
-        loop = glib.MainLoop()
+        loop = GObject.MainLoop()
 
         self.setup_timeout(loop)
 
@@ -64,7 +65,7 @@ class TestSource(unittest.TestCase):
     def testSourcePrepare(self):
         # this test may not terminate if prepare() is wrapped incorrectly
         dispatched = [False]
-        loop = glib.MainLoop()
+        loop = GObject.MainLoop()
 
         class CustomTimeout(glib.Source):
             def prepare(self):
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index c90d1d6..2e831df 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -5,6 +5,7 @@ import unittest
 
 import glib
 
+from gi.repository import GObject
 
 class TestProcess(unittest.TestCase):
 
@@ -14,7 +15,7 @@ class TestProcess(unittest.TestCase):
 
     def testChildWatch(self):
         self.data = None
-        self.loop = glib.MainLoop()
+        self.loop = GObject.MainLoop()
         argv = [sys.executable, '-c', 'import sys']
         pid, stdin, stdout, stderr = glib.spawn_async(
             argv, flags=glib.SPAWN_DO_NOT_REAP_CHILD)
diff --git a/tests/test_thread.py b/tests/test_thread.py
index be746a4..a7224f1 100644
--- a/tests/test_thread.py
+++ b/tests/test_thread.py
@@ -5,10 +5,11 @@ import unittest
 import glib
 import testhelper
 
+from gi.repository import GObject
 
 class TestThread(unittest.TestCase):
     def setUp(self):
-        self.main = glib.MainLoop()
+        self.main = GObject.MainLoop()
 
     def from_thread_cb(self, test, enum):
         assert test == self.obj
@@ -22,7 +23,7 @@ class TestThread(unittest.TestCase):
 
     def testExtensionModule(self):
         glib.idle_add(self.idle_cb)
-        glib.timeout_add(50, self.timeout_cb)
+        GObject.timeout_add(50, self.timeout_cb)
         self.main.run()
 
     def timeout_cb(self):
diff --git a/tests/test_unknown.py b/tests/test_unknown.py
index 2a18eec..8c076a8 100644
--- a/tests/test_unknown.py
+++ b/tests/test_unknown.py
@@ -2,17 +2,17 @@
 
 import unittest
 
-import gobject
+from gi.repository import GObject
 import testhelper
 
 
-TestInterface = gobject.GType.from_name('TestInterface')
+TestInterface = GObject.GType.from_name('TestInterface')
 
 
 class TestUnknown(unittest.TestCase):
     def testFoo(self):
         obj = testhelper.get_unknown()
-        TestUnknownGType = gobject.GType.from_name('TestUnknown')
-        TestUnknown = gobject.new(TestUnknownGType).__class__
+        TestUnknownGType = GObject.GType.from_name('TestUnknown')
+        TestUnknown = GObject.new(TestUnknownGType).__class__
         assert isinstance(obj, testhelper.Interface)
         assert isinstance(obj, TestUnknown)
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index 4d1b44d..b242a34 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -531,7 +531,7 @@ PYGLIB_MODULE_START(testhelper, "testhelper")
 
   d = PyModule_GetDict(module);
 
-  if ((m = PyImport_ImportModule("gobject")) != NULL) {
+  if ((m = PyImport_ImportModule("gi._gobject")) != NULL) {
     PyObject *moddict = PyModule_GetDict(m);
     
     _PyGObject_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "GObject");
diff --git a/tests/testmodule.py b/tests/testmodule.py
index 5fc29b3..c4132c5 100644
--- a/tests/testmodule.py
+++ b/tests/testmodule.py
@@ -1,17 +1,17 @@
-import gobject
+from gi.repository import GObject
 
-class PyGObject(gobject.GObject):
+class PyGObject(GObject.GObject):
     __gtype_name__ = 'PyGObject'
     __gproperties__ = {
-        'label': (gobject.TYPE_STRING,
+        'label': (GObject.TYPE_STRING,
                   'label property',
                   'the label of the object',
-                  'default', gobject.PARAM_READWRITE),
+                  'default', GObject.PARAM_READWRITE),
         }
 
     def __init__(self):
         self._props = {}
-        gobject.GObject.__init__(self)
+        GObject.GObject.__init__(self)
         self.set_property('label', 'hello')
 
     def do_set_property(self, name, value):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]