[pygobject] test_everything: Add tests for Regress type tests



commit 476e29d1ba3eda92cc021710017bce4ec252e5b5
Author: Martin Pitt <martinpitt gnome org>
Date:   Fri Nov 9 18:45:22 2012 +0100

    test_everything: Add tests for Regress type tests
    
    Add tests for all the data type handling tests of g-i's Regress module.

 tests/test_everything.py |  183 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 3dc4ed8..9c5cc44 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -80,6 +80,123 @@ class TestEverything(unittest.TestCase):
         self.assertEqual(surface.get_width(), 10)
         self.assertEqual(surface.get_height(), 10)
 
+    def test_bool(self):
+        self.assertEqual(Everything.test_boolean(False), False)
+        self.assertEqual(Everything.test_boolean(True), True)
+        self.assertEqual(Everything.test_boolean('hello'), True)
+        self.assertEqual(Everything.test_boolean(''), False)
+
+        self.assertEqual(Everything.test_boolean_true(True), True)
+        self.assertEqual(Everything.test_boolean_false(False), False)
+
+    def test_int8(self):
+        self.assertEqual(Everything.test_int8(GObject.G_MAXINT8),
+                         GObject.G_MAXINT8)
+        self.assertEqual(Everything.test_int8(GObject.G_MININT8),
+                         GObject.G_MININT8)
+        self.assertRaises(ValueError, Everything.test_int8, GObject.G_MAXINT8 + 1)
+
+        self.assertEqual(Everything.test_uint8(GObject.G_MAXUINT8),
+                         GObject.G_MAXUINT8)
+        self.assertEqual(Everything.test_uint8(0), 0)
+        self.assertRaises(ValueError, Everything.test_uint8, -1)
+        self.assertRaises(ValueError, Everything.test_uint8, GObject.G_MAXUINT8 + 1)
+
+    def test_int16(self):
+        self.assertEqual(Everything.test_int16(GObject.G_MAXINT16),
+                         GObject.G_MAXINT16)
+        self.assertEqual(Everything.test_int16(GObject.G_MININT16),
+                         GObject.G_MININT16)
+        self.assertRaises(ValueError, Everything.test_int16, GObject.G_MAXINT16 + 1)
+
+        self.assertEqual(Everything.test_uint16(GObject.G_MAXUINT16),
+                         GObject.G_MAXUINT16)
+        self.assertEqual(Everything.test_uint16(0), 0)
+        self.assertRaises(ValueError, Everything.test_uint16, -1)
+        self.assertRaises(ValueError, Everything.test_uint16, GObject.G_MAXUINT16 + 1)
+
+    def test_int32(self):
+        self.assertEqual(Everything.test_int32(GObject.G_MAXINT32),
+                         GObject.G_MAXINT32)
+        self.assertEqual(Everything.test_int32(GObject.G_MININT32),
+                         GObject.G_MININT32)
+        self.assertRaises(ValueError, Everything.test_int32, GObject.G_MAXINT32 + 1)
+
+        self.assertEqual(Everything.test_uint32(GObject.G_MAXUINT32),
+                         GObject.G_MAXUINT32)
+        self.assertEqual(Everything.test_uint32(0), 0)
+        self.assertRaises(ValueError, Everything.test_uint32, -1)
+        self.assertRaises(ValueError, Everything.test_uint32, GObject.G_MAXUINT32 + 1)
+
+    def test_int64(self):
+        self.assertEqual(Everything.test_int64(GObject.G_MAXINT64),
+                         GObject.G_MAXINT64)
+        self.assertEqual(Everything.test_int64(GObject.G_MININT64),
+                         GObject.G_MININT64)
+        self.assertRaises(ValueError, Everything.test_int64, GObject.G_MAXINT64 + 1)
+
+        self.assertEqual(Everything.test_uint64(GObject.G_MAXUINT64),
+                         GObject.G_MAXUINT64)
+        self.assertEqual(Everything.test_uint64(0), 0)
+        self.assertRaises(ValueError, Everything.test_uint64, -1)
+        self.assertRaises(ValueError, Everything.test_uint64, GObject.G_MAXUINT64 + 1)
+
+    def test_int(self):
+        self.assertEqual(Everything.test_int(GObject.G_MAXINT),
+                         GObject.G_MAXINT)
+        self.assertEqual(Everything.test_int(GObject.G_MININT),
+                         GObject.G_MININT)
+        self.assertRaises(ValueError, Everything.test_int, GObject.G_MAXINT + 1)
+
+        self.assertEqual(Everything.test_uint(GObject.G_MAXUINT),
+                         GObject.G_MAXUINT)
+        self.assertEqual(Everything.test_uint(0), 0)
+        self.assertRaises(ValueError, Everything.test_uint, -1)
+        self.assertRaises(ValueError, Everything.test_uint, GObject.G_MAXUINT + 1)
+
+    def test_short(self):
+        self.assertEqual(Everything.test_short(GObject.G_MAXSHORT),
+                         GObject.G_MAXSHORT)
+        self.assertEqual(Everything.test_short(GObject.G_MINSHORT),
+                         GObject.G_MINSHORT)
+        self.assertRaises(ValueError, Everything.test_short, GObject.G_MAXSHORT + 1)
+
+        self.assertEqual(Everything.test_ushort(GObject.G_MAXUSHORT),
+                         GObject.G_MAXUSHORT)
+        self.assertEqual(Everything.test_ushort(0), 0)
+        self.assertRaises(ValueError, Everything.test_ushort, -1)
+        self.assertRaises(ValueError, Everything.test_ushort, GObject.G_MAXUSHORT + 1)
+
+    def test_long(self):
+        self.assertEqual(Everything.test_long(GObject.G_MAXLONG),
+                         GObject.G_MAXLONG)
+        self.assertEqual(Everything.test_long(GObject.G_MINLONG),
+                         GObject.G_MINLONG)
+        self.assertRaises(ValueError, Everything.test_long, GObject.G_MAXLONG + 1)
+
+        self.assertEqual(Everything.test_ulong(GObject.G_MAXULONG),
+                         GObject.G_MAXULONG)
+        self.assertEqual(Everything.test_ulong(0), 0)
+        self.assertRaises(ValueError, Everything.test_ulong, -1)
+        self.assertRaises(ValueError, Everything.test_ulong, GObject.G_MAXULONG + 1)
+
+    def test_size(self):
+        self.assertEqual(Everything.test_ssize(GObject.G_MAXSSIZE),
+                         GObject.G_MAXSSIZE)
+        self.assertEqual(Everything.test_ssize(GObject.G_MINSSIZE),
+                         GObject.G_MINSSIZE)
+        self.assertRaises(ValueError, Everything.test_ssize, GObject.G_MAXSSIZE + 1)
+
+        self.assertEqual(Everything.test_size(GObject.G_MAXSIZE),
+                         GObject.G_MAXSIZE)
+        self.assertEqual(Everything.test_size(0), 0)
+        self.assertRaises(ValueError, Everything.test_size, -1)
+        self.assertRaises(ValueError, Everything.test_size, GObject.G_MAXSIZE + 1)
+
+    def test_timet(self):
+        self.assertEqual(Everything.test_timet(42), 42)
+        self.assertRaises(ValueError, Everything.test_timet, GObject.G_MAXUINT64 + 1)
+
     def test_unichar(self):
         self.assertEqual("c", Everything.test_unichar("c"))
 
