[pypy-svn] rev 548 - in pypy/trunk/src/pypy: . appspace/test interpreterinterpreter/test module/test objspace/std/test
mwh at codespeak.net
mwh at codespeak.net
Tue May 27 14:57:33 CEST 2003
Author: mwh
Date: Tue May 27 14:57:33 2003
New Revision: 548
Added:
pypy/trunk/src/pypy/appspace/test/__init__.py
pypy/trunk/src/pypy/interpreter/testtools.py
pypy/trunk/src/pypy/module/test/__init__.py
pypy/trunk/src/pypy/objspace/std/test/__init__.py
pypy/trunk/src/pypy/objspace/std/test/broken_test_floatobject.py
- copied unchanged from rev 544, pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py
pypy/trunk/src/pypy/objspace/std/test/broken_test_template.py
- copied unchanged from rev 544, pypy/trunk/src/pypy/objspace/std/test/test_template.py
pypy/trunk/src/pypy/testall.py
Removed:
pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py
pypy/trunk/src/pypy/objspace/std/test/test_template.py
Modified:
pypy/trunk/src/pypy/interpreter/appfile.py
pypy/trunk/src/pypy/interpreter/test/testsupport.py
pypy/trunk/src/pypy/module/test/testsupport.py (contents, props changed)
pypy/trunk/src/pypy/objspace/std/test/testsupport.py
pypy/trunk/src/pypy/testsupport.py
Log:
Reorganize (well, add) testing framework.
The new testall.py script in the root of the project scours for test_*.py
files and runs tests therein.
Also change testsupport.py files to run tests in their directories when
run as a script.
Move a couple of REALLY broken tests so that the testall.py script doesn't
find them.
Added: pypy/trunk/src/pypy/appspace/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/appspace/test/__init__.py Tue May 27 14:57:33 2003
@@ -0,0 +1 @@
+# empty
Modified: pypy/trunk/src/pypy/interpreter/appfile.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/appfile.py (original)
+++ pypy/trunk/src/pypy/interpreter/appfile.py Tue May 27 14:57:33 2003
@@ -25,7 +25,7 @@
break
else:
raise IOError, "cannot locate helper module '%s' in %s" % (
- modulename, lookuppaths_ext)
+ modulename, path_ext)
f = open(filename, 'r')
src = f.read()
f.close()
Modified: pypy/trunk/src/pypy/interpreter/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/testsupport.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/testsupport.py Tue May 27 14:57:33 2003
@@ -1,49 +1,60 @@
-"""
-Master version of testsupport.py: copy into any subdirectory of pypy
-from which scripts need to be run (typically all of the 'test' subdirs)
-so that any test can "import testsupport" to ensure the parent of pypy
-is on the sys.path -- so that "import pypy.etc.etc." always works.
-
-Also, this module exposes a member 'TestCase' that is unittest.TestCase
-or a subclass thereof supplying extra methods; and a function 'main'
-that is unittest.main or the equivalent.
-
-Furthermore, this module now exposes a member 'objspace' which is
-by default class pypy.objspace.trivial.TrivialObjSpace but can be
-set to use another objectspace instead; this allows tests to run
-under different objectspaces without needing to edit their sources.
-
-For this setting, use environment variable OBJSPACE and set it to
-a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
-also the default if the environment variable is not found or empty
-or without any dot in it).
-"""
-import sys, os
-
-head = this_path = os.path.abspath(__file__)
-while 1:
- head, tail = os.path.split(head)
- if not tail:
- raise EnvironmentError, "pypy not among parents of %r!" % this_path
- elif tail.lower()=='pypy':
- sys.path.insert(0, head)
- break
-
-import pypy.interpreter.unittest_w
-TestCase = pypy.interpreter.unittest_w.TestCase_w
-import unittest
-main = unittest.main
-
-objspace_path = os.environ.get('OBJSPACE')
-if not objspace_path or '.' not in objspace_path:
- import pypy.objspace.trivial
- objspace = pypy.objspace.trivial.TrivialObjSpace
-else:
- objspace_pieces = objspace_path.split('.')
- objspace_path = '.'.join(objspace_pieces[:-1])
- objspace_module = __import__(objspace_path)
- for piece in objspace_pieces[1:-1]:
- objspace_module = getattr(objspace_module, piece)
- objspace_classname = objspace_pieces[-1]
- objspace = getattr(objspace_module, objspace_classname)
-
+"""
+Master version of testsupport.py: copy into any subdirectory of pypy
+from which scripts need to be run (typically all of the 'test' subdirs)
+so that any test can "import testsupport" to ensure the parent of pypy
+is on the sys.path -- so that "import pypy.etc.etc." always works.
+
+Also, this module exposes a member 'TestCase' that is unittest.TestCase
+or a subclass thereof supplying extra methods; and a function 'main'
+that is unittest.main or the equivalent.
+
+Furthermore, this module now exposes a member 'objspace' which is
+by default class pypy.objspace.trivial.TrivialObjSpace but can be
+set to use another objectspace instead; this allows tests to run
+under different objectspaces without needing to edit their sources.
+
+For this setting, use environment variable OBJSPACE and set it to
+a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
+also the default if the environment variable is not found or empty
+or without any dot in it).
+
+When run as a script, runs all tests found in files called 'test_*.py'
+in the same directory.
+"""
+import sys, os
+
+try:
+ head = this_path = os.path.abspath(__file__)
+except NameError:
+ head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+while 1:
+ head, tail = os.path.split(head)
+ if not tail:
+ raise EnvironmentError, "pypy not among parents of %r!" % this_path
+ elif tail.lower()=='pypy':
+ sys.path.insert(0, head)
+ break
+
+import pypy.interpreter.unittest_w
+TestCase = pypy.interpreter.unittest_w.TestCase_w
+import unittest
+main = unittest.main
+
+from pypy.interpreter import testtools
+
+objspace_path = os.environ.get('OBJSPACE')
+if not objspace_path or '.' not in objspace_path:
+ import pypy.objspace.trivial
+ objspace = pypy.objspace.trivial.TrivialObjSpace
+else:
+ objspace_pieces = objspace_path.split('.')
+ objspace_path = '.'.join(objspace_pieces[:-1])
+ objspace_module = __import__(objspace_path)
+ for piece in objspace_pieces[1:-1]:
+ objspace_module = getattr(objspace_module, piece)
+ objspace_classname = objspace_pieces[-1]
+ objspace = getattr(objspace_module, objspace_classname)
+
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0])))
Added: pypy/trunk/src/pypy/interpreter/testtools.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/interpreter/testtools.py Tue May 27 14:57:33 2003
@@ -0,0 +1,18 @@
+import os
+import unittest
+
+def get_tests_for_dir(directory):
+ files = os.listdir(directory)
+ testfiles = [f[:-3] for f in files if f.startswith('test_') and f.endswith('.py')]
+
+ ts = unittest.TestSuite()
+
+ tl = unittest.TestLoader()
+
+ for testfile in testfiles:
+ mod = __import__(testfile)
+ ts.addTest(tl.loadTestsFromModule(mod))
+
+ return ts
+
+
Added: pypy/trunk/src/pypy/module/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/__init__.py Tue May 27 14:57:33 2003
@@ -0,0 +1 @@
+# empty
Modified: pypy/trunk/src/pypy/module/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/testsupport.py (original)
+++ pypy/trunk/src/pypy/module/test/testsupport.py Tue May 27 14:57:33 2003
@@ -1,49 +1,60 @@
-"""
-Master version of testsupport.py: copy into any subdirectory of pypy
-from which scripts need to be run (typically all of the 'test' subdirs)
-so that any test can "import testsupport" to ensure the parent of pypy
-is on the sys.path -- so that "import pypy.etc.etc." always works.
-
-Also, this module exposes a member 'TestCase' that is unittest.TestCase
-or a subclass thereof supplying extra methods; and a function 'main'
-that is unittest.main or the equivalent.
-
-Furthermore, this module now exposes a member 'objspace' which is
-by default class pypy.objspace.trivial.TrivialObjSpace but can be
-set to use another objectspace instead; this allows tests to run
-under different objectspaces without needing to edit their sources.
-
-For this setting, use environment variable OBJSPACE and set it to
-a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
-also the default if the environment variable is not found or empty
-or without any dot in it).
-"""
-import sys, os
-
-head = this_path = os.path.abspath(__file__)
-while 1:
- head, tail = os.path.split(head)
- if not tail:
- raise EnvironmentError, "pypy not among parents of %r!" % this_path
- elif tail.lower()=='pypy':
- sys.path.insert(0, head)
- break
-
-import pypy.interpreter.unittest_w
-TestCase = pypy.interpreter.unittest_w.TestCase_w
-import unittest
-main = unittest.main
-
-objspace_path = os.environ.get('OBJSPACE')
-if not objspace_path or '.' not in objspace_path:
- import pypy.objspace.trivial
- objspace = pypy.objspace.trivial.TrivialObjSpace
-else:
- objspace_pieces = objspace_path.split('.')
- objspace_path = '.'.join(objspace_pieces[:-1])
- objspace_module = __import__(objspace_path)
- for piece in objspace_pieces[1:-1]:
- objspace_module = getattr(objspace_module, piece)
- objspace_classname = objspace_pieces[-1]
- objspace = getattr(objspace_module, objspace_classname)
-
+"""
+Master version of testsupport.py: copy into any subdirectory of pypy
+from which scripts need to be run (typically all of the 'test' subdirs)
+so that any test can "import testsupport" to ensure the parent of pypy
+is on the sys.path -- so that "import pypy.etc.etc." always works.
+
+Also, this module exposes a member 'TestCase' that is unittest.TestCase
+or a subclass thereof supplying extra methods; and a function 'main'
+that is unittest.main or the equivalent.
+
+Furthermore, this module now exposes a member 'objspace' which is
+by default class pypy.objspace.trivial.TrivialObjSpace but can be
+set to use another objectspace instead; this allows tests to run
+under different objectspaces without needing to edit their sources.
+
+For this setting, use environment variable OBJSPACE and set it to
+a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
+also the default if the environment variable is not found or empty
+or without any dot in it).
+
+When run as a script, runs all tests found in files called 'test_*.py'
+in the same directory.
+"""
+import sys, os
+
+try:
+ head = this_path = os.path.abspath(__file__)
+except NameError:
+ head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+while 1:
+ head, tail = os.path.split(head)
+ if not tail:
+ raise EnvironmentError, "pypy not among parents of %r!" % this_path
+ elif tail.lower()=='pypy':
+ sys.path.insert(0, head)
+ break
+
+import pypy.interpreter.unittest_w
+TestCase = pypy.interpreter.unittest_w.TestCase_w
+import unittest
+main = unittest.main
+
+from pypy.interpreter import testtools
+
+objspace_path = os.environ.get('OBJSPACE')
+if not objspace_path or '.' not in objspace_path:
+ import pypy.objspace.trivial
+ objspace = pypy.objspace.trivial.TrivialObjSpace
+else:
+ objspace_pieces = objspace_path.split('.')
+ objspace_path = '.'.join(objspace_pieces[:-1])
+ objspace_module = __import__(objspace_path)
+ for piece in objspace_pieces[1:-1]:
+ objspace_module = getattr(objspace_module, piece)
+ objspace_classname = objspace_pieces[-1]
+ objspace = getattr(objspace_module, objspace_classname)
+
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0])))
Added: pypy/trunk/src/pypy/objspace/std/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/objspace/std/test/__init__.py Tue May 27 14:57:33 2003
@@ -0,0 +1 @@
+# empty
Deleted: pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_floatobject.py Tue May 27 14:57:33 2003
+++ (empty file)
@@ -1,118 +0,0 @@
-#!/usr/bin/env python
-import unittest
-import sys
-import os
-
-print "not working, rewrite this test!"
-sys.exit(0)
-
-#Start HACK
-
-#######################################
-# Workaround to give the modules
-# an "objectspace"
-#######################################
-
-import pypy.objspace
-thisdir = os.getcwd()
-syspath = sys.path
-sys.path.insert(0,thisdir)
-sys.path.append('..')
-
-
-#######################################
-# import the module you want to test
-# import yourmodule
-#######################################
-
-os.chdir('..')
-import floatobject as fl
-os.chdir(thisdir)
-
-# End HACK
-
-True,False = (1==1),(1==0)
-
-class TestW_FloatObject(unittest.TestCase):
-
- def setUp(self):
- self.space = objspace.StdObjSpace
-
- def tearDown(self):
- pass
-
- def test_float(self):
- f1 = fl.W_FloatObject(1.0)
- result = fl.float_float(self.space,f1)
- assert result == f1
-
- def test_repr(self):
- x = 1.0
- f1 = fl.W_FloatObject(x)
- result = fl.float_repr(self.space,f1)
- assert self.space.unwrap(result) == repr(x)
-
- def test_str(self):
- x = 1.0
- f1 = fl.W_FloatObject(x)
- result = fl.float_str(self.space,f1)
- assert self.space.unwrap(result) == str(x)
-
- def test_hash(self):
- x = 1.0
- f1 = fl.W_FloatObject(x)
- result = fl.float_hash(self.space,f1)
- assert self.space.unwrap(result) == hash(x)
-
- def test_add(self):
- f1 = fl.W_FloatObject(1.0)
- f2 = fl.W_FloatObject(2.0)
- result = fl.float_float_add(self.space,f1,f2)
- assert result.floatval == 3.0
-
- def test_sub(self):
- f1 = fl.W_FloatObject(1.0)
- f2 = fl.W_FloatObject(2.0)
- result = fl.float_float_sub(self.space,f1,f2)
- assert result.floatval == -1.0
-
- def test_mul(self):
- f1 = fl.W_FloatObject(1.0)
- f2 = fl.W_FloatObject(2.0)
- result = fl.float_float_mul(self.space,f1,f2)
- assert result.floatval == 2.0
-
- def test_div(self):
- f1 = fl.W_FloatObject(1.0)
- f2 = fl.W_FloatObject(2.0)
- result = fl.float_float_div(self.space,f1,f2)
- assert result.floatval == 0.5
-
- def test_mod(self):
- x = 1.0
- y = 2.0
- f1 = fl.W_FloatObject(x)
- f2 = fl.W_FloatObject(y)
- v = fl.float_float_mod(self.space,f1,f2)
- assert v.floatval == x % y
-
- def test_divmod(self):
- x = 1.0
- y = 2.0
- f1 = fl.W_FloatObject(x)
- f2 = fl.W_FloatObject(y)
- wrappedTuple = fl.float_float_divmod(self.space,f1,f2)
- v,w = self.space.unwrap(wrappedTuple)
- assert (v.floatval,w.floatval) == divmod(x,y)
-
- def test_pow(self):
- x = 1.0
- y = 2.0
- f1 = fl.W_FloatObject(x)
- f2 = fl.W_FloatObject(y)
- v = fl.float_float_pow(self.space,f1,f2)
- assert v.floatval == x ** y
-
-
-if __name__ == '__main__':
- unittest.main()
Deleted: pypy/trunk/src/pypy/objspace/std/test/test_template.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_template.py Tue May 27 14:57:33 2003
+++ (empty file)
@@ -1,35 +0,0 @@
-import sys
-print "not working, do not run nor use this!"
-sys.exit(0)
-
-import objspace
-thisdir = os.getcwd()
-syspath = sys.path
-sys.path.insert(0,thisdir)
-sys.path.append('..')
-
-
-#######################################
-# import the module you want to test
-# import yourmodule
-#######################################
-
-os.chdir('..')
-#import your_object_class
-os.chdir(thisdir)
-
-# End HACK
-class TestYourObjectClass(unittest.TestCase):
-
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
- def test_test1(self):
- pass
-
-
-if __name__ == '__main__':
- unittest.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/testsupport.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/testsupport.py Tue May 27 14:57:33 2003
@@ -17,10 +17,16 @@
a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
also the default if the environment variable is not found or empty
or without any dot in it).
+
+When run as a script, runs all tests found in files called 'test_*.py'
+in the same directory.
"""
import sys, os
-head = this_path = os.path.abspath(__file__)
+try:
+ head = this_path = os.path.abspath(__file__)
+except NameError:
+ head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
while 1:
head, tail = os.path.split(head)
if not tail:
@@ -34,6 +40,8 @@
import unittest
main = unittest.main
+from pypy.interpreter import testtools
+
objspace_path = os.environ.get('OBJSPACE')
if not objspace_path or '.' not in objspace_path:
import pypy.objspace.trivial
@@ -47,3 +55,6 @@
objspace_classname = objspace_pieces[-1]
objspace = getattr(objspace_module, objspace_classname)
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0])))
Added: pypy/trunk/src/pypy/testall.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/testall.py Tue May 27 14:57:33 2003
@@ -0,0 +1,39 @@
+import os
+import unittest
+import sys
+
+try:
+ head = this_path = os.path.abspath(__file__)
+except NameError:
+ head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+while 1:
+ head, tail = os.path.split(head)
+ if not tail:
+ raise EnvironmentError, "pypy not among parents of %r!" % this_path
+ elif tail.lower()=='pypy':
+ PYPYDIR = head
+ if PYPYDIR not in sys.path:
+ sys.path.insert(0, PYPYDIR)
+ break
+
+def find_tests(root):
+ testmods = []
+ def callback(arg, dirname, names):
+ if os.path.basename(dirname) == 'test':
+ package = dirname[len(PYPYDIR)+1:].replace(os.sep, '.')
+ testfiles = [f[:-3] for f in names
+ if f.startswith('test_') and f.endswith('.py')]
+ for file in testfiles:
+ testmods.append(package + '.' + file)
+
+ os.path.walk(root, callback, None)
+
+ tl = unittest.TestLoader()
+
+ return tl.loadTestsFromNames(testmods)
+
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ runner.run(find_tests(PYPYDIR))
+
+
Modified: pypy/trunk/src/pypy/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/testsupport.py (original)
+++ pypy/trunk/src/pypy/testsupport.py Tue May 27 14:57:33 2003
@@ -1,49 +1,60 @@
-"""
-Master version of testsupport.py: copy into any subdirectory of pypy
-from which scripts need to be run (typically all of the 'test' subdirs)
-so that any test can "import testsupport" to ensure the parent of pypy
-is on the sys.path -- so that "import pypy.etc.etc." always works.
-
-Also, this module exposes a member 'TestCase' that is unittest.TestCase
-or a subclass thereof supplying extra methods; and a function 'main'
-that is unittest.main or the equivalent.
-
-Furthermore, this module now exposes a member 'objspace' which is
-by default class pypy.objspace.trivial.TrivialObjSpace but can be
-set to use another objectspace instead; this allows tests to run
-under different objectspaces without needing to edit their sources.
-
-For this setting, use environment variable OBJSPACE and set it to
-a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
-also the default if the environment variable is not found or empty
-or without any dot in it).
-"""
-import sys, os
-
-head = this_path = os.path.abspath(__file__)
-while 1:
- head, tail = os.path.split(head)
- if not tail:
- raise EnvironmentError, "pypy not among parents of %r!" % this_path
- elif tail.lower()=='pypy':
- sys.path.insert(0, head)
- break
-
-import pypy.interpreter.unittest_w
-TestCase = pypy.interpreter.unittest_w.TestCase_w
-import unittest
-main = unittest.main
-
-objspace_path = os.environ.get('OBJSPACE')
-if not objspace_path or '.' not in objspace_path:
- import pypy.objspace.trivial
- objspace = pypy.objspace.trivial.TrivialObjSpace
-else:
- objspace_pieces = objspace_path.split('.')
- objspace_path = '.'.join(objspace_pieces[:-1])
- objspace_module = __import__(objspace_path)
- for piece in objspace_pieces[1:-1]:
- objspace_module = getattr(objspace_module, piece)
- objspace_classname = objspace_pieces[-1]
- objspace = getattr(objspace_module, objspace_classname)
-
+"""
+Master version of testsupport.py: copy into any subdirectory of pypy
+from which scripts need to be run (typically all of the 'test' subdirs)
+so that any test can "import testsupport" to ensure the parent of pypy
+is on the sys.path -- so that "import pypy.etc.etc." always works.
+
+Also, this module exposes a member 'TestCase' that is unittest.TestCase
+or a subclass thereof supplying extra methods; and a function 'main'
+that is unittest.main or the equivalent.
+
+Furthermore, this module now exposes a member 'objspace' which is
+by default class pypy.objspace.trivial.TrivialObjSpace but can be
+set to use another objectspace instead; this allows tests to run
+under different objectspaces without needing to edit their sources.
+
+For this setting, use environment variable OBJSPACE and set it to
+a value such as 'pypy.objspace.trivial.TrivialObjSpace' (which is
+also the default if the environment variable is not found or empty
+or without any dot in it).
+
+When run as a script, runs all tests found in files called 'test_*.py'
+in the same directory.
+"""
+import sys, os
+
+try:
+ head = this_path = os.path.abspath(__file__)
+except NameError:
+ head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+while 1:
+ head, tail = os.path.split(head)
+ if not tail:
+ raise EnvironmentError, "pypy not among parents of %r!" % this_path
+ elif tail.lower()=='pypy':
+ sys.path.insert(0, head)
+ break
+
+import pypy.interpreter.unittest_w
+TestCase = pypy.interpreter.unittest_w.TestCase_w
+import unittest
+main = unittest.main
+
+from pypy.interpreter import testtools
+
+objspace_path = os.environ.get('OBJSPACE')
+if not objspace_path or '.' not in objspace_path:
+ import pypy.objspace.trivial
+ objspace = pypy.objspace.trivial.TrivialObjSpace
+else:
+ objspace_pieces = objspace_path.split('.')
+ objspace_path = '.'.join(objspace_pieces[:-1])
+ objspace_module = __import__(objspace_path)
+ for piece in objspace_pieces[1:-1]:
+ objspace_module = getattr(objspace_module, piece)
+ objspace_classname = objspace_pieces[-1]
+ objspace = getattr(objspace_module, objspace_classname)
+
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ runner.run(testtools.get_tests_for_dir(os.path.dirname(sys.argv[0])))
More information about the Pypy-commit
mailing list