[pygobject] Add tests for internal API
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Add tests for internal API
- Date: Mon, 17 Dec 2012 21:55:57 +0000 (UTC)
commit 449b1ef0d94450c1e457770a093abd6d6c9e6291
Author: Martin Pitt <martinpitt gnome org>
Date: Mon Dec 17 22:50:59 2012 +0100
Add tests for internal API
These cover functions like pygobject_new(), pyg_value_from_pyobject() and
pyg_value_as_pyobject() that are wrapped by testhelpermodule.c. With that these
functions can be tested in isolation without the whole GI stack around them.
tests/Makefile.am | 1 +
tests/test_internal_api.py | 73 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a91c814..77efd2e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,6 +88,7 @@ EXTRA_DIST = \
test_gobject.py \
test_gtype.py \
test_interface.py \
+ test_internal_api.py \
test_iochannel.py \
test_mainloop.py \
test_option.py \
diff --git a/tests/test_internal_api.py b/tests/test_internal_api.py
new file mode 100644
index 0000000..ca50f6b
--- /dev/null
+++ b/tests/test_internal_api.py
@@ -0,0 +1,73 @@
+# -*- Mode: Python -*-
+
+import unittest
+
+from gi.repository import GLib, GObject
+
+import testhelper
+import testmodule
+
+
+class TestObject(unittest.TestCase):
+ def test_create_ctor(self):
+ o = testmodule.PyGObject()
+ self.assertTrue(isinstance(o, GObject.Object))
+ self.assertTrue(isinstance(o, testmodule.PyGObject))
+
+ # has expected property
+ self.assertEqual(o.props.label, 'hello')
+ o.props.label = 'goodbye'
+ self.assertEqual(o.props.label, 'goodbye')
+ self.assertRaises(AttributeError, getattr, o.props, 'nosuchprop')
+
+ def test_pyobject_new_test_type(self):
+ o = testhelper.create_test_type()
+ self.assertTrue(isinstance(o, testmodule.PyGObject))
+
+ # has expected property
+ self.assertEqual(o.props.label, 'hello')
+ o.props.label = 'goodbye'
+ self.assertEqual(o.props.label, 'goodbye')
+ self.assertRaises(AttributeError, getattr, o.props, 'nosuchprop')
+
+ def test_new_refcount(self):
+ # TODO: justify why this should be 2
+ self.assertEqual(testhelper.test_g_object_new(), 2)
+
+
+class TestGValueConversion(unittest.TestCase):
+ def test_int(self):
+ self.assertEqual(testhelper.test_value(0), 0)
+ self.assertEqual(testhelper.test_value(5), 5)
+ self.assertEqual(testhelper.test_value(-5), -5)
+ self.assertEqual(testhelper.test_value(GObject.G_MAXINT32), GObject.G_MAXINT32)
+ self.assertEqual(testhelper.test_value(GObject.G_MININT32), GObject.G_MININT32)
+
+ def test_str(self):
+ self.assertEqual(testhelper.test_value('hello'), 'hello')
+
+ def test_int_array(self):
+ self.assertEqual(testhelper.test_value_array([]), [])
+ self.assertEqual(testhelper.test_value_array([0]), [0])
+ ar = list(range(100))
+ self.assertEqual(testhelper.test_value_array(ar), ar)
+
+ def test_str_array(self):
+ self.assertEqual(testhelper.test_value_array([]), [])
+ self.assertEqual(testhelper.test_value_array(['a']), ['a'])
+ ar = ('aa ' * 1000).split()
+ self.assertEqual(testhelper.test_value_array(ar), ar)
+
+
+class TestErrors(unittest.TestCase):
+ def test_gerror(self):
+ callable_ = lambda: GLib.file_get_contents('/nonexisting ')
+ self.assertRaises(GLib.GError, testhelper.test_gerror_exception, callable_)
+
+ def test_no_gerror(self):
+ callable_ = lambda: GLib.file_get_contents(__file__)
+ self.assertEqual(testhelper.test_gerror_exception(callable_), None)
+
+
+if __name__ == '__main__':
+ unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]