[pygobject] Clean and improve the test infrastructure



commit 0a9f1da052fd33dcef81d0e267fc7972f02c7888
Author: Simon van der Linden <svdlinden gnome org>
Date:   Wed Jul 28 14:56:00 2010 +0200

    Clean and improve the test infrastructure
    
    To run select tests, use for instance:
    % make check TEST_NAMES='test_everything test_gi.TestConstant'
    
    It works with check.gdb and check.valgrind too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=625488

 Makefile.am                |    5 ---
 tests/Makefile.am          |   65 ++++++++++++++++++++-----------------------
 tests/common.py            |   47 -------------------------------
 tests/runtests.py          |   43 +++++++++++------------------
 tests/test_gcancellable.py |    4 +-
 tests/test_gi.py           |    3 --
 tests/test_gicon.py        |    3 +-
 tests/test_gio.py          |    3 +-
 tests/test_gobject.py      |    3 +-
 tests/test_gresolver.py    |    4 +-
 tests/test_gsocket.py      |    4 ++-
 tests/test_interface.py    |    6 +++-
 tests/test_mainloop.py     |   11 +++-----
 tests/test_signal.py       |    4 ++-
 tests/test_source.py       |    4 +-
 tests/test_subprocess.py   |    5 +---
 tests/test_thread.py       |    5 +++-
 tests/test_unknown.py      |    5 +++-
 18 files changed, 82 insertions(+), 142 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 94bcf8e..6fe43c6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -128,11 +128,6 @@ dist-hook: $(BUILT_EXTRA_DIST)
 check.gdb:
 	cd tests && $(MAKE) check.gdb
 
-%.gdb:
-	cd tests && $(MAKE) $*.gdb
-
 check.valgrind:
 	cd tests && $(MAKE) check.valgrind
 
-%.valgrind:
-	cd tests && $(MAKE) $*.valgrind
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d0b1ca1..1cdabf9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,20 +1,7 @@
-INCLUDES = \
-	-I$(top_srcdir)/gobject \
-	$(PYTHON_INCLUDES) \
-	$(GLIB_CFLAGS)
-
-EXTRA_DIST = \
-	$(tests) \
-	common.py \
-	runtests.py \
-	testmodule.py \
-	test-floating.h \
-	test-thread.h \
-	test-unknown.h
 
 noinst_LTLIBRARIES = testhelper.la
-linked_LIBS = testhelper.la
 
+testhelper_la_CFLAGS = -I$(top_srcdir)/gobject $(PYTHON_INCLUDES) $(GLIB_CFLAGS)
 testhelper_la_LDFLAGS = -module -avoid-version
 testhelper_la_LIBADD = $(GLIB_LIBS)
 testhelper_la_SOURCES = \
@@ -23,49 +10,57 @@ testhelper_la_SOURCES = \
 	test-thread.c \
 	test-unknown.c
 
-tests =  \
+# 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)
+
+
+.la.so:
+	test -L $@ || $(LN_S) .libs/$@ $@
+
+
+all: $(LTLIBRARIES:.la=.so)
+
+
+EXTRA_DIST = \
+	runtests.py \
+	testmodule.py \
+	test-floating.h \
+	test-thread.h \
+	test-unknown.h \
+	\
+	test_gcancellable.py \
 	test_gicon.py \
 	test_gio.py \
 	test_gobject.py \
+	test_gresolver.py \
+	test_gsocket.py \
 	test_interface.py \
 	test_mainloop.py \
+	test_option.py \
 	test_properties.py \
 	test_signal.py \
+	test_source.py \
 	test_subprocess.py \
-	test_unknown.py \
-	test_source.py
+	test_thread.py
 
 if ENABLE_INTROSPECTION
-tests += \
+EXTRA_DIST += \
 	test_everything.py \
 	test_gi.py \
 	test_overrides.py
 endif
 
