[pygobject/coverage-gobject-overrides] wip



commit e528266fbc3a271dc794d899bcbc263bad98d525
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Nov 23 20:54:25 2018 +0100

    wip

 gi/overrides/GObject.py         |  18 +++---
 tests/test_gobject.py           |   9 +++
 tests/test_overrides_gobject.py | 132 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 11 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 26e9f25b..b9b3390a 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -268,6 +268,8 @@ class Value(GObjectModule.Value):
             self.set_string(py_value)
         elif gtype == TYPE_PARAM:
             self.set_param(py_value)
+        elif gtype == TYPE_PYOBJECT:
+            self.set_boxed(py_value)
         elif gtype.is_a(TYPE_ENUM):
             self.set_enum(py_value)
         elif gtype.is_a(TYPE_FLAGS):
@@ -278,16 +280,10 @@ class Value(GObjectModule.Value):
             self.set_pointer(py_value)
         elif gtype.is_a(TYPE_OBJECT):
             self.set_object(py_value)
-        elif gtype == TYPE_UNICHAR:
-            self.set_uint(int(py_value))
-        # elif gtype == TYPE_OVERRIDE:
-        #     pass
         elif gtype == TYPE_GTYPE:
             self.set_gtype(py_value)
         elif gtype == TYPE_VARIANT:
             self.set_variant(py_value)
-        elif gtype == TYPE_PYOBJECT:
-            self.set_boxed(py_value)
         else:
             raise TypeError("Unknown value type %s" % gtype)
 
@@ -318,6 +314,8 @@ class Value(GObjectModule.Value):
             return self.get_double()
         elif gtype == TYPE_STRING:
             return self.get_string()
+        elif gtype == TYPE_PYOBJECT:
+            return self.get_boxed()
         elif gtype == TYPE_PARAM:
             return self.get_param()
         elif gtype.is_a(TYPE_ENUM):
@@ -330,16 +328,14 @@ class Value(GObjectModule.Value):
             return self.get_pointer()
         elif gtype.is_a(TYPE_OBJECT):
             return self.get_object()
-        elif gtype == TYPE_UNICHAR:
-            return self.get_uint()
         elif gtype == TYPE_GTYPE:
             return self.get_gtype()
         elif gtype == TYPE_VARIANT:
             return self.get_variant()
-        elif gtype == TYPE_PYOBJECT:
-            pass
-        else:
+        elif gtype == _gi.TYPE_INVALID:
             return None
+        else:
+            raise TypeError("Unknown value type %s" % gtype)
 
     def __repr__(self):
         return '<Value (%s) %s>' % (self.g_type.name, self.get_value())
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index bef3e9b5..9b4656b4 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -15,6 +15,7 @@ from gi.module import get_introspection_module
 from gi import _gi
 
 import testhelper
+from .helper import capture_glib_deprecation_warnings
 
 
 class TestGObjectAPI(unittest.TestCase):
@@ -463,6 +464,14 @@ class TestPropertyBindings(unittest.TestCase):
         self.assertEqual(self.source.int_prop, 1)
         self.assertEqual(self.target.int_prop, 2)
 
+    def test_call_binding(self):
+        binding = self.source.bind_property('int_prop', self.target, 'int_prop',
+                                            GObject.BindingFlags.DEFAULT)
+        with capture_glib_deprecation_warnings() as warn:
+            result = binding()
+        assert len(warn)
+        assert result is binding
+
     def test_bidirectional_binding(self):
         binding = self.source.bind_property('int_prop', self.target, 'int_prop',
                                             GObject.BindingFlags.BIDIRECTIONAL)
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
new file mode 100644
index 00000000..ab1d37fc
--- /dev/null
+++ b/tests/test_overrides_gobject.py
@@ -0,0 +1,132 @@
+from __future__ import absolute_import
+
+from gi import PyGIDeprecationWarning
+from gi.repository import GObject, GLib
+
+import pytest
+
+
+def test_stop_emission_deprec():
+    class TestObject(GObject.GObject):
+        int_prop = GObject.Property(default=0, type=int)
+
+    obj = TestObject()
+
+    def notify_callback(obj, *args):
+        with pytest.warns(PyGIDeprecationWarning):
+            obj.stop_emission("notify::int-prop")
+
+        with pytest.warns(PyGIDeprecationWarning):
+            obj.emit_stop_by_name("notify::int-prop")
+
+        obj.stop_emission_by_name("notify::int-prop")
+
+    obj.connect("notify::int-prop", notify_callback)
+    obj.notify("int-prop")
+
+
+def test_signal_parse_name():
+    obj = GObject.GObject()
+    assert GObject.signal_parse_name("notify", obj, True) == (1, 0)
+
+    with pytest.raises(ValueError):
+        GObject.signal_parse_name("foobar", obj, True)
+
+
+def test_signal_query():
+    obj = GObject.GObject()
+    res = GObject.signal_query("notify", obj)
+    assert res.signal_name == "notify"
+    assert res.itype == obj.__gtype__
+
+    res = GObject.signal_query("foobar", obj)
+    assert res is None
+
+
+def test_value_repr():
+    v = GObject.Value()
+    assert repr(v) == "<Value (invalid) None>"
+
+    v = GObject.Value(int, 0)
+    assert repr(v) == "<Value (gint) 0>"
+
+
+def test_value_no_init():
+    v = GObject.Value()
+    with pytest.raises(TypeError):
+        v.set_value(0)
+    v.init(GObject.TYPE_LONG)
+    v.set_value(0)
+
+
+def test_value_invalid_type():
+    # FIXME: this complains that the value isn't a GType
+    # GObject.Value(GObject.TYPE_INVALID)
+    pass
+
+
+def test_value_long():
+    v = GObject.Value(GObject.TYPE_LONG)
+    v.set_value(0)
+    assert v.get_value() == 0
+
+    v.set_value(GLib.MAXLONG)
+    assert v.get_value() == GLib.MAXLONG
+
+    v.set_value(GLib.MINLONG)
+    assert v.get_value() == GLib.MINLONG
+
+
+def test_value_pointer():
+    v = GObject.Value(GObject.TYPE_POINTER)
+    v.set_value(42)
+    assert v.get_value() == 42
+    v.set_value(0)
+    assert v.get_value() == 0
+
+
+def test_value_unichar():
+    assert GObject.TYPE_UNICHAR == GObject.TYPE_UINT
+
+    v = GObject.Value(GObject.TYPE_UNICHAR)
+    v.set_value(42)
+    assert v.get_value() == 42
+
+    v.set_value(GLib.MAXUINT)
+    assert v.get_value() == GLib.MAXUINT
+
+
+def test_value_gtype():
+    class TestObject(GObject.GObject):
+        pass
+
+    v = GObject.Value(GObject.TYPE_GTYPE)
+    v.set_value(TestObject.__gtype__)
+    assert v.get_value() == TestObject.__gtype__
+    v.set_value(TestObject)
+    assert v.get_value() == TestObject.__gtype__
+
+    with pytest.raises(TypeError):
+        v.set_value(None)
+
+
+def test_value_variant():
+    v = GObject.Value(GObject.TYPE_VARIANT)
+    variant = GLib.Variant('i', 42)
+    v.set_value(variant)
+
+    # FIXME: triggers an assert
+    # assert v.get_value() == variant
+
+    v.set_value(None)
+    assert v.get_value() is None
+
+
+def test_value_pyobject():
+    class Foo(object):
+        pass
+
+    v = GObject.Value(GObject.TYPE_PYOBJECT)
+    for obj in [Foo(), None, 42, "foo"]:
+        v.set_value(obj)
+        assert v.get_value() == obj


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