summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2005-01-10 16:25:46 +0000
committerJohan Dahlin <johan@src.gnome.org>2005-01-10 16:25:46 +0000
commit64e07ba0b2a4acb84f61e5688d3537f4a38e09e6 (patch)
tree9daa6194ea657c79cdf0580528bcbd57ed66a38b
parentdc62a03bbc1b3a8271c24ca0887e7285a0ab4848 (diff)
downloadpygobject-64e07ba0b2a4acb84f61e5688d3537f4a38e09e6.tar.gz
Make testsuite work and do things the way they were supposed to be done
* tests/Makefile.am: * tests/common.py: * tests/runtests.py: * tests/test_thread.py: Make testsuite work and do things the way they were supposed to be done from the beginning.
-rw-r--r--tests/Makefile.am14
-rw-r--r--tests/common.py74
-rw-r--r--tests/runtests.py7
-rw-r--r--tests/test_thread.py5
4 files changed, 75 insertions, 25 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2b68b3db..6572eff5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,10 +32,14 @@ tests = \
testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES)
$(LINK) -rpath $(pkgpyexecdir) $(testhelper_la_LDFLAGS) $(testhelper_la_OBJECTS) $(testhelper_la_LIBADD) $(LIBS)
-PYTHONPATH = $(top_builddir):$(top_builddir)/gobject:$(top_srcdir):$(top_srcdir)/gtk
-
check-local: $(top_srcdir)/gtk/__init__.py
- @if ! test -e $(top_builddir)/gtk/__init__.py; then cp $(top_srcdir)/gtk/__init__.py $(top_builddir)/gtk/__init__.py; fi
- @PYTHONPATH=$(PYTHONPATH) DIST_CHECK=1 $(PYTHON) $(srcdir)/runtests.py
- @if test "$(top_builddir)" != "$(top_srcdir)"; then rm -f $(top_builddir)/gtk/__init__.py*; fi
+ @if test "$(top_builddir)" != "$(top_srcdir)"; then \
+ cp $(top_srcdir)/gtk/__init__.py $(top_builddir)/gtk/__init__.py; \
+ cp $(top_srcdir)/gtk/keysyms.py $(top_builddir)/gtk/keysyms.py; \
+ fi
+ @$(PYTHON) $(srcdir)/runtests.py $(top_builddir) $(top_srcdir)
+ @if test "$(top_builddir)" != "$(top_srcdir)"; then \
+ rm -f $(top_builddir)/gtk/__init__.py*; \
+ rm -f $(top_builddir)/gtk/keysyms.py*; \
+ fi
@rm -fr *.pyc
diff --git a/tests/common.py b/tests/common.py
index 237e6f25..9429579a 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -1,23 +1,67 @@
import os
import sys
-if not os.environ.has_key('DIST_CHECK'):
- sys.path.insert(0, '..')
- sys.path.insert(0, '../gobject')
+def importModules(buildDir, srcDir):
+ # Be very careful when you change this code, it's
+ # fragile and the order is really significant
+
+ # ltihooks
+ sys.path.insert(0, srcDir)
+ # atk, pango
+ sys.path.insert(0, buildDir)
+ # gobject
+ 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'))
-import ltihooks
+ import ltihooks
+
+ gobject = importModule('gobject', buildDir, 'gobject/gobject.la')
+ atk = importModule('atk', buildDir)
+ pango = importModule('pango', buildDir)
+ gtk = importModule('gtk', buildDir, 'gtk')
+ gdk = importModule('gtk.gdk', buildDir, '_gdk.la')
+ try:
+ glade = importModule('gtk.glade', buildDir, 'glade.la')
+ except ImportError:
+ glade = None
+
+ testhelper = importModule('testhelper', '.')
+
+ ltihooks.uninstall()
+ del ltihooks
+
+ globals().update(locals())
+
+ os.environ['PYGTK_USE_GIL_STATE_API'] = ''
+ gobject.threads_init()
-import gobject
-import atk
-import pango
+def importModule(module, directory, name=None):
+ global isDistCheck
-import gtk
-from gtk import gdk
-try:
- from gtk import glade
-except ImportError:
- glade = None
+ if '.' in module:
+ fromlist = '.'.join(module.split('.')[:-1])
+ else:
+ fromlist = None
-import testhelper
+ if not name:
+ name = module + '.la'
-ltihooks.uninstall()
+ obj = __import__(module, {}, {}, fromlist)
+ if hasattr(obj, '__file__'):
+ location = obj.__file__
+ else:
+ package = __import__(fromlist)
+ location = os.path.join(package.__file__, name)
+
+ current = os.getcwd()
+ expected = os.path.abspath(os.path.join(current, location))
+ current = os.path.abspath(location)
+ if current != expected:
+ raise AssertionError('module %s imported from wrong location. Expected %s, got %s' % (
+ module, expected, current))
+
+ return obj
+
diff --git a/tests/runtests.py b/tests/runtests.py
index 83b6013b..b22ce2b9 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -4,6 +4,13 @@ import os
import sys
import unittest
+import common
+
+buildDir = sys.argv[1]
+srcDir = sys.argv[2]
+common.importModules(buildDir=buildDir,
+ srcDir=srcDir)
+
SKIP_FILES = ['common', 'runtests']
dir = os.path.split(os.path.abspath(__file__))[0]
diff --git a/tests/test_thread.py b/tests/test_thread.py
index ad23d273..647783ac 100644
--- a/tests/test_thread.py
+++ b/tests/test_thread.py
@@ -3,11 +3,6 @@ import unittest
from common import gobject, gtk, testhelper
-# Enable PyGILState API
-os.environ['PYGTK_USE_GIL_STATE_API'] = ''
-
-gobject.threads_init()
-
class TestThread(unittest.TestCase):
def from_thread_cb(self, test, enum):
assert test == self.obj