-# 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)
-
-check-local: $(LTLIBRARIES:.la=.so)
-	$(EXEC_NAME) $(PYTHON) $(srcdir)/runtests.py $(top_builddir) $(tests)
-
-all: $(LTLIBRARIES:.la=.so)
 
 clean-local:
 	rm -f $(LTLIBRARIES:.la=.so)
 
-.la.so:
-	$(LN_S) .libs/$@ $@ || true
+
+check-local: $(LTLIBRARIES:.la=.so)
+	PYTHONPATH=$(top_builddir):$(top_builddir)/tests:$${PYTHONPATH:+:$$PYTHONPATH} $(EXEC_NAME) $(PYTHON) $(srcdir)/runtests.py
 
 check.gdb:
 	EXEC_NAME="gdb --args" $(MAKE) check
 
-%.gdb:
-	EXEC_NAME="gdb --args" TEST_NAMES=$* $(MAKE) check
-
 check.valgrind:
 	EXEC_NAME="valgrind" $(MAKE) check
-
-%.valgrind:
-	EXEC_NAME="valgrind" TEST_NAMES=$* $(MAKE) check
-
diff --git a/tests/runtests.py b/tests/runtests.py
index e6b483e..eae684c 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -1,35 +1,24 @@
-#!/usr/bin/env python
-import glob
-import os
-import sys
-import unittest
-
-import common
-
-program = None
-if len(sys.argv) < 2:
-    raise ValueError('Need at least 2 parameters: runtests.py <build-dir> '
-                     '<test-module-1> <test-module-2> ...')
+# -*- Mode: Python -*-
 
-buildDir = sys.argv[1]
-files = sys.argv[2:]
+import os
+import glob
 
-common.importModules(buildDir=buildDir)
+import unittest
 
-dir = os.path.split(os.path.abspath(__file__))[0]
-os.chdir(dir)
 
-def gettestnames():
-    names = map(lambda x: x[:-3], files)
-    return names
+# Load tests.
+if 'TEST_NAMES' in os.environ:
+	names = os.environ['TEST_NAMES'].split()
+else:
+	names = []
+	for filename in glob.iglob("test_*.py"):
+		names.append(filename[:-3])
 
-suite = unittest.TestSuite()
 loader = unittest.TestLoader()
+suite = loader.loadTestsFromNames(names)
+
 
-for name in gettestnames():
-    if program and program not in name:
-        continue
-    suite.addTest(loader.loadTestsFromName(name))
+# Run tests.
+runner = unittest.TextTestRunner(verbosity=2)
+runner.run(suite)
 
-testRunner = unittest.TextTestRunner(verbosity=2)
-testRunner.run(suite)
diff --git a/tests/test_gcancellable.py b/tests/test_gcancellable.py
index 7a0f94b..f911572 100644
--- a/tests/test_gcancellable.py
+++ b/tests/test_gcancellable.py
@@ -1,9 +1,9 @@
 # -*- Mode: Python -*-
 
-import os
 import unittest
 
-from common import gio, glib
+import glib
+import gio
 
 
 class TestResolver(unittest.TestCase):
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 284b362..08caf48 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -7,9 +7,6 @@ pygtk.require("2.0")
 import unittest
 from gi.repository import GObject
 
-import sys
-sys.path.insert(0, "../")
-
 import gobject
 from gi.repository import GIMarshallingTests
 
diff --git a/tests/test_gicon.py b/tests/test_gicon.py
index 5ce7ece..b9af6ff 100644
--- a/tests/test_gicon.py
+++ b/tests/test_gicon.py
@@ -3,7 +3,8 @@
 import os
 import unittest
 
-from common import gio, glib
+import glib
+import gio
 
 
 class TestIcon(unittest.TestCase):
diff --git a/tests/test_gio.py b/tests/test_gio.py
index feafc70..7c8251e 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -3,7 +3,8 @@
 import os
 import unittest
 
