[pygobject/gsoc2009: 7/160] Add (s|)size conversion and long checking capability
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 7/160] Add (s|)size conversion and long checking capability
- Date: Fri, 14 Aug 2009 21:22:40 +0000 (UTC)
commit 8f0dd4b682eabc1384a4da580290eb6454abb345
Author: Simon van der Linden <simon vanderlinden student uclouvain be>
Date: Tue Jun 23 02:24:30 2009 +0200
Add (s|)size conversion and long checking capability
Add (s|)size conversion from and to Python.
Add long checking capability in Callable.type_check.
Enable the corresponding tests.
girepository/bank-argument.c | 8 ++++++
girepository/btypes.py | 8 ++++-
tests/test_girepository.py | 58 ++++++++----------------------------------
3 files changed, 25 insertions(+), 49 deletions(-)
---
diff --git a/girepository/bank-argument.c b/girepository/bank-argument.c
index 335ea58..92f77b1 100644
--- a/girepository/bank-argument.c
+++ b/girepository/bank-argument.c
@@ -66,9 +66,11 @@ pyg_argument_from_pyobject(PyObject *object, GITypeInfo *type_info)
case GI_TYPE_TAG_INT:
arg.v_int = PyInt_AsLong(object);
break;
+ case GI_TYPE_TAG_SSIZE:
case GI_TYPE_TAG_LONG:
arg.v_long = PyInt_AsLong(object);
break;
+ case GI_TYPE_TAG_SIZE:
case GI_TYPE_TAG_ULONG:
arg.v_ulong = PyInt_AsLong(object);
break;
@@ -269,6 +271,12 @@ pyg_argument_to_pyobject(GArgument *arg, GITypeInfo *type_info)
case GI_TYPE_TAG_ULONG:
obj = PyInt_FromLong(arg->v_ulong);
break;
+ case GI_TYPE_TAG_SSIZE:
+ obj = PyInt_FromLong(arg->v_ssize);
+ break;
+ case GI_TYPE_TAG_SIZE:
+ obj = PyInt_FromLong(arg->v_size);
+ break;
case GI_TYPE_TAG_INT8:
obj = PyInt_FromLong(arg->v_int8);
break;
diff --git a/girepository/btypes.py b/girepository/btypes.py
index 46319c4..d7b6abd 100644
--- a/girepository/btypes.py
+++ b/girepository/btypes.py
@@ -61,14 +61,18 @@ class Callable(object):
elif tag in (repo.TYPE_TAG_UINT32,
repo.TYPE_TAG_INT64,
repo.TYPE_TAG_UINT64,
- repo.TYPE_TAG_ULONG):
+ repo.TYPE_TAG_LONG,
+ repo.TYPE_TAG_ULONG,
+ repo.TYPE_TAG_SIZE,
+ repo.TYPE_TAG_SSIZE):
try:
long(value)
except ValueError:
raise TypeError("%s must be int or long, not %s" % (name, type(value).__name__))
if tag in (repo.TYPE_TAG_UINT32,
repo.TYPE_TAG_UINT64,
- repo.TYPE_TAG_ULONG) and value < 0:
+ repo.TYPE_TAG_ULONG,
+ repo.TYPE_TAG_SIZE) and value < 0:
raise TypeError("%s must be an unsigned value, not %s", name, value)
elif tag in (repo.TYPE_TAG_FLOAT,
repo.TYPE_TAG_DOUBLE):
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index f93cc6f..11876d0 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -103,59 +103,23 @@ class TestGIEverything(unittest.TestCase):
self.assertEqual(UINT64_MAX, Everything.test_uint64(UINT64_MAX))
self.assertRaises(TypeError, Everything.test_uint64, -3)
-# FIXME
-# ======================================================================
-# ERROR: testLong (__main__.TestGIEverything)
-# ----------------------------------------------------------------------
-# Traceback (most recent call last):
-# File "test_girepository.py", line 128, in testLong
-# self.assertEqual(3, Everything.test_long(3))
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 124, in __call__
-# self.type_check(name, value, argType)
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 97, in type_check
-# raise NotImplementedError('type checking for tag %d' % tag)
-# NotImplementedError: type checking for tag 12
-# def testLong(self):
-# self.assertEqual(3, Everything.test_long(3))
-# self.assertEqual(-3, Everything.test_long(-3))
-# self.assertRaises(TypeError, Everything.test_long, 'a')
+ def testLong(self):
+ self.assertEqual(3, Everything.test_long(3))
+ self.assertEqual(-3, Everything.test_long(-3))
+ self.assertRaises(TypeError, Everything.test_long, 'a')
def testULong(self):
self.assertEqual(3, Everything.test_ulong(3))
self.assertRaises(TypeError, Everything.test_ulong, -3)
-# FIXME
-# ======================================================================
-# ERROR: testSSize (__main__.TestGIEverything)
-# ----------------------------------------------------------------------
-# Traceback (most recent call last):
-# File "test_girepository.py", line 137, in testSSize
-# self.assertEqual(3, Everything.test_ssize(3))
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 124, in __call__
-# self.type_check(name, value, argType)
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 97, in type_check
-# raise NotImplementedError('type checking for tag %d' % tag)
-# NotImplementedError: type checking for tag 14
-# def testSSize(self):
-# self.assertEqual(3, Everything.test_ssize(3))
-# self.assertEqual(-3, Everything.test_ssize(-3))
-# self.assertRaises(TypeError, Everything.test_ssize, 'a')
+ def testSSize(self):
+ self.assertEqual(3, Everything.test_ssize(3))
+ self.assertEqual(-3, Everything.test_ssize(-3))
+ self.assertRaises(TypeError, Everything.test_ssize, 'a')
-# FIXME
-# ======================================================================
-# ERROR: testSSize (__main__.TestGIEverything)
-# ----------------------------------------------------------------------
-# Traceback (most recent call last):
-# File "test_girepository.py", line 137, in testSSize
-# self.assertEqual(3, Everything.test_ssize(3))
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 124, in __call__
-# self.type_check(name, value, argType)
-# File "/opt/gnome-introspection/lib64/python2.5/site-packages/gtk-2.0/girepository/btypes.py", line 97, in type_check
-# raise NotImplementedError('type checking for tag %d' % tag)
-# NotImplementedError: type checking for tag 14
-# def testSize(self):
-# self.assertEqual(3, Everything.test_size(3))
-# self.assertRaises(TypeError, Everything.test_size, -3)
+ def testSize(self):
+ self.assertEqual(3, Everything.test_size(3))
+ self.assertRaises(TypeError, Everything.test_size, -3)
def testFloat(self):
self.assertAlmostEqual(3.14, Everything.test_float(3.14), 6)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]