@@ -89,6 +206,62 @@ class TestEverything(unittest.TestCase):
         self.assertRaises(TypeError, Everything.test_unichar, "")
         self.assertRaises(TypeError, Everything.test_unichar, "morethanonechar")
 
+    def test_float(self):
+        self.assertEqual(Everything.test_float(GObject.G_MAXFLOAT),
+                         GObject.G_MAXFLOAT)
+        self.assertEqual(Everything.test_float(GObject.G_MINFLOAT),
+                         GObject.G_MINFLOAT)
+        self.assertRaises(ValueError, Everything.test_float, GObject.G_MAXFLOAT * 2)
+
+    def test_double(self):
+        self.assertEqual(Everything.test_double(GObject.G_MAXDOUBLE),
+                         GObject.G_MAXDOUBLE)
+        self.assertEqual(Everything.test_double(GObject.G_MINDOUBLE),
+                         GObject.G_MINDOUBLE)
+        self.assertRaises(ValueError, Everything.test_double, GObject.G_MAXDOUBLE * 2)
+
+    def test_value(self):
+        self.assertEqual(Everything.test_int_value_arg(GObject.G_MAXINT), GObject.G_MAXINT)
+        self.assertEqual(Everything.test_value_return(GObject.G_MAXINT), GObject.G_MAXINT)
+
+    def test_variant(self):
+        v = Everything.test_gvariant_i()
+        self.assertEqual(v.get_type_string(), 'i')
+        self.assertEqual(v.get_int32(), 1)
+
+        v = Everything.test_gvariant_s()
+        self.assertEqual(v.get_type_string(), 's')
+        self.assertEqual(v.get_string(), 'one')
+
+        v = Everything.test_gvariant_v()
+        self.assertEqual(v.get_type_string(), 'v')
+        vi = v.get_variant()
+        self.assertEqual(vi.get_type_string(), 's')
+        self.assertEqual(vi.get_string(), 'contents')
+
+        v = Everything.test_gvariant_as()
+        self.assertEqual(v.get_type_string(), 'as')
+        self.assertEqual(v.get_strv(), ['one', 'two', 'three'])
+
+        v = Everything.test_gvariant_asv()
+        self.assertEqual(v.get_type_string(), 'a{sv}')
+        self.assertEqual(v.lookup_value('nosuchkey', None), None)
+        name = v.lookup_value('name', None)
+        self.assertEqual(name.get_string(), 'foo')
+        timeout = v.lookup_value('timeout', None)
+        self.assertEqual(timeout.get_int32(), 10)
+
+    def test_string(self):
+        const_str = b'const \xe2\x99\xa5 utf8'.decode('UTF-8')
+        noconst_str = 'non' + const_str
+
+        self.assertEqual(Everything.test_utf8_const_return(), const_str)
+        self.assertEqual(Everything.test_utf8_nonconst_return(), noconst_str)
+        self.assertEqual(Everything.test_utf8_out(), noconst_str)
+
+        Everything.test_utf8_const_in(const_str)
+        self.assertEqual(Everything.test_utf8_inout(const_str), noconst_str)
+
     def test_floating(self):
         e = Everything.TestFloating()
         self.assertEqual(e.__grefcount__, 1)
@@ -563,6 +736,16 @@ class TestCallbacks(unittest.TestCase):
 
 @unittest.skipUnless(has_cairo, 'built without cairo support')
 class TestClosures(unittest.TestCase):
+    def test_no_arg(self):
+        def callback():
+            self.called = True
+            return 42
+
+        self.called = False
+        result = Everything.test_closure(callback)
+        self.assertTrue(self.called)
+        self.assertEqual(result, 42)
+
     def test_int_arg(self):
         def callback(num):
             self.called = True



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