-from common import gio, glib
+import glib
+import gio
 
 
 class TestFile(unittest.TestCase):
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index d91f3ad..f3cdf29 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -2,7 +2,8 @@
 
 import unittest
 
-from common import gobject, testhelper
+import gobject
+import testhelper
 
 
 class TestGObjectAPI(unittest.TestCase):
diff --git a/tests/test_gresolver.py b/tests/test_gresolver.py
index 4303f0f..ef8585c 100644
--- a/tests/test_gresolver.py
+++ b/tests/test_gresolver.py
@@ -1,9 +1,9 @@
 # -*- Mode: Python -*-
 
-import os
 import unittest
 
-from common import gio, glib
+import glib
+import gio
 
 
 class TestResolver(unittest.TestCase):
diff --git a/tests/test_gsocket.py b/tests/test_gsocket.py
index 16ff40f..627f6fd 100644
--- a/tests/test_gsocket.py
+++ b/tests/test_gsocket.py
@@ -3,7 +3,9 @@
 import os
 import unittest
 
-from common import gio, glib, gobject
+import glib
+import gobject
+import gio
 
 
 class TestSocket(unittest.TestCase):
diff --git a/tests/test_interface.py b/tests/test_interface.py
index d959791..fbc0586 100644
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -1,6 +1,10 @@
+# -*- Mode: Python -*-
+
 import unittest
 
-from common import gobject, testhelper
+import gobject
+import testhelper
+
 
 GUnknown = gobject.type_from_name("TestUnknown")
 Unknown = GUnknown.pytype
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 95e5f78..4286d13 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -1,12 +1,12 @@
-#!/usr/bin/env python
+# -*- Mode: Python -*-
 
-import exceptions
 import os
 import sys
 import select
 import unittest
 
-from common import glib
+import glib
+
 
 class TestMainLoop(unittest.TestCase):
     def testExceptionHandling(self):
@@ -31,7 +31,7 @@ class TestMainLoop(unittest.TestCase):
         os.close(pipe_w)
 
         def excepthook(type, value, traceback):
-            assert type is exceptions.Exception
+            assert type is Exception
             assert value.args[0] == "deadbabe"
         sys.excepthook = excepthook
 
@@ -48,6 +48,3 @@ class TestMainLoop(unittest.TestCase):
         #
         sys.excepthook = sys.__excepthook__
         assert not got_exception
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 96e0731..075b03e 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -4,7 +4,9 @@ import gc
 import unittest
 import sys
 
-from common import gobject, testhelper
+import gobject
+import testhelper
+
 
 class C(gobject.GObject):
     __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
diff --git a/tests/test_source.py b/tests/test_source.py
index abe2f69..c4ea62c 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -1,8 +1,8 @@
-#!/usr/bin/env python
+# -*- Mode: Python -*-
 
 import unittest
 
-from common import glib
+import glib
 
 
 class Idle(glib.Idle):
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index 1522edb..c90d1d6 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -3,7 +3,7 @@
 import sys
 import unittest
 
-from common import glib
+import glib
 
 
 class TestProcess(unittest.TestCase):
@@ -22,6 +22,3 @@ class TestProcess(unittest.TestCase):
         glib.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_thread.py b/tests/test_thread.py
index 09ad074..be746a4 100644
--- a/tests/test_thread.py
+++ b/tests/test_thread.py
@@ -1,6 +1,9 @@
+# -*- Mode: Python -*-
+
 import unittest
 
-from common import glib, testhelper
+import glib
+import testhelper
 
 
 class TestThread(unittest.TestCase):
diff --git a/tests/test_unknown.py b/tests/test_unknown.py
index d65bb89..2a18eec 100644
--- a/tests/test_unknown.py
+++ b/tests/test_unknown.py
@@ -1,7 +1,10 @@
+# -*- Mode: Python -*-
 
 import unittest
 
-from common import gobject, testhelper
+import gobject
+import testhelper
+
 
 TestInterface = gobject.GType.from_name('TestInterface')
 



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