[pygobject/gsoc2009: 26/160] Add tests for subclasses



commit 4506bb08ca3045a3a8bba30a26418cb1dd946a6f
Author: Simon van der Linden <simon vanderlinden student uclouvain be>
Date:   Sun Jun 28 13:22:58 2009 +0200

    Add tests for subclasses

 tests/test_girepository.py |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index 63d9d7c..c21d719 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -497,7 +497,13 @@ class TestGIEverything(unittest.TestCase):
         self.assertRaises(TypeError, Everything.TestObj, 'foo', 'bar')
         self.assertRaises(TypeError, Everything.TestObj, 42)
 
-    def testlInstanceMethod(self):
+    def testInstanceMethod(self):
+        o = Everything.TestObj('foo')
+        self.assertEquals(-1, o.instance_method())
+        self.assertRaises(TypeError, o.instance_method, 'foo')
+        self.assertRaises(TypeError, Everything.TestObj.instance_method, gobject.GObject())
+
+    def testlVirtualMethod(self):
         o = Everything.TestObj('foo')
         self.assertEquals(42, o.do_matrix('matrix'))
         self.assertRaises(TypeError, o.do_matrix)
@@ -513,12 +519,24 @@ class TestGIEverything(unittest.TestCase):
         o = Everything.TestObj('foo')
         self.assertEquals(42, o.static_method(42))
 
-    def testSubclass(self):
-        class TestSubclass(Everything.TestObj):
-            def __init__(self):
-                Everything.TestObj.__init__(self, 'foo')
-        s = TestSubclass()
-        self.assertEquals(s.do_matrix('matrix'), 42)
+    def testSubObj(self):
+        self.assertTrue(issubclass(Everything.TestSubObj, Everything.TestObj))
+        self.assertEquals(42, Everything.TestSubObj.static_method(42))
+
+        self.assertRaises(TypeError, Everything.TestSubObj, 'foo')
+
+        s = Everything.TestSubObj()
+        self.assertTrue(isinstance(s, Everything.TestSubObj))
+        self.assertTrue(isinstance(s, Everything.TestObj))
+
+        self.assertTrue(hasattr(s, 'set_bare'))
+
+        self.assertEquals(42, s.do_matrix('foo'))
+
+        self.assertTrue(hasattr(s, 'unset_bare'))
+
+        self.assertEquals(0, s.instance_method())
+        self.assertRaises(TypeError, Everything.TestObj.instance_method, Everything.TestObj('foo'))
 
 
 if __name__ == '__main__':



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