[pygobject] gtype: raise ValueError when converting an invalid GType to C
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] gtype: raise ValueError when converting an invalid GType to C
- Date: Sun, 25 Nov 2018 11:22:34 +0000 (UTC)
commit eea9716a8351dead3bdcdb8a20bbf8d94f132249
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sun Nov 25 12:17:32 2018 +0100
gtype: raise ValueError when converting an invalid GType to C
Instead of complaining that the type is wrong, which isn't the case here.
gi/pygi-basictype.c | 6 +++++-
tests/test_generictreemodel.py | 2 +-
tests/test_overrides_gobject.py | 8 +++++---
3 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c
index 82b43c54..dafddf27 100644
--- a/gi/pygi-basictype.c
+++ b/gi/pygi-basictype.c
@@ -259,7 +259,11 @@ pygi_gtype_from_py (PyObject *py_arg, GType *type)
GType temp = pyg_type_from_object (py_arg);
if (temp == 0) {
- PyErr_Format (PyExc_TypeError, "Must be gobject.GType, not %s",
+ if (!PyErr_Occurred ()) {
+ PyErr_SetString (PyExc_ValueError, "Invalid GType");
+ return FALSE;
+ }
+ PyErr_Format (PyExc_TypeError, "Must be GObject.GType, not %s",
Py_TYPE (py_arg)->tp_name);
return FALSE;
}
diff --git a/tests/test_generictreemodel.py b/tests/test_generictreemodel.py
index 5e9d716e..acb6028c 100644
--- a/tests/test_generictreemodel.py
+++ b/tests/test_generictreemodel.py
@@ -378,7 +378,7 @@ class TestReturnsAfterError(unittest.TestCase):
self.assertEqual(count, 0)
def test_get_column_type(self):
- with ExceptHook(NotImplementedError, TypeError):
+ with ExceptHook(NotImplementedError, ValueError):
col_type = self.model.get_column_type(0)
self.assertEqual(col_type, GObject.TYPE_INVALID)
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
index 3c7cc04b..b902564f 100644
--- a/tests/test_overrides_gobject.py
+++ b/tests/test_overrides_gobject.py
@@ -66,9 +66,11 @@ def test_value_no_init():
def test_value_invalid_type():
- # FIXME: this complains that the value isn't a GType
- # GObject.Value(GObject.TYPE_INVALID)
- pass
+ v = GObject.Value()
+ assert v.g_type == GObject.TYPE_INVALID
+ assert isinstance(GObject.TYPE_INVALID, GObject.GType)
+ with pytest.raises(ValueError, match="Invalid GType"):
+ v.init(GObject.TYPE_INVALID)
def test_value_long():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]