[pygtk] tests: fix test_api, test_dialog, test_enum and test_liststore



commit 5f66d9b20eb223bdd547f027634b8a71db66e526
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Thu Mar 24 08:29:15 2011 +0100

    tests: fix test_api, test_dialog, test_enum and test_liststore

 tests/test_api.py       |    6 +-
 tests/test_dialog.py    |    7 +-
 tests/test_enum.py      |  164 +++++++++++++++++++++++-----------------------
 tests/test_liststore.py |    6 +-
 4 files changed, 92 insertions(+), 91 deletions(-)
---
diff --git a/tests/test_api.py b/tests/test_api.py
index 77984a9..0cba7b0 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -2,7 +2,7 @@ import os
 import sys
 import unittest
 
-from common import gobject, gtk, glade
+from common import gobject, gtk
 
 class APITest(unittest.TestCase):
     def testKeysyms(self):
@@ -26,8 +26,8 @@ class APITest(unittest.TestCase):
         self.assertEqual(ra.get_child().get_text(), 'label')
 
     def testGlade(self):
-        self.failUnless(hasattr(glade, 'XML'))
-        self.failUnless(issubclass(glade.XML, gobject.GObject))
+        self.failUnless(hasattr(gtk.glade, 'XML'))
+        self.failUnless(issubclass(gtk.glade.XML, gobject.GObject))
 
     def testReload(self):
         # test for #349026
diff --git a/tests/test_dialog.py b/tests/test_dialog.py
index 9102af6..a6a3ce5 100644
--- a/tests/test_dialog.py
+++ b/tests/test_dialog.py
@@ -16,11 +16,12 @@ class MessageDialogTest(unittest.TestCase):
     def testSubclass(self):
         # Normal subclassing should not register a type
         sub = type('sub', (gtk.MessageDialog,), {})
+        print sub.__gtype__
+        print sub.__gtype__.name
         self.assertEqual(sub.__gtype__.name, 'GtkMessageDialog')
 
-        # This depends on 311254
-        #type('Sub', (gtk.MessageDialog,), {'__gtype_name__': 'SubDialog'})
-        #self.assertEqual(sub.__gtype__.name, 'SubDialog')
+        type('Sub', (gtk.MessageDialog,), {'__gtype_name__': 'SubDialog'})
+        self.assertEqual(sub.__gtype__.name, 'SubDialog')
 
     def testDialogLeak(self):
         dlg = gtk.Dialog()
diff --git a/tests/test_enum.py b/tests/test_enum.py
index 8f02250..9e6f926 100644
--- a/tests/test_enum.py
+++ b/tests/test_enum.py
@@ -2,7 +2,7 @@ import unittest
 import warnings
 
 from gobject import GEnum, GFlags, GObject, GType, PARAM_READWRITE
