[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/
Modified runalltests.py so it imports modules more like
test.py, i.e.
Stefan H. Holek
stefan at epy.co.at
Wed May 18 10:02:33 EDT 2005
Log message for revision 30382:
Modified runalltests.py so it imports modules more like test.py, i.e.
without touching sys.path and without the help of imp.
Changed:
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
U Zope/trunk/lib/python/Testing/ZopeTestCase/runalltests.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/runalltests.py
-=-
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2005-05-18 06:52:18 UTC (rev 30381)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2005-05-18 14:02:32 UTC (rev 30382)
@@ -17,6 +17,8 @@
Reusing the registry from other modules becomes a lot cleaner as a result.
- Made sure to close the REQUEST so as not to leak REQUEST._held. Thanks
to Sidnei da Silva.
+- Modified runalltests.py so it imports modules more like test.py, i.e.
+ without touching sys.path and without the help of imp.
0.9.6
- Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/runalltests.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/runalltests.py 2005-05-18 06:52:18 UTC (rev 30381)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/runalltests.py 2005-05-18 14:02:32 UTC (rev 30382)
@@ -15,38 +15,34 @@
Execute like:
python runalltests.py [-R]
-$Id:$
+$Id$
"""
-__version__ = '0.2.1'
+__version__ = '0.3.1'
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
-import unittest, imp
+import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
-def visitor(recursive, dir, names):
- tests = [n[:-3] for n in names if n.startswith('test') and n.endswith('.py')]
-
- for test in tests:
- saved_syspath = sys.path[:]
- sys.path.insert(0, dir)
- try:
- fp, path, desc = imp.find_module(test, [dir])
- m = imp.load_module(test, fp, path, desc)
+def test_finder(recurse, dir, names):
+ if dir == os.curdir or '__init__.py' in names:
+ parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
+ tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
+ for test in tests:
+ modpath = parts + [test[:-3]]
+ m = __import__('.'.join(modpath))
+ for part in modpath[1:]:
+ m = getattr(m, part)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
- finally:
- fp.close()
- sys.path[:] = saved_syspath
-
- if not recursive:
+ if not recurse:
names[:] = []
if __name__ == '__main__':
- os.path.walk(os.curdir, visitor, '-R' in sys.argv)
+ os.path.walk(os.curdir, test_finder, '-R' in sys.argv)
TestRunner().run(suite)
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/runalltests.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/runalltests.py 2005-05-18 06:52:18 UTC (rev 30381)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/runalltests.py 2005-05-18 14:02:32 UTC (rev 30382)
@@ -15,38 +15,34 @@
Execute like:
python runalltests.py [-R]
-$Id:$
+$Id$
"""
-__version__ = '0.2.1'
+__version__ = '0.3.1'
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
-import unittest, imp
+import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
-def visitor(recursive, dir, names):
- tests = [n[:-3] for n in names if n.startswith('test') and n.endswith('.py')]
-
- for test in tests:
- saved_syspath = sys.path[:]
- sys.path.insert(0, dir)
- try:
- fp, path, desc = imp.find_module(test, [dir])
- m = imp.load_module(test, fp, path, desc)
+def test_finder(recurse, dir, names):
+ if dir == os.curdir or '__init__.py' in names:
+ parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
+ tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
+ for test in tests:
+ modpath = parts + [test[:-3]]
+ m = __import__('.'.join(modpath))
+ for part in modpath[1:]:
+ m = getattr(m, part)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
- finally:
- fp.close()
- sys.path[:] = saved_syspath
-
- if not recursive:
+ if not recurse:
names[:] = []
if __name__ == '__main__':
- os.path.walk(os.curdir, visitor, '-R' in sys.argv)
+ os.path.walk(os.curdir, test_finder, '-R' in sys.argv)
TestRunner().run(suite)
More information about the Zope-Checkins
mailing list