diff options
author | Johan Dahlin <johan@src.gnome.org> | 2006-04-02 15:05:57 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2006-04-02 15:05:57 +0000 |
commit | db1cc34d52660412224937180e53e0ee39645422 (patch) | |
tree | 8f88abc435695f49764965e2f734262b9dbf6354 /tests | |
parent | 232911e2425feeddd2aeaea13cda39b618696658 (diff) | |
download | pygtk-db1cc34d52660412224937180e53e0ee39645422.tar.gz |
tests which moved to pygobject
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 35 | ||||
-rw-r--r-- | tests/common.py | 4 | ||||
-rw-r--r-- | tests/test-thread.c | 64 | ||||
-rw-r--r-- | tests/test-thread.h | 22 | ||||
-rw-r--r-- | tests/test-unknown.c | 37 | ||||
-rw-r--r-- | tests/test-unknown.h | 33 | ||||
-rw-r--r-- | tests/test_gtype.py | 67 | ||||
-rw-r--r-- | tests/test_mainloop.py | 53 | ||||
-rw-r--r-- | tests/test_properties.py | 112 | ||||
-rw-r--r-- | tests/test_signal.py | 121 | ||||
-rw-r--r-- | tests/test_source.py | 66 | ||||
-rw-r--r-- | tests/test_subprocess.py | 26 | ||||
-rw-r--r-- | tests/test_subtype.py | 78 | ||||
-rw-r--r-- | tests/test_thread.py | 23 | ||||
-rw-r--r-- | tests/test_unknown.py | 15 | ||||
-rw-r--r-- | tests/testhelpermodule.c | 131 |
16 files changed, 2 insertions, 885 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 4f2db18c..7b450ad3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,22 +1,4 @@ -INCLUDES = \ - $(PYTHON_INCLUDES) \ - $(PYGOBJECT_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(PANGO_CFLAGS) \ - $(ATK_CFLAGS) \ - $(GTK_CFLAGS) - -EXTRA_DIST = $(tests) common.py runtests.py test-thread.h test-unknown.h testmodule.py leak.glade - -noinst_LTLIBRARIES = testhelper.la -linked_LIBS = testhelper.la - -testhelper_la_LDFLAGS = -module -avoid-version -testhelper_la_LIBADD = $(GLIB_LIBS) -testhelper_la_SOURCES = \ - testhelpermodule.c \ - test-thread.c \ - test-unknown.c +EXTRA_DIST = $(tests) common.py runtests.py testmodule.py leak.glade tests = \ test_glade.py \ @@ -24,21 +6,8 @@ tests = \ test_dialog.py \ test_enum.py \ test_gdk.py \ - test_gtype.py \ - test_mainloop.py \ test_radiobutton.py \ - test_properties.py \ - test_signal.py \ - test_subprocess.py \ - test_subtype.py \ - test_gdkevent.py \ - test_unknown.py \ - test_textview.py \ - test_source.py - -# This is a hack to make sure a shared library is built -testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES) - $(LINK) -rpath $(pkgpyexecdir) $(testhelper_la_LDFLAGS) $(testhelper_la_OBJECTS) $(testhelper_la_LIBADD) $(LIBS) + test_textview.py check-local: $(top_srcdir)/gtk/__init__.py @if test "$(top_builddir)" != "$(top_srcdir)"; then \ diff --git a/tests/common.py b/tests/common.py index e9704611..d2785e1c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -13,8 +13,6 @@ def importModules(buildDir, srcDir): sys.path.insert(0, os.path.join(buildDir, 'gobject')) # _gtk, keysyms, glade sys.path.insert(0, os.path.join(buildDir, 'gtk')) - # testhelper - sys.path.insert(0, os.path.join(buildDir, 'tests')) sys.argv.append('--g-fatal-warnings') import ltihooks @@ -28,8 +26,6 @@ def importModules(buildDir, srcDir): except ImportError: glade = None - testhelper = importModule('testhelper', '.') - ltihooks.uninstall() del ltihooks diff --git a/tests/test-thread.c b/tests/test-thread.c deleted file mode 100644 index 0f5b9096..00000000 --- a/tests/test-thread.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "test-thread.h" - -enum -{ - /* methods */ - SIGNAL_EMIT_SIGNAL, - SIGNAL_FROM_THREAD, - LAST_SIGNAL -}; - -static guint test_thread_signals[LAST_SIGNAL] = { 0 }; - -typedef enum { - TEST_THREAD_A, - TEST_THREAD_B -} ThreadEnumType; - -static GType -test_thread_enum_get_type (void) -{ - static GType enum_type = 0; - static GEnumValue enum_values[] = { - {TEST_THREAD_A, "TEST_THREAD_A", "a as in apple"}, - {0, NULL, NULL}, - }; - - if (!enum_type) { - enum_type = - g_enum_register_static ("TestThreadEnum", enum_values); - } - return enum_type; -} - -G_DEFINE_TYPE(TestThread, test_thread, G_TYPE_OBJECT); - -static void -other_thread_cb (TestThread *self) -{ - g_signal_emit_by_name (self, "from-thread", 0, NULL); - g_thread_exit (0); -} - -static void -test_thread_emit_signal (TestThread *self) -{ - self->thread = g_thread_create ((GThreadFunc)other_thread_cb, - self, TRUE, NULL); -} - -static void test_thread_init (TestThread *self) {} -static void test_thread_class_init (TestThreadClass *klass) -{ - test_thread_signals[SIGNAL_EMIT_SIGNAL] = - g_signal_new ("emit-signal", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (TestThreadClass, emit_signal), - NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - test_thread_signals[SIGNAL_FROM_THREAD] = - g_signal_new ("from-thread", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (TestThreadClass, from_thread), - NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, - test_thread_enum_get_type ()); - - klass->emit_signal = test_thread_emit_signal; -} diff --git a/tests/test-thread.h b/tests/test-thread.h deleted file mode 100644 index db12fe43..00000000 --- a/tests/test-thread.h +++ /dev/null @@ -1,22 +0,0 @@ -#include <glib-object.h> - -typedef struct { - GObject parent; - GThread *thread; -} TestThread; - -typedef struct { - GObjectClass parent_class; - void (*emit_signal) (TestThread *sink); - void (*from_thread) (TestThread *sink); -} TestThreadClass; - -GType test_thread_get_type (void); - -#define TEST_TYPE_THREAD (test_thread_get_type()) -#define TEST_THREAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_THREAD, TestTHREAD)) -#define TEST_THREAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_THREAD, TestTHREADClass)) -#define TEST_IS_THREAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_THREAD)) -#define TEST_IS_THREAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_THREAD)) -#define TEST_THREAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_THREAD, TestTHREADClass)) - diff --git a/tests/test-unknown.c b/tests/test-unknown.c deleted file mode 100644 index 36a99041..00000000 --- a/tests/test-unknown.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "test-unknown.h" - -G_DEFINE_TYPE_WITH_CODE (TestUnknown, test_unknown, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TEST_TYPE_INTERFACE, NULL)); - -static void test_unknown_init (TestUnknown *self) {} -static void test_unknown_class_init (TestUnknownClass *klass) {} - -GType -test_interface_get_type (void) -{ - static GType gtype = 0; - - if (!gtype) - { - static const GTypeInfo info = - { - sizeof (TestInterface), /* class_size */ - NULL, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL - }; - - gtype = - g_type_register_static (G_TYPE_INTERFACE, "TestInterface", - &info, 0); - - g_type_interface_add_prerequisite (gtype, G_TYPE_OBJECT); - } - - return gtype; -} diff --git a/tests/test-unknown.h b/tests/test-unknown.h deleted file mode 100644 index 7e5dde26..00000000 --- a/tests/test-unknown.h +++ /dev/null @@ -1,33 +0,0 @@ -#include <glib-object.h> - -/* TestUnknown */ - -typedef struct { - GObject parent; -} TestUnknown; - -typedef struct { - GObjectClass parent_class; -} TestUnknownClass; - -#define TEST_TYPE_UNKNOWN (test_unknown_get_type()) -#define TEST_UNKNOWN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_UNKNOWN, TestUnknown)) -#define TEST_UNKNOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_UNKNOWN, TestUnknownClass)) -#define TEST_IS_UNKNOWN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_UNKNOWN)) -#define TEST_IS_UNKNOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_UNKNOWN)) -#define TEST_UNKNOWN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_UNKNOWN, TestUnknownClass)) - -GType test_unknown_get_type (void); - -/* TestInterface */ -typedef struct -{ - GTypeInterface g_iface; -} TestInterface; - -#define TEST_TYPE_INTERFACE (test_interface_get_type ()) -#define TEST_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_INTERFACE, TestInterface)) -#define TEST_IS_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_INTERFACE)) -#define TEST_INTERFACE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_INTERFACE, TestInterfaceIface)) - -GType test_interface_get_type (void); diff --git a/tests/test_gtype.py b/tests/test_gtype.py deleted file mode 100644 index eb89a878..00000000 --- a/tests/test_gtype.py +++ /dev/null @@ -1,67 +0,0 @@ -import unittest - -from gobject import GType -from common import gobject, gtk - -class GTypeTest(unittest.TestCase): - def checkType(self, expected, *objects): - # First, double check so we get back what we sent - str = GType(expected).name # pyg_type_from_object - val = GType.from_name(str) # pyg_type_wrapper_new - self.assertEqual(val, expected, - 'got %r while %r was expected' % (val, expected)) - - # Then test the objects - for object in objects: - val = GType.from_name(GType(expected).name) - self.assertEqual(val, expected, - 'got %r while %r was expected' % - (val, expected)) - - def testBool(self): - self.checkType(gobject.TYPE_BOOLEAN, 'gboolean', bool) - - def testInt(self): - self.checkType(gobject.TYPE_INT, 'gint', int) - model = gtk.ListStore(str, int) - iter = model.append() - model.set(iter, 1, 100000000) - - def testInt64(self): - self.checkType(gobject.TYPE_INT64, 'gint64') - - def testUint(self): - self.checkType(gobject.TYPE_UINT, 'guint') - - def testUint64(self): - self.checkType(gobject.TYPE_UINT64, 'guint64') - - def testLong(self): - self.checkType(gobject.TYPE_LONG, 'glong', long) - - def testUlong(self): - self.checkType(gobject.TYPE_ULONG, 'gulong') - - def testDouble(self): - self.checkType(gobject.TYPE_DOUBLE, 'gdouble', float) - - def testFloat(self): - self.checkType(gobject.TYPE_FLOAT, 'gfloat') - - def testPyObject(self): - self.checkType(gobject.TYPE_PYOBJECT, 'GObject', object) - - def testObject(self): - self.checkType(gobject.TYPE_OBJECT, 'PyObject') - - # XXX: Flags, Enums - -class MyObject(gobject.GObject): - __gtype_name__ = 'MyObject' - -class TypeNameTest(unittest.TestCase): - def testTypeName(self): - self.assertEqual(GType(MyObject).name, 'MyObject') - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py deleted file mode 100644 index 44d6937f..00000000 --- a/tests/test_mainloop.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python - -import exceptions -import os -import sys -import select -import unittest - -from common import gobject - -class TestMainLoop(unittest.TestCase): - def testExceptionHandling(self): - pipe_r, pipe_w = os.pipe() - - pid = os.fork() - if pid == 0: - os.close(pipe_w) - select.select([pipe_r], [], []) - os.close(pipe_r) - os._exit(1) - - def child_died(pid, status, loop): - loop.quit() - raise Exception("deadbabe") - - loop = gobject.MainLoop() - gobject.child_watch_add(pid, child_died, loop) - - os.close(pipe_r) - os.write(pipe_w, "Y") - os.close(pipe_w) - - def excepthook(type, value, traceback): - assert type is exceptions.Exception - assert value.args[0] == "deadbabe" - sys.excepthook = excepthook - - got_exception = False - try: - loop.run() - except: - got_exception = True - - # - # The exception should be handled (by printing it) - # immediately on return from child_died() rather - # than here. See bug #303573 - # - sys.excepthook = sys.__excepthook__ - assert not got_exception - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_properties.py b/tests/test_properties.py deleted file mode 100644 index de290bee..00000000 --- a/tests/test_properties.py +++ /dev/null @@ -1,112 +0,0 @@ - -import unittest - -from common import testhelper -from gobject import GObject, GType, new, PARAM_READWRITE, \ - PARAM_CONSTRUCT, PARAM_CONSTRUCT_ONLY, TYPE_UINT64 - -class PropertyObject(GObject): - __gproperties__ = { - 'normal': (str, 'blurb', 'description', 'default', - PARAM_READWRITE), - 'construct': (str, 'blurb', 'description', 'default', - PARAM_READWRITE|PARAM_CONSTRUCT), - 'construct-only': (str, 'blurb', 'description', 'default', - PARAM_READWRITE|PARAM_CONSTRUCT_ONLY), - 'uint64': (TYPE_UINT64, 'blurb', 'description', 0, 10, 0, - PARAM_READWRITE), - } - - def __init__(self): - GObject.__init__(self) - self._value = 'default' - self._construct_only = None - self._construct = None - self._uint64 = 0L - - def do_get_property(self, pspec): - if pspec.name == 'normal': - return self._value - elif pspec.name == 'construct': - return self._construct - elif pspec.name == 'construct-only': - return self._construct_only - elif pspec.name == 'uint64': - return self._uint64 - else: - raise AssertionError - - def do_set_property(self, pspec, value): - if pspec.name == 'normal': - self._value = value - elif pspec.name == 'construct': - self._construct = value - elif pspec.name == 'construct-only': - self._construct_only = value - elif pspec.name == 'uint64': - self._uint64 = value - else: - raise AssertionError - -class TestProperties(unittest.TestCase): - def testGetSet(self): - obj = PropertyObject() - obj.props.normal = "value" - self.assertEqual(obj.props.normal, "value") - - def testListWithInstance(self): - obj = PropertyObject() - self.failUnless(hasattr(obj.props, "normal")) - - def testListWithoutInstance(self): - self.failUnless(hasattr(PropertyObject.props, "normal")) - - def testSetNoInstance(self): - def set(obj): - obj.props.normal = "foobar" - - self.assertRaises(TypeError, set, PropertyObject) - - def testIterator(self): - for obj in (PropertyObject.props, PropertyObject().props): - for pspec in obj: - gtype = GType(pspec) - self.assertEqual(gtype.parent.name, 'GParam') - self.failUnless(pspec.name in ['normal', - 'construct', - 'construct-only', - 'uint64']) - self.assertEqual(len(obj), 4) - - def testNormal(self): - obj = new(PropertyObject, normal="123") - self.assertEqual(obj.props.normal, "123") - obj.set_property('normal', '456') - self.assertEqual(obj.props.normal, "456") - obj.props.normal = '789' - self.assertEqual(obj.props.normal, "789") - - def testConstruct(self): - obj = new(PropertyObject, construct="123") - self.assertEqual(obj.props.construct, "123") - obj.set_property('construct', '456') - self.assertEqual(obj.props.construct, "456") - obj.props.construct = '789' - self.assertEqual(obj.props.construct, "789") - - def testConstructOnly(self): - obj = new(PropertyObject, construct_only="123") - self.assertEqual(obj.props.construct_only, "123") - self.assertRaises(TypeError, - setattr, obj.props, 'construct_only', '456') - self.assertRaises(TypeError, - obj.set_property, 'construct-only', '456') - - def testUint64(self): - obj = new(PropertyObject) - self.assertEqual(obj.props.uint64, 0) - obj.props.uint64 = 1L - self.assertEqual(obj.props.uint64, 1L) - obj.props.uint64 = 1 - self.assertEqual(obj.props.uint64, 1L) - diff --git a/tests/test_signal.py b/tests/test_signal.py deleted file mode 100644 index 5513f2f1..00000000 --- a/tests/test_signal.py +++ /dev/null @@ -1,121 +0,0 @@ -# -*- Mode: Python -*- - -import gc -import unittest - -from common import gobject, gtk - -class C(gobject.GObject): - __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_INT,)) } - def do_my_signal(self, arg): - self.arg = arg - -class D(C): - def do_my_signal(self, arg2): - self.arg2 = arg2 - C.do_my_signal(self, arg2) - -class TestChaining(unittest.TestCase): - def setUp(self): - self.inst = C() - self.inst.connect("my_signal", self.my_signal_handler_cb, 1, 2, 3) - - def my_signal_handler_cb(self, *args): - assert len(args) == 5 - assert isinstance(args[0], C) - assert args[0] == self.inst - - assert isinstance(args[1], int) - assert args[1] == 42 - - assert args[2:] == (1, 2, 3) - - def testChaining(self): - self.inst.emit("my_signal", 42) - assert self.inst.arg == 42 - - def testChaining(self): - inst2 = D() - inst2.emit("my_signal", 44) - assert inst2.arg == 44 - assert inst2.arg2 == 44 - -# This is for bug 153718 -class TestGSignalsError(unittest.TestCase): - def testInvalidType(self, *args): - def foo(): - class Foo(gobject.GObject): - __gsignals__ = None - self.assertRaises(TypeError, foo) - gc.collect() - - def testInvalidName(self, *args): - def foo(): - class Foo(gobject.GObject): - __gsignals__ = {'not-exists' : 'override'} - self.assertRaises(TypeError, foo) - gc.collect() - -class TestGPropertyError(unittest.TestCase): - def testInvalidType(self, *args): - def foo(): - class Foo(gobject.GObject): - __gproperties__ = None - self.assertRaises(TypeError, foo) - gc.collect() - - def testInvalidName(self, *args): - def foo(): - class Foo(gobject.GObject): - __gproperties__ = { None: None } - - self.assertRaises(TypeError, foo) - gc.collect() - - -class DrawingArea(gtk.DrawingArea): - __gsignals__ = { 'my-activate': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ()) , - 'my-adjust': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gtk.Adjustment, gtk.Adjustment)) } - def __init__(self): - gtk.DrawingArea.__init__(self) - self.activated = False - self.adjusted = False - - def do_my_activate(self): - self.activated = True - - def do_my_adjust(self, hadj, vadj): - self.adjusted = True - -DrawingArea.set_activate_signal('my-activate') -DrawingArea.set_set_scroll_adjustments_signal('my-adjust') - -class TestOldStyleOverride(unittest.TestCase): - def testActivate(self): - b = DrawingArea() - self.assertEqual(b.activated, False) - b.activate() - self.assertEqual(b.activated, True) - - def testSetScrollAdjustment(self): - b = DrawingArea() - self.assertEqual(b.adjusted, False) - b.set_scroll_adjustments(gtk.Adjustment(), gtk.Adjustment()) - self.assertEqual(b.adjusted, True) - -class TestList(unittest.TestCase): - def testListObject(self): - self.assertEqual(gobject.signal_list_names(C), ('my-signal',)) - - def testListInterface(self): - signals = gobject.signal_list_names(gtk.Editable) - self.failUnless('changed' in signals) - self.failUnless('insert-text' in signals) - self.failUnless('delete-text' in signals) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_source.py b/tests/test_source.py deleted file mode 100644 index 5e0f01b7..00000000 --- a/tests/test_source.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python - -import exceptions -import os -import sys -import select -import unittest - -from common import gobject - -class Idle(gobject.Idle): - def __init__(self, loop): - gobject.Idle.__init__(self) - self.count = 0 - self.set_callback(self.callback, loop) - - def callback(self, loop): - self.count += 1 - return True - -class MySource(gobject.Source): - def __init__(self): - gobject.Source.__init__(self) - - def prepare(self): - return True, 0 - - def check(self): - return True - - def dispatch(self, callback, args): - return callback(*args) - -class TestSource(unittest.TestCase): - def timeout_callback(self, loop): - loop.quit() - - def my_callback(self, loop): - self.pos += 1 - return True - - def setup_timeout(self, loop): - timeout = gobject.Timeout(500) - timeout.set_callback(self.timeout_callback, loop) - timeout.attach() - - def testSources(self): - loop = gobject.MainLoop() - - self.setup_timeout(loop) - - idle = Idle(loop) - idle.attach() - - self.pos = 0 - - m = MySource() - m.set_callback(self.my_callback, loop) - m.attach() - - loop.run() - - assert self.pos >= 0 and idle.count >= 0 - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py deleted file mode 100644 index 189327df..00000000 --- a/tests/test_subprocess.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Mode: Python -*- - -import gc -import unittest -import sys - -from common import gobject - -class TestProcess(unittest.TestCase): - - def _child_watch_cb(self, pid, condition, data): - self.data = data - self.loop.quit() - - def testChildWatch(self): - self.data = None - self.loop = gobject.MainLoop() - argv = [sys.executable, '-c', 'import sys'] - pid, stdin, stdout, stderr = gobject.spawn_async( - argv, flags=gobject.SPAWN_DO_NOT_REAP_CHILD) - gobject.child_watch_add(pid, self._child_watch_cb, 12345) - self.loop.run() - self.assertEqual(self.data, 12345) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_subtype.py b/tests/test_subtype.py deleted file mode 100644 index 91a1e71a..00000000 --- a/tests/test_subtype.py +++ /dev/null @@ -1,78 +0,0 @@ -import unittest - -import testmodule -from common import gobject, gtk, testhelper -from gobject import GObject, GInterface - -class TestSubType(unittest.TestCase): - def testSubType(self): - t = type('testtype', (GObject, GInterface), {}) - self.failUnless(issubclass(t, GObject)) - self.failUnless(issubclass(t, GInterface)) - t = type('testtype2', (GObject, gtk.TreeModel), {}) - self.failUnless(issubclass(t, GObject)) - self.failUnless(issubclass(t, gtk.TreeModel)) - - def testTpBasicSize(self): - self.assertEqual(GObject.__basicsize__, - gtk.Widget.__basicsize__) - - self.assertEqual(GInterface.__basicsize__, - gtk.TreeModel.__basicsize__) - - def testLabel(self): - label = gtk.Label() - self.assertEqual(label.__grefcount__, 1) - label = gobject.new(gtk.Label) - self.assertEqual(label.__grefcount__, 1) - - def testPythonSubclass(self): - label = testmodule.PyLabel() - self.assertEqual(label.__grefcount__, 1) - self.assertEqual(label.props.label, "hello") - label = gobject.new(testmodule.PyLabel) - self.assertEqual(label.__grefcount__, 1) - self.assertEqual(label.props.label, "hello") - - def testCPyCSubclassing(self): - obj = testhelper.create_test_type() - self.assertEqual(obj.__grefcount__, 1) - refcount = testhelper.test_g_object_new() - self.assertEqual(refcount, 2) - - def testMassiveGtkSubclassing(self): - for name, cls in [(name, getattr(gtk, name)) for name in dir(gtk)]: - ## Skip some deprecated types - if name in ['CTree', '_gobject']: - continue - try: - if not issubclass(cls, gobject.GObject): - continue - except TypeError: # raised by issubclass if cls is not a class - continue - subname = name + "PyGtkTestSubclass" - sub = type(subname, (cls,), {'__gtype_name__': subname }) - - def testGtkWindowObjNewRefcount(self): - foo = gobject.new(gtk.Window) - self.assertEqual(foo.__grefcount__, 2) - - def testGtkWindowFactoryRefcount(self): - foo = gtk.Window() - self.assertEqual(foo.__grefcount__, 2) - - def testPyWindowObjNewRefcount(self): - PyWindow = type('PyWindow', (gtk.Window,), dict(__gtype_name__='PyWindow1')) - foo = gobject.new(PyWindow) - self.assertEqual(foo.__grefcount__, 2) - - def testGtkWindowFactoryRefcount(self): - PyWindow = type('PyWindow', (gtk.Window,), dict(__gtype_name__='PyWindow2')) - foo = PyWindow() - self.assertEqual(foo.__grefcount__, 2) - - def testRegisterArgNotType(self): - self.assertRaises(TypeError, gobject.type_register, 1) - - def testGObjectNewError(self): - self.assertRaises(TypeError, gobject.new, gtk.Label, text='foo') diff --git a/tests/test_thread.py b/tests/test_thread.py deleted file mode 100644 index 647783ac..00000000 --- a/tests/test_thread.py +++ /dev/null @@ -1,23 +0,0 @@ -import os -import unittest - -from common import gobject, gtk, testhelper - -class TestThread(unittest.TestCase): - def from_thread_cb(self, test, enum): - assert test == self.obj - assert int(enum) == 0 - assert type(enum) != int - - def idle_cb(self): - self.obj = testhelper.get_test_thread() - self.obj.connect('from-thread', self.from_thread_cb) - self.obj.emit('emit-signal') - - def testExtensionModule(self): - gobject.idle_add(self.idle_cb) - gobject.timeout_add(50, self.timeout_cb) - gtk.main() - - def timeout_cb(self): - gtk.main_quit() diff --git a/tests/test_unknown.py b/tests/test_unknown.py deleted file mode 100644 index 49e8c404..00000000 --- a/tests/test_unknown.py +++ /dev/null @@ -1,15 +0,0 @@ - -import unittest -from gobject import GType, new - -from common import gobject, testhelper - -TestInterface = GType.from_name('TestInterface') - -class TestUnknown(unittest.TestCase): - def testFoo(self): - obj = testhelper.get_unknown() - TestUnknownGType = GType.from_name('TestUnknown') - TestUnknown = new(TestUnknownGType).__class__ - assert isinstance(obj, testhelper.Interface) - assert isinstance(obj, TestUnknown) diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c deleted file mode 100644 index 76847210..00000000 --- a/tests/testhelpermodule.c +++ /dev/null @@ -1,131 +0,0 @@ -#include "pygobject.h" -#include <gobject/gmarshal.h> - -#include "test-thread.h" -#include "test-unknown.h" - -GType -test_type_get_type(void) -{ - static GType gtype = 0; - GType parent_type; - - if (gtype == 0) - { - GTypeInfo *type_info; - GTypeQuery query; - - parent_type = g_type_from_name("PyLabel"); - if (parent_type == 0) - g_error("could not get PyLabel from testmodule"); - - type_info = (GTypeInfo *)g_new0(GTypeInfo, 1); - - g_type_query(parent_type, &query); - type_info->class_size = query.class_size; - type_info->instance_size = query.instance_size; - - gtype = g_type_register_static(parent_type, - "TestType", type_info, 0); - if (!gtype) - g_error("Could not register TestType"); - } - - return gtype; -} - -#define TYPE_TEST (test_type_get_type()) - -static PyObject * -_wrap_get_test_thread (PyObject * self) -{ - GObject *obj; - - test_thread_get_type(); - g_assert (g_type_is_a (TEST_TYPE_THREAD, G_TYPE_OBJECT)); - obj = g_object_new (TEST_TYPE_THREAD, NULL); - g_assert (obj != NULL); - - return pygobject_new(obj); -} - -static PyObject * -_wrap_get_unknown (PyObject * self) -{ - GObject *obj; - obj = g_object_new (TEST_TYPE_UNKNOWN, NULL); - return pygobject_new(obj); -} - -static PyObject * -_wrap_create_test_type (PyObject * self) -{ - GObject *obj; - PyObject *rv; - obj = g_object_new(TYPE_TEST, NULL); - rv = pygobject_new(obj); - g_object_unref(obj); - return rv; -} - -static PyObject * -_wrap_test_g_object_new (PyObject * self) -{ - GObject *obj; - PyObject *rv; - - obj = g_object_new(g_type_from_name("PyLabel"), NULL); - rv = PyInt_FromLong(obj->ref_count); /* should be == 2 at this point */ - g_object_unref(obj); - return rv; -} - -static PyMethodDef testhelper_methods[] = { - { "get_test_thread", (PyCFunction)_wrap_get_test_thread, METH_NOARGS }, - { "get_unknown", (PyCFunction)_wrap_get_unknown, METH_NOARGS }, - { "create_test_type", (PyCFunction)_wrap_create_test_type, METH_NOARGS }, - { "test_g_object_new", (PyCFunction)_wrap_test_g_object_new, METH_NOARGS }, - { NULL, NULL } -}; - -PyTypeObject PyTestInterface_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "test.Interface", /* tp_name */ - sizeof(PyObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)0, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)0, /* tp_compare */ - (reprfunc)0, /* tp_repr */ - (PyNumberMethods*)0, /* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, -}; - -void -inittesthelper () -{ - PyObject *m, *d; - - init_pygobject(); - g_thread_init(NULL); - m = Py_InitModule ("testhelper", testhelper_methods); - - d = PyModule_GetDict(m); - - pyg_register_interface(d, "Interface", TEST_TYPE_INTERFACE, - &PyTestInterface_Type); - -} - |