-from common import gobject, atk, gtk, gdk
+from common import gobject, atk, gtk
 
 class PObject(GObject):
     __gproperties__ = {
@@ -18,11 +18,11 @@ class PObject(GObject):
 
 class EnumTest(unittest.TestCase):
     def testEnums(self):
-        self.failUnless(issubclass(GEnum, int))
-        self.failUnless(isinstance(atk.LAYER_OVERLAY, atk.Layer))
-        self.failUnless(isinstance(atk.LAYER_OVERLAY, int))
-        self.failUnless('LAYER_OVERLAY' in repr(atk.LAYER_OVERLAY))
-        self.failUnless(int(atk.LAYER_OVERLAY))
+        self.assertTrue(issubclass(GEnum, int))
+        self.assertTrue(isinstance(atk.LAYER_OVERLAY, atk.Layer))
+        self.assertTrue(isinstance(atk.LAYER_OVERLAY, int))
+        self.assertTrue('LAYER_OVERLAY' in repr(atk.LAYER_OVERLAY))
+        self.assertTrue(int(atk.LAYER_OVERLAY))
         self.assertEquals(atk.LAYER_INVALID, 0)
         self.assertNotEquals(atk.LAYER_INVALID, 1)
         self.assertNotEquals(atk.LAYER_INVALID, -1)
@@ -43,17 +43,17 @@ class EnumTest(unittest.TestCase):
         win.realize()
 
         state = win.window.get_state()
-        self.assertEquals(state, gdk.WINDOW_STATE_WITHDRAWN)
-        self.failUnless(isinstance(state, gdk.WindowState))
-        self.failUnless('WINDOW_STATE_WITHDRAWN' in repr(state))
+        self.assertEquals(state, gtk.gdk.WINDOW_STATE_WITHDRAWN)
+        self.assertTrue(isinstance(state, gtk.gdk.WindowState))
+        self.assertTrue('WINDOW_STATE_WITHDRAWN' in repr(state))
 
     def testProperty(self):
         win = gtk.Window()
 
         wtype = win.get_property('type')
         self.assertEquals(wtype, gtk.WINDOW_TOPLEVEL)
-        self.failUnless(isinstance(wtype, gtk.WindowType))
-        self.failUnless('WINDOW_TOPLEVEL' in repr(wtype))
+        self.assertTrue(isinstance(wtype, gtk.WindowType))
+        self.assertTrue('WINDOW_TOPLEVEL' in repr(wtype))
 
     def testAtkObj(self):
         obj = atk.NoOpObject(GObject())
@@ -63,56 +63,56 @@ class EnumTest(unittest.TestCase):
         win = gtk.Window()
         enums = filter(lambda x: GType.is_a(x.value_type, GEnum),
                        gobject.list_properties(win))
-        self.failUnless(enums)
+        self.assertTrue(enums)
         enum = enums[0]
-        self.failUnless(hasattr(enum, 'enum_class'))
-        self.failUnless(issubclass(enum.enum_class, GEnum))
+        self.assertTrue(hasattr(enum, 'enum_class'))
+        self.assertTrue(issubclass(enum.enum_class, GEnum))
 
     def testWeirdEnumValues(self):
-        self.assertEquals(int(gdk.NOTHING), -1)
-        self.assertEquals(int(gdk.BUTTON_PRESS), 4)
+        self.assertEquals(int(gtk.gdk.NOTHING), -1)
+        self.assertEquals(int(gtk.gdk.BUTTON_PRESS), 4)
 
     def testParamSpec(self):
         props = filter(lambda prop: GType.is_a(prop.value_type, GEnum),
                        gobject.list_properties(gtk.Window))
-        self.failUnless(len(props)>= 6)
+        self.assertTrue(len(props)>= 6)
         props = filter(lambda prop: prop.name == 'type', props)
-        self.failUnless(props)
+        self.assertTrue(props)
         pspec = props[0]
         klass = pspec.enum_class
         self.assertEquals(klass, gtk.WindowType)
-        self.failUnless(hasattr(klass, '__enum_values__'))
-        self.failUnless(isinstance(klass.__enum_values__, dict))
-        self.failUnless(len(klass.__enum_values__) >= 2)
-        self.failUnless(isinstance(pspec.default_value, gtk.WindowType))
+        self.assertTrue(hasattr(klass, '__enum_values__'))
+        self.assertTrue(isinstance(klass.__enum_values__, dict))
+        self.assertTrue(len(klass.__enum_values__) >= 2)
+        self.assertTrue(isinstance(pspec.default_value, gtk.WindowType))
 
     def testOutofBounds(self):
         val = gtk.icon_size_register('fake', 24, 24)
-        self.failUnless(isinstance(val, gobject.GEnum))
+        self.assertTrue(isinstance(val, gobject.GEnum))
         self.assertEquals(int(val), 7)
-        self.failUnless('7' in repr(val))
-        self.failUnless('GtkIconSize' in repr(val))
+        self.assertTrue('7' in repr(val))
+        self.assertTrue('GtkIconSize' in repr(val))
 
     def testEnumProperty(self):
         default = PObject.props.enum.default_value
-        self.failUnless(isinstance(default, gtk.WindowType))
+        self.assertTrue(isinstance(default, gtk.WindowType))
         self.assertEqual(default, gtk.WINDOW_TOPLEVEL)
         default = PObject.props.enum2.default_value
-        self.failUnless(isinstance(default, gtk.WindowType))
+        self.assertTrue(isinstance(default, gtk.WindowType))
         self.assertEqual(default, gtk.WINDOW_TOPLEVEL)
 
 class FlagsTest(unittest.TestCase):
     def testFlags(self):
-        self.failUnless(issubclass(GFlags, int))
-        self.failUnless(isinstance(gdk.BUTTON_PRESS_MASK, gdk.EventMask))
-        self.failUnless(isinstance(gdk.BUTTON_PRESS_MASK, int))
-        self.assertEquals(gdk.BUTTON_PRESS_MASK, 256)
-        self.assertNotEquals(gdk.BUTTON_PRESS_MASK, 0)
-        self.assertNotEquals(gdk.BUTTON_PRESS_MASK, -256)
-        self.assertNotEquals(gdk.BUTTON_PRESS_MASK, gdk.BUTTON_RELEASE_MASK)
+        self.assertTrue(issubclass(GFlags, int))
+        self.assertTrue(isinstance(gtk.gdk.BUTTON_PRESS_MASK, gtk.gdk.EventMask))
+        self.assertTrue(isinstance(gtk.gdk.BUTTON_PRESS_MASK, int))
+        self.assertEquals(gtk.gdk.BUTTON_PRESS_MASK, 256)
+        self.assertNotEquals(gtk.gdk.BUTTON_PRESS_MASK, 0)
+        self.assertNotEquals(gtk.gdk.BUTTON_PRESS_MASK, -256)
+        self.assertNotEquals(gtk.gdk.BUTTON_PRESS_MASK, gtk.gdk.BUTTON_RELEASE_MASK)
 
-        self.assertEquals(gdk.EventMask.__bases__[0], GFlags)
-        self.assertEquals(len(gdk.EventMask.__flags_values__), 22)
+        self.assertEquals(gtk.gdk.EventMask.__bases__[0], GFlags)
+        self.assertEquals(len(gtk.gdk.EventMask.__flags_values__), 22)
 
     def testComparisionWarning(self):
         warnings.filterwarnings("error", "", Warning, "", 0)
@@ -125,26 +125,26 @@ class FlagsTest(unittest.TestCase):
         warnings.resetwarnings()
 
     def testFlagOperations(self):
-        a = gdk.BUTTON_PRESS_MASK
-        self.failUnless(isinstance(a, GFlags))
+        a = gtk.gdk.BUTTON_PRESS_MASK
+        self.assertTrue(isinstance(a, GFlags))
         self.assertEquals(a.first_value_name, 'GDK_BUTTON_PRESS_MASK')
         self.assertEquals(a.first_value_nick, 'button-press-mask')
         self.assertEquals(a.value_names, ['GDK_BUTTON_PRESS_MASK'],
                           a.value_names)
         self.assertEquals(a.value_nicks, ['button-press-mask'],
                           a.value_names)
-        b = gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK
-        self.failUnless(isinstance(b, GFlags))
+        b = gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK
+        self.assertTrue(isinstance(b, GFlags))
         self.assertEquals(b.first_value_name, 'GDK_BUTTON_PRESS_MASK')
         self.assertEquals(b.first_value_nick, 'button-press-mask')
         self.assertEquals(b.value_names, ['GDK_BUTTON_PRESS_MASK',
                                           'GDK_BUTTON_RELEASE_MASK'])
         self.assertEquals(b.value_nicks, ['button-press-mask',
                                           'button-release-mask'])
-        c = (gdk.BUTTON_PRESS_MASK |
-             gdk.BUTTON_RELEASE_MASK |
-             gdk.ENTER_NOTIFY_MASK)
-        self.failUnless(isinstance(c, GFlags))
+        c = (gtk.gdk.BUTTON_PRESS_MASK |
+             gtk.gdk.BUTTON_RELEASE_MASK |
+             gtk.gdk.ENTER_NOTIFY_MASK)
+        self.assertTrue(isinstance(c, GFlags))
         self.assertEquals(c.first_value_name, 'GDK_BUTTON_PRESS_MASK')
         self.assertEquals(c.first_value_nick, 'button-press-mask')
         self.assertEquals(c.value_names,
@@ -155,20 +155,20 @@ class FlagsTest(unittest.TestCase):
                           ['button-press-mask',
                            'button-release-mask',
                            'enter-notify-mask'])
-        self.failUnless(int(a))
-        self.assertEquals(int(a), int(gdk.BUTTON_PRESS_MASK))
-        self.failUnless(int(b))
-        self.assertEquals(int(b), (int(gdk.BUTTON_PRESS_MASK) |
-                                   int(gdk.BUTTON_RELEASE_MASK)))
-        self.failUnless(int(c))
-        self.assertEquals(int(c), (int(gdk.BUTTON_PRESS_MASK) |
-                                   int(gdk.BUTTON_RELEASE_MASK) |
-                                   int(gdk.ENTER_NOTIFY_MASK)))
+        self.assertTrue(int(a))
+        self.assertEquals(int(a), int(gtk.gdk.BUTTON_PRESS_MASK))
+        self.assertTrue(int(b))
+        self.assertEquals(int(b), (int(gtk.gdk.BUTTON_PRESS_MASK) |
+                                   int(gtk.gdk.BUTTON_RELEASE_MASK)))
+        self.assertTrue(int(c))
+        self.assertEquals(int(c), (int(gtk.gdk.BUTTON_PRESS_MASK) |
+                                   int(gtk.gdk.BUTTON_RELEASE_MASK) |
+                                   int(gtk.gdk.ENTER_NOTIFY_MASK)))
 
     def testUnsupportedOpertionWarning(self):
         warnings.filterwarnings("error", "", Warning, "", 0)
         try:
-            value = gdk.BUTTON_PRESS_MASK + gdk.BUTTON_RELEASE_MASK
+            value = gtk.gdk.BUTTON_PRESS_MASK + gtk.gdk.BUTTON_RELEASE_MASK
         except Warning:
             pass
         else:
@@ -178,51 +178,51 @@ class FlagsTest(unittest.TestCase):
     def testParamSpec(self):
         props = filter(lambda x: GType.is_a(x.value_type, GFlags),
                        gtk.Table.list_child_properties())
-        self.failUnless(len(props) >= 2)
+        self.assertTrue(len(props) >= 2)
         pspec = props[0]
         klass = pspec.flags_class
         self.assertEquals(klass, gtk.AttachOptions)
-        self.failUnless(hasattr(klass, '__flags_values__'))
-        self.failUnless(isinstance(klass.__flags_values__, dict))
-        self.failUnless(len(klass.__flags_values__) >= 3)
-        self.failUnless(isinstance(pspec.default_value, gtk.AttachOptions))
+        self.assertTrue(hasattr(klass, '__flags_values__'))
+        self.assertTrue(isinstance(klass.__flags_values__, dict))
+        self.assertTrue(len(klass.__flags_values__) >= 3)
+        self.assertTrue(isinstance(pspec.default_value, gtk.AttachOptions))
 
     def testEnumComparision(self):
         enum = gtk.TREE_VIEW_DROP_BEFORE
         self.assertEquals(enum, 0)
-        self.failUnless(not enum == 10)
-        self.failUnless(not enum != 0)
+        self.assertTrue(not enum == 10)
+        self.assertTrue(not enum != 0)
         self.assertNotEquals(enum, 10)
-        self.failUnless(not enum < 0)
-        self.failUnless(enum < 10)
-        self.failUnless(not enum > 0)
-        self.failUnless(not enum > 10)
-        self.failUnless(enum >= 0)
-        self.failUnless(not enum >= 10)
-        self.failUnless(enum <= 0)
-        self.failUnless(enum <= 10)
+        self.assertTrue(not enum < 0)
+        self.assertTrue(enum < 10)
+        self.assertTrue(not enum > 0)
+        self.assertTrue(not enum > 10)
+        self.assertTrue(enum >= 0)
+        self.assertTrue(not enum >= 10)
+        self.assertTrue(enum <= 0)
+        self.assertTrue(enum <= 10)
 
     def testFlagComparision(self):
-        flag = gdk.EXPOSURE_MASK
+        flag = gtk.gdk.EXPOSURE_MASK
         self.assertEquals(flag, 2)
-        self.failUnless(not flag == 10)
-        self.failUnless(not flag != 2)
+        self.assertTrue(not flag == 10)
+        self.assertTrue(not flag != 2)
         self.assertNotEquals(flag, 10)
-        self.failUnless(not flag < 2)
-        self.failUnless(flag < 10)
-        self.failUnless(not flag > 2)
-        self.failUnless(not flag > 10)
-        self.failUnless(flag >= 2)
-        self.failUnless(not flag >= 10)
-        self.failUnless(flag <= 2)
-        self.failUnless(flag <= 10)
+        self.assertTrue(not flag < 2)
+        self.assertTrue(flag < 10)
+        self.assertTrue(not flag > 2)
+        self.assertTrue(not flag > 10)
+        self.assertTrue(flag >= 2)
+        self.assertTrue(not flag >= 10)
+        self.assertTrue(flag <= 2)
+        self.assertTrue(flag <= 10)
 
     def testFlagsProperty(self):
         default = PObject.props.flags.default_value
-        self.failUnless(isinstance(default, gtk.AttachOptions))
+        self.assertTrue(isinstance(default, gtk.AttachOptions))
         self.assertEqual(default, gtk.EXPAND)
         default = PObject.props.flags2.default_value
-        self.failUnless(isinstance(default, gtk.AttachOptions))
+        self.assertTrue(isinstance(default, gtk.AttachOptions))
         self.assertEqual(default, gtk.EXPAND)
 
 if __name__ == '__main__':
diff --git a/tests/test_liststore.py b/tests/test_liststore.py
index 87dd594..c2d03ed 100644
--- a/tests/test_liststore.py
+++ b/tests/test_liststore.py
@@ -24,13 +24,13 @@ class ListStoreTest(unittest.TestCase):
 
     def testSetDefaultSortFunc(self):
         store = gtk.ListStore(int)
-        self.failIf(store.has_default_sort_func())
+        self.assertFalse(store.has_default_sort_func())
         store.set_default_sort_func(lambda x: None)
         store.set_sort_column_id(0, gtk.SORT_ASCENDING)
 
-        self.failUnless(store.has_default_sort_func())
+        self.assertTrue(store.has_default_sort_func())
         store.set_default_sort_func(None)
-        self.failIf(store.has_default_sort_func())
+        self.assertFalse(store.has_default_sort_func())
 
     # Two tests for bug 537459.  Since it is a memory corruption, we
     # use a large loop count hoping to trigger a segfault.



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