diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | tests/common.py | 6 | ||||
-rw-r--r-- | tests/test_conversion.py | 2 | ||||
-rw-r--r-- | tests/test_enum.py | 35 | ||||
-rw-r--r-- | tests/test_interface.py | 9 | ||||
-rw-r--r-- | tests/test_option.py | 22 | ||||
-rw-r--r-- | tests/test_source.py | 9 | ||||
-rw-r--r-- | tests/test_subprocess.py | 6 | ||||
-rw-r--r-- | tests/test_subtype.py | 17 | ||||
-rw-r--r-- | tests/test_thread.py | 9 | ||||
-rw-r--r-- | tests/test_unknown.py | 8 |
11 files changed, 73 insertions, 65 deletions
@@ -1,5 +1,20 @@ 2008-07-26 Johan Dahlin <johan@gnome.org> + * tests/common.py: + * tests/test_conversion.py: + * tests/test_enum.py: + * tests/test_interface.py: + * tests/test_option.py: + * tests/test_source.py: + * tests/test_subprocess.py: + * tests/test_subtype.py: + * tests/test_thread.py: + * tests/test_unknown.py: + Run pyflakes on the testsuite, remove unused imports + and reorganize others. + +2008-07-26 Johan Dahlin <johan@gnome.org> + * glib/glibmodule.c (pyglib_register_constants), (init_glib): * gobject/__init__.py: * gobject/gobjectmodule.c (init_gobject): diff --git a/tests/common.py b/tests/common.py index fe7940f6..d41b9f22 100644 --- a/tests/common.py +++ b/tests/common.py @@ -42,11 +42,7 @@ def importModule(module, directory, name=None): except ImportError, e: raise SystemExit('%s could not be imported: %s' % (origName, e)) - if hasattr(obj, '__file__'): - location = obj.__file__ - else: - package = __import__(fromlist) - location = os.path.join(package.__file__, name) + location = obj.__file__ current = os.getcwd() expected = os.path.abspath(os.path.join(current, location)) diff --git a/tests/test_conversion.py b/tests/test_conversion.py index d3aee722..30d29df8 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -1,7 +1,5 @@ # -*- Mode: Python -*- -import sys - import unittest from common import gtk, gobject diff --git a/tests/test_enum.py b/tests/test_enum.py index 41d72a25..f4d6bef3 100644 --- a/tests/test_enum.py +++ b/tests/test_enum.py @@ -2,19 +2,20 @@ import pickle import unittest import warnings -import gobject -from gobject import GEnum, GFlags, GObject, GType, PARAM_READWRITE -from common import gobject, atk, pango, gtk, gdk +# FIXME: Do not import this +from common import gobject, atk, gtk, gdk -class PObject(GObject): + +class PObject(gobject.GObject): enum = gobject.property(type=gtk.WindowType, default=gtk.WINDOW_TOPLEVEL) enum2 = gobject.property(type=gtk.WindowType, default=int(gtk.WINDOW_TOPLEVEL)) flags = gobject.property(type=gtk.AttachOptions, default=gtk.EXPAND) flags2 = gobject.property(type=gtk.AttachOptions, default=int(gtk.EXPAND)) + class EnumTest(unittest.TestCase): def testEnums(self): - self.failUnless(issubclass(GEnum, int)) + self.failUnless(issubclass(gobject.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)) @@ -52,24 +53,24 @@ class EnumTest(unittest.TestCase): self.failUnless('WINDOW_TOPLEVEL' in repr(wtype)) def testAtkObj(self): - obj = atk.NoOpObject(GObject()) + obj = atk.NoOpObject(gobject.GObject()) self.assertEquals(obj.get_role(), atk.ROLE_INVALID) def testGParam(self): win = gtk.Window() - enums = filter(lambda x: GType.is_a(x.value_type, GEnum), + enums = filter(lambda x: gobject.GType.is_a(x.value_type, gobject.GEnum), gobject.list_properties(win)) self.failUnless(enums) enum = enums[0] self.failUnless(hasattr(enum, 'enum_class')) - self.failUnless(issubclass(enum.enum_class, GEnum)) + self.failUnless(issubclass(enum.enum_class, gobject.GEnum)) def testWeirdEnumValues(self): self.assertEquals(int(gdk.NOTHING), -1) self.assertEquals(int(gdk.BUTTON_PRESS), 4) def testParamSpec(self): - props = filter(lambda prop: GType.is_a(prop.value_type, GEnum), + props = filter(lambda prop: gobject.GType.is_a(prop.value_type, gobject.GEnum), gobject.list_properties(gtk.Window)) self.failUnless(len(props)>= 6) props = filter(lambda prop: prop.name == 'type', props) @@ -84,7 +85,7 @@ class EnumTest(unittest.TestCase): def testOutofBounds(self): val = gtk.icon_size_register('fake', 24, 24) - self.failUnless(isinstance(val, gobject.GEnum)) + self.failUnless(isinstance(val, gobject.gobject.GEnum)) self.assertEquals(int(val), 7) self.failUnless('7' in repr(val)) self.failUnless('GtkIconSize' in repr(val)) @@ -99,7 +100,7 @@ class EnumTest(unittest.TestCase): def testPickling(self): values = [getattr(gtk, name) for name in dir(gtk) - if isinstance(getattr(gtk, name), gobject.GEnum)] + if isinstance(getattr(gtk, name), gobject.gobject.GEnum)] for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1): for value in values: self.assertEqual(value, pickle.loads(pickle.dumps(value, protocol))) @@ -107,7 +108,7 @@ class EnumTest(unittest.TestCase): class FlagsTest(unittest.TestCase): def testFlags(self): - self.failUnless(issubclass(GFlags, int)) + self.failUnless(issubclass(gobject.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) @@ -115,7 +116,7 @@ class FlagsTest(unittest.TestCase): self.assertNotEquals(gdk.BUTTON_PRESS_MASK, -256) self.assertNotEquals(gdk.BUTTON_PRESS_MASK, gdk.BUTTON_RELEASE_MASK) - self.assertEquals(gdk.EventMask.__bases__[0], GFlags) + self.assertEquals(gdk.EventMask.__bases__[0], gobject.GFlags) self.assertEquals(len(gdk.EventMask.__flags_values__), 22) def testComparisionWarning(self): @@ -130,7 +131,7 @@ class FlagsTest(unittest.TestCase): def testFlagOperations(self): a = gdk.BUTTON_PRESS_MASK - self.failUnless(isinstance(a, GFlags)) + self.failUnless(isinstance(a, gobject.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'], @@ -138,7 +139,7 @@ class FlagsTest(unittest.TestCase): 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)) + self.failUnless(isinstance(b, gobject.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', @@ -148,7 +149,7 @@ class FlagsTest(unittest.TestCase): c = (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.ENTER_NOTIFY_MASK) - self.failUnless(isinstance(c, GFlags)) + self.failUnless(isinstance(c, gobject.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, @@ -180,7 +181,7 @@ class FlagsTest(unittest.TestCase): warnings.resetwarnings() def testParamSpec(self): - props = filter(lambda x: GType.is_a(x.value_type, GFlags), + props = filter(lambda x: gobject.GType.is_a(x.value_type, gobject.GFlags), gtk.container_class_list_child_properties(gtk.Table)) self.failUnless(len(props) >= 2) pspec = props[0] diff --git a/tests/test_interface.py b/tests/test_interface.py index 4413d64d..d9597917 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -1,13 +1,11 @@ import unittest -import testmodule from common import gobject, testhelper -from gobject import GObject, GInterface -import gobject GUnknown = gobject.type_from_name("TestUnknown") Unknown = GUnknown.pytype + class MyUnknown(Unknown, testhelper.Interface): some_property = gobject.property(type=str) @@ -18,19 +16,18 @@ class MyUnknown(Unknown, testhelper.Interface): def do_iface_method(self): self.called = True Unknown.do_iface_method(self) - gobject.type_register(MyUnknown) + class MyObject(gobject.GObject, testhelper.Interface): some_property = gobject.property(type=str) def __init__(self): - GObject.__init__(self) + gobject.GObject.__init__(self) self.called = False def do_iface_method(self): self.called = True - gobject.type_register(MyObject) diff --git a/tests/test_option.py b/tests/test_option.py index 988ce520..dcafc0a2 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -1,20 +1,18 @@ #!/usr/bin/env python -import optparse import unittest import sys from StringIO import StringIO -from gobject import option - -from common import gobject +from gobject.option import OptionParser, OptionGroup, OptionValueError, \ + make_option, BadOptionError class TestOption(unittest.TestCase): EXCEPTION_MESSAGE = "This callback fails" def setUp(self): - self.parser = option.OptionParser("NAMES...", + self.parser = OptionParser("NAMES...", description="Option unit test") self.parser.add_option("-t", "--test", help="Unit test option", action="store_false", dest="test", default=True) @@ -27,18 +25,18 @@ class TestOption(unittest.TestCase): def option_callback(option, opt, value, parser): raise StandardError(self.EXCEPTION_MESSAGE) - group = option.OptionGroup( + group = OptionGroup( "unittest", "Unit test options", "Show all unittest options", option_list = [ - option.make_option("-f", "-u", "--file", "--unit-file", + make_option("-f", "-u", "--file", "--unit-file", type="filename", dest="unit_file", help="Unit test option"), - option.make_option("--test-integer", + make_option("--test-integer", type="int", dest="test_integer", help="Unit integer option"), - option.make_option("--callback-failure-test", + make_option("--callback-failure-test", action="callback", callback=option_callback, dest="test_integer", @@ -89,16 +87,16 @@ class TestOption(unittest.TestCase): def testOptionValueError(self): self._create_group() - self.assertRaises(option.OptionValueError, self.parser.parse_args, + self.assertRaises(OptionValueError, self.parser.parse_args, ["test_option.py", "--test-integer=text"]) def testBadOptionError(self): - self.assertRaises(option.BadOptionError, + self.assertRaises(BadOptionError, self.parser.parse_args, ["test_option.py", "--unknwon-option"]) def testOptionGroupConstructor(self): - self.assertRaises(TypeError, option.OptionGroup) + self.assertRaises(TypeError, OptionGroup) def testStandardError(self): self._create_group() diff --git a/tests/test_source.py b/tests/test_source.py index a5118a9c..abe2f695 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -1,12 +1,9 @@ #!/usr/bin/env python -import exceptions -import os -import sys -import select import unittest -from common import glib, gobject +from common import glib + class Idle(glib.Idle): def __init__(self, loop): @@ -18,6 +15,7 @@ class Idle(glib.Idle): self.count += 1 return True + class MySource(glib.Source): def __init__(self): glib.Source.__init__(self) @@ -31,6 +29,7 @@ class MySource(glib.Source): def dispatch(self, callback, args): return callback(*args) + class TestSource(unittest.TestCase): def timeout_callback(self, loop): loop.quit() diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 84950104..1522edb9 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -1,10 +1,10 @@ # -*- Mode: Python -*- -import gc -import unittest import sys +import unittest + +from common import glib -from common import glib, gobject class TestProcess(unittest.TestCase): diff --git a/tests/test_subtype.py b/tests/test_subtype.py index a77ea4e1..b74c4ff7 100644 --- a/tests/test_subtype.py +++ b/tests/test_subtype.py @@ -1,29 +1,32 @@ import unittest import weakref import gc -import sys import testmodule from common import gobject, testhelper -from gobject import GObject, GInterface, GObjectMeta + +# FIXME: do not import gtk import gtk -class _ClassInittableMetaType(GObjectMeta): + +class _ClassInittableMetaType(gobject.GObjectMeta): def __init__(cls, name, bases, namespace): super(_ClassInittableMetaType, cls).__init__(name, bases, namespace) cls.__class_init__(namespace) + class ClassInittableObject(object): __metaclass__ = _ClassInittableMetaType def __class_init__(cls, namespace): pass __class_init__ = classmethod(__class_init__) + class TestSubType(unittest.TestCase): def testSubType(self): - t = type('testtype', (GObject, GInterface), {}) - self.failUnless(issubclass(t, GObject)) - self.failUnless(issubclass(t, GInterface)) + t = type('testtype', (gobject.GObject, gobject.GInterface), {}) + self.failUnless(issubclass(t, gobject.GObject)) + self.failUnless(issubclass(t, gobject.GInterface)) def testGObject(self): label = gobject.GObject() @@ -230,7 +233,7 @@ class TestSubType(unittest.TestCase): disposed_calls = [] def on_dispose(): disposed_calls.append(None) - gobj = GObject() + gobj = gobject.GObject() gobj.set_data('tmp', CallInDel(on_dispose)) del gobj assert len(disposed_calls) == 1 diff --git a/tests/test_thread.py b/tests/test_thread.py index 9f77f0bf..09ad0745 100644 --- a/tests/test_thread.py +++ b/tests/test_thread.py @@ -1,11 +1,12 @@ -import os import unittest from common import glib, testhelper -main = glib.MainLoop() class TestThread(unittest.TestCase): + def setUp(self): + self.main = glib.MainLoop() + def from_thread_cb(self, test, enum): assert test == self.obj assert int(enum) == 0 @@ -19,7 +20,7 @@ class TestThread(unittest.TestCase): def testExtensionModule(self): glib.idle_add(self.idle_cb) glib.timeout_add(50, self.timeout_cb) - main.run() + self.main.run() def timeout_cb(self): - main.quit() + self.main.quit() diff --git a/tests/test_unknown.py b/tests/test_unknown.py index d2ce6de9..d65bb894 100644 --- a/tests/test_unknown.py +++ b/tests/test_unknown.py @@ -1,15 +1,15 @@ import unittest -from gobject import GType, new from common import gobject, testhelper -TestInterface = GType.from_name('TestInterface') +TestInterface = gobject.GType.from_name('TestInterface') + class TestUnknown(unittest.TestCase): def testFoo(self): obj = testhelper.get_unknown() - TestUnknownGType = GType.from_name('TestUnknown') - TestUnknown = new(TestUnknownGType).__class__ + TestUnknownGType = gobject.GType.from_name('TestUnknown') + TestUnknown = gobject.new(TestUnknownGType).__class__ assert isinstance(obj, testhelper.Interface) assert isinstance(obj, TestUnknown) |