[pypy-svn] rev 831 - in pypy/trunk/src/pypy: . appspace/test interpreterinterpreter/test module/test objspace/std/test test tool
hpk at codespeak.net
hpk at codespeak.net
Wed Jun 18 16:01:30 CEST 2003
Author: hpk
Date: Wed Jun 18 16:01:28 2003
New Revision: 831
Added:
pypy/trunk/src/pypy/appspace/test/autopath.py
pypy/trunk/src/pypy/interpreter/autopath.py
pypy/trunk/src/pypy/interpreter/test/autopath.py
pypy/trunk/src/pypy/module/test/autopath.py
pypy/trunk/src/pypy/objspace/std/test/autopath.py
pypy/trunk/src/pypy/test_all.py
pypy/trunk/src/pypy/tool/__init__.py
pypy/trunk/src/pypy/tool/autopath.py
pypy/trunk/src/pypy/tool/test.py
Removed:
pypy/trunk/src/pypy/appspace/test/testsupport.py
pypy/trunk/src/pypy/interpreter/test/testsupport.py
pypy/trunk/src/pypy/interpreter/testsupport.py
pypy/trunk/src/pypy/interpreter/testtools.py
pypy/trunk/src/pypy/module/test/testsupport.py
pypy/trunk/src/pypy/objspace/std/test/testsupport.py
pypy/trunk/src/pypy/test/
pypy/trunk/src/pypy/testall.py
pypy/trunk/src/pypy/testcts.py
pypy/trunk/src/pypy/testsupport.py
pypy/trunk/src/pypy/testwice.py
pypy/trunk/src/pypy/tool/test_all.py
Modified:
pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py
pypy/trunk/src/pypy/appspace/test/test_complexobject.py
pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py
pypy/trunk/src/pypy/appspace/test/test_exec.py
pypy/trunk/src/pypy/interpreter/interactive.py
pypy/trunk/src/pypy/interpreter/main.py
pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py
pypy/trunk/src/pypy/interpreter/test/test_extmodule.py
pypy/trunk/src/pypy/interpreter/test/test_interpreter.py
pypy/trunk/src/pypy/interpreter/test/test_main.py
pypy/trunk/src/pypy/interpreter/test/test_objspace.py
pypy/trunk/src/pypy/interpreter/test/test_pyframe_app.py
pypy/trunk/src/pypy/interpreter/unittest_w.py
pypy/trunk/src/pypy/module/test/test_apply.py
pypy/trunk/src/pypy/module/test/test_builtin.py
pypy/trunk/src/pypy/module/test/test_filter.py
pypy/trunk/src/pypy/module/test/test_functional.py
pypy/trunk/src/pypy/module/test/test_funtional.py
pypy/trunk/src/pypy/module/test/test_map.py
pypy/trunk/src/pypy/module/test/test_minmax.py
pypy/trunk/src/pypy/module/test/test_range.py
pypy/trunk/src/pypy/module/test/test_reduce.py
pypy/trunk/src/pypy/module/test/test_sysmodule.py
pypy/trunk/src/pypy/module/test/test_vars.py
pypy/trunk/src/pypy/module/test/test_zip.py
pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py
pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py
pypy/trunk/src/pypy/objspace/std/test/test_listobject.py
pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py
pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py
pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py
pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py
pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py
pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py
pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py
pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py
Log:
Refactored our Test "Framework".
- got rid of duplicate code, removed all testsupport/cts/all/whatnot
files.
- concentrate most of the test functionality in tool/test.py
- factored out automatic path manipulation in "autopath.py" whose
master version lives in tool/autopath.py and can be
started to update the others.
- modified interactive.py and main.py to use the new
"-S" "-T" objectspace selection via cmdline.
Command line option parsing still needs more work, ugh.
- please start "python pypy/test_all.py -h"
to see some help about the options.
- consult the wiki page
http://codespeak.net/moin/pypy/moin.cgi/TestFramework
for some documentation i am currently putting up.
- please complain about the stuff i accidentally broke :-)
Added: pypy/trunk/src/pypy/appspace/test/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/appspace/test/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Modified: pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py (original)
+++ pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py Wed Jun 18 16:01:28 2003
@@ -14,9 +14,10 @@
import sys
import types
import unittest
-import testsupport
+import autopath
#try:
+from pypy.tool import test
from pypy.appspace import cmathmodule
from pypy.appspace.complexobject import complex as pycomplex
#except ImportError:
@@ -26,7 +27,7 @@
from test_complexobject import equal, enumerate
-class TestCMathModule(unittest.TestCase):
+class TestCMathModule(test.TestCase):
def assertAEqual(self, a, b):
if not equal(a, b):
@@ -68,4 +69,4 @@
if __name__ == "__main__":
- unittest.main()
+ test.main()
Modified: pypy/trunk/src/pypy/appspace/test/test_complexobject.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/test_complexobject.py (original)
+++ pypy/trunk/src/pypy/appspace/test/test_complexobject.py Wed Jun 18 16:01:28 2003
@@ -10,14 +10,15 @@
sorted out.
"""
+import autopath
import math
import cmath
import sys
import types
import unittest
-import testsupport
+from pypy.tool import test
from pypy.appspace.complexobject import complex as pycomplex
Modified: pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py (original)
+++ pypy/trunk/src/pypy/appspace/test/test_exceptcomp.py Wed Jun 18 16:01:28 2003
@@ -2,10 +2,12 @@
New for PyPy - Could be incorporated into CPython regression tests.
"""
+import autopath
import unittest
+from pypy.tool import test
-class TestExceptionComp(unittest.TestCase):
+class TestExceptionComp(test.TestCase):
def test_string(self):
string = "string"
@@ -121,4 +123,4 @@
self.fail("Exception does not match self in nested tuple.")
if __name__ == "__main__":
- unittest.main()
+ test.main()
Modified: pypy/trunk/src/pypy/appspace/test/test_exec.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/test_exec.py (original)
+++ pypy/trunk/src/pypy/appspace/test/test_exec.py Wed Jun 18 16:01:28 2003
@@ -2,10 +2,12 @@
New for PyPy - Could be incorporated into CPython regression tests.
"""
+import autopath
import unittest
+from pypy.tool import test
-class TestExecStmt(unittest.TestCase):
+class TestExecStmt(test.TestCase):
def test_string(self):
g = {}
Deleted: pypy/trunk/src/pypy/appspace/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Added: pypy/trunk/src/pypy/interpreter/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/interpreter/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Modified: pypy/trunk/src/pypy/interpreter/interactive.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/interactive.py (original)
+++ pypy/trunk/src/pypy/interpreter/interactive.py Wed Jun 18 16:01:28 2003
@@ -1,3 +1,5 @@
+import autopath
+
from pypy.interpreter import executioncontext, pyframe, baseobjspace
import sys
import code
@@ -18,7 +20,7 @@
class PyPyConsole(code.InteractiveConsole):
def __init__(self, objspace):
code.InteractiveConsole.__init__(self)
- self.space = objspace()
+ self.space = objspace
self.ec = executioncontext.ExecutionContext(self.space)
self.w_globals = self.ec.make_standard_w_globals()
self.space.setitem(self.w_globals,
@@ -66,14 +68,9 @@
import readline
except ImportError:
pass
- # object space selection
- if len(sys.argv) < 2:
- choice = 'trivial' # default
- else:
- choice = sys.argv[1]
- classname = choice.capitalize() + 'ObjSpace'
- module = __import__('pypy.objspace.%s' % choice,
- globals(), locals(), [classname])
- ObjSpace = getattr(module, classname)
- con = PyPyConsole(ObjSpace)
+
+ from pypy.tool import test
+ args = test.process_options()
+ objspace = test.objspace()
+ con = PyPyConsole(objspace)
con.interact()
Modified: pypy/trunk/src/pypy/interpreter/main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/main.py (original)
+++ pypy/trunk/src/pypy/interpreter/main.py Wed Jun 18 16:01:28 2003
@@ -1,4 +1,5 @@
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std import StdObjSpace
from pypy.module.builtin import Builtin
from pypy.interpreter import executioncontext, baseobjspace, pyframe
@@ -29,23 +30,22 @@
ec.eval_frame(frame)
def run_file(fname, space=None):
+ if __name__=='__main__':
+ print "Running %r with %r" % (fname, space)
istring = open(fname).read()
run_string(istring, fname, space)
def main(argv=None):
if argv is None:
argv = sys.argv
- if os.environ.get('OBJSPACE'):
- space = testsupport.objspace()
- print "Running with %r" % os.environ.get('OBJSPACE')
- else:
- space = None
+ argv = test.process_options(argv[1:])
+ space = test.objspace()
try:
- run_file(argv[1], space)
+ run_file(argv[0], space)
except baseobjspace.PyPyError, pypyerr:
pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ main(sys.argv)
Added: pypy/trunk/src/pypy/interpreter/test/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/interpreter/test/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Modified: pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_executioncontext.py Wed Jun 18 16:01:28 2003
@@ -1,14 +1,14 @@
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.interpreter.pyframe import PyFrame
from pypy.interpreter import baseobjspace, executioncontext
-
-class TestExecutionContext(testsupport.TestCase):
+class TestExecutionContext(test.TestCase):
def test_trivial1(self):
# build frame
- space = testsupport.objspace()
+ space = test.objspace()
ec = executioncontext.ExecutionContext(space)
compile = space.builtin.compile
bytecode = space.unwrap(compile(space.wrap('def f(x): return x+1'),
@@ -22,4 +22,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/interpreter/test/test_extmodule.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_extmodule.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_extmodule.py Wed Jun 18 16:01:28 2003
@@ -1,9 +1,11 @@
-import testsupport
+import autopath
# need pypy.module.builtin first to make other imports work (???)
from pypy.module import builtin
-
from pypy.interpreter import extmodule
+from pypy.tool import test
+
+import unittest
class EmptyBM(extmodule.BuiltinModule):
__pythonname__ = 'empty_bm'
@@ -18,11 +20,10 @@
somedata = 'twentythree'
somedata = extmodule.appdata(somedata)
-
-class TestBuiltinModule(testsupport.TestCase):
+class TestBuiltinModule(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
def tearDown(self):
pass
@@ -71,10 +72,10 @@
self.assertEqual(thedata, 'twentythree')
-class TestPyBuiltinCode(testsupport.TestCase):
+class TestPyBuiltinCode(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
def tearDown(self):
pass
@@ -128,4 +129,4 @@
self.assertEqual_w(s.call_function(builtin_f, w(2), a=w(1)), w(3))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py Wed Jun 18 16:01:28 2003
@@ -1,6 +1,7 @@
-import testsupport
+import autopath
+from pypy.tool import test
-class TestInterpreter(testsupport.TestCase):
+class TestInterpreter(test.TestCase):
def codetest(self, source, functionname, args):
"""Compile and run the given code string, and then call its function
@@ -33,7 +34,7 @@
return space.unwrap(w_output)
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
def test_exception_trivial(self):
x = self.codetest('''
@@ -141,7 +142,7 @@
self.assertEquals(self.codetest(code, 'f', [9]),
1+2+3 + 5+6+7+8+900)
-class AppTestInterpreter(testsupport.AppTestCase):
+class AppTestInterpreter(test.AppTestCase):
def test_exception(self):
try:
raise Exception, 1
@@ -192,7 +193,21 @@
self.assertEquals(f(), 2)
def test_print(self):
- print 10
+ #import sys
+ #save = sys.stdout
+ #class Out:
+ # def __init__(self):
+ # self.args = []
+ # def write(self, *args):
+ # self.args.extend(args)
+ #out = Out()
+ #try:
+ # sys.stdout = out
+ # print 10
+ # self.assertEquals(out.args, ['10','\n'])
+ #finally:
+ # sys.stdout = save
+ print 42
def test_identity(self):
def f(x): return x
@@ -200,4 +215,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/interpreter/test/test_main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_main.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_main.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,8 @@
import unittest
-import testsupport
+import autopath
from cStringIO import StringIO
+from pypy.tool import test
from pypy.interpreter.baseobjspace import OperationError
testcode = """\
@@ -17,7 +18,7 @@
capture = StringIO()
def checkoutput(expected_output,f,*args):
- space = testsupport.objspace()
+ space = test.objspace()
w_sys = space.get_builtin_module(space.wrap("sys"))
w_oldout = space.getattr(w_sys, space.wrap("stdout"))
capture.reset()
Modified: pypy/trunk/src/pypy/interpreter/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_objspace.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_objspace.py Wed Jun 18 16:01:28 2003
@@ -1,12 +1,13 @@
-import testsupport
+import autopath
+from pypy.tool import test
# this test isn't so much to test that the objspace interface *works*
# -- it's more to test that it's *there*
-class TestStdObjectSpace(testsupport.TestCase):
+class TestStdObjectSpace(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
def tearDown(self):
pass
@@ -76,4 +77,4 @@
self.space.wrap(1))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/interpreter/test/test_pyframe_app.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_pyframe_app.py (original)
+++ pypy/trunk/src/pypy/interpreter/test/test_pyframe_app.py Wed Jun 18 16:01:28 2003
@@ -1,5 +1,6 @@
-import unittest
-import testsupport
+import autopath
+
+from pypy.tool import test
from pypy.interpreter.pyframe_app import decode_frame_arguments
class CodeObject:
@@ -10,7 +11,7 @@
self.co_flags = 4 * vflag + 8 * kflag
-class Testdecode_frame_arguments(unittest.TestCase):
+class Testdecode_frame_arguments(test.TestCase):
def test_plain_parameters(self):
self.assertEqual(
@@ -88,4 +89,4 @@
(1, 2, 3, 4), {}, (), None, CodeObject(kflag=1))
if __name__ == "__main__":
- unittest.main()
+ test.main()
Deleted: pypy/trunk/src/pypy/interpreter/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Deleted: pypy/trunk/src/pypy/interpreter/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Deleted: pypy/trunk/src/pypy/interpreter/testtools.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/testtools.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,44 +0,0 @@
-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
-
-def objspace():
- objspace_path = os.environ.get('OBJSPACE')
- if not objspace_path or '.' not in objspace_path:
- return trivobjspace()
- else:
- return stdobjspace()
-
-_trivobjspace = None
-
-def trivobjspace():
- global _trivobjspace
- if _trivobjspace:
- return _trivobjspace
- from pypy.objspace.trivial import TrivialObjSpace
- _trivobjspace = TrivialObjSpace()
- return _trivobjspace
-
-_stdobjspace = None
-
-def stdobjspace():
- global _stdobjspace
- if _stdobjspace:
- return _stdobjspace
- from pypy.objspace.std import StdObjSpace
- _stdobjspace = StdObjSpace()
- return _stdobjspace
Modified: pypy/trunk/src/pypy/interpreter/unittest_w.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/unittest_w.py (original)
+++ pypy/trunk/src/pypy/interpreter/unittest_w.py Wed Jun 18 16:01:28 2003
@@ -1,6 +1,7 @@
+import autopath
+
import sys, os
import unittest
-import testtools
def wrap_func(space, func):
# this is generally useful enough that it should probably go
@@ -11,7 +12,6 @@
return space.newfunction(code, space.newdict([]),
space.wrap(func.func_defaults), None)
-
def make_testcase_class(space, tc_w):
# XXX this is all a bit insane (but it works)
@@ -114,12 +114,14 @@
unittest.TestCase.__init__(self, methodName)
def __call__(self, result=None):
- setattr(self, self.methodName,
+ if type(getattr(self, self.methodName)) != WrappedFunc:
+ setattr(self, self.methodName,
WrappedFunc(self, getattr(self, self.methodName)))
return unittest.TestCase.__call__(self, result)
def setUp(self):
- self.space = testtools.objspace()
+ from pypy.tool import test
+ self.space = test.objspace()
def app_fail(self, w_self, w_msg=None):
msg = self.space.unwrap(w_msg)
Added: pypy/trunk/src/pypy/module/test/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Modified: pypy/trunk/src/pypy/module/test/test_apply.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_apply.py (original)
+++ pypy/trunk/src/pypy/module/test/test_apply.py Wed Jun 18 16:01:28 2003
@@ -1,12 +1,14 @@
-import testsupport
+import autopath
+
from pypy.module.builtin_app import apply, min, max
+from pypy.tool import test
def myminmax(*arr, **dict):
# trivial function which has the signature *args, **kw
v = list(arr) + dict.values()
return min(v), max(v)
-class TestApply(testsupport.TestCase):
+class TestApply(test.TestCase):
def setUp(self):
pass
@@ -33,6 +35,6 @@
(-4, 2))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_builtin.py (original)
+++ pypy/trunk/src/pypy/module/test/test_builtin.py Wed Jun 18 16:01:28 2003
@@ -1,11 +1,13 @@
-import testsupport
+import autopath
+
from pypy.module.builtin_app import cmp
+from pypy.tool import test
-class TestBuiltin(testsupport.TestCase):
+class TestBuiltin(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
def tearDown(self):
pass
@@ -39,7 +41,7 @@
# sufficiently simple
s.call_function(w_import, w('quopri'), w_dict, w_dict, w_fromlist)
-class TestCmp(testsupport.TestCase):
+class TestCmp(test.TestCase):
def test_cmp(self):
self.failUnless(cmp(9, 9) == 0)
@@ -47,5 +49,5 @@
self.failUnless(cmp(9,0) > 0)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_filter.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_filter.py (original)
+++ pypy/trunk/src/pypy/module/test/test_filter.py Wed Jun 18 16:01:28 2003
@@ -1,6 +1,6 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import filter
-
+from pypy.tool import test
# trivial functions for testing
@@ -16,7 +16,7 @@
else:
return False
-class TestFilter(testsupport.TestCase):
+class TestFilter(test.TestCase):
def test_filter_no_arguments(self):
self.assertRaises(TypeError, filter)
@@ -52,4 +52,4 @@
self.assertEqual(filter(larger_than_a, 'xyzabcd'), 'xyzbcd')
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_functional.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_functional.py (original)
+++ pypy/trunk/src/pypy/module/test/test_functional.py Wed Jun 18 16:01:28 2003
@@ -1,5 +1,7 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import map, filter, reduce, zip
+from pypy.tool import test
+
# trivial functions for testing
@@ -10,7 +12,7 @@
return x + y
-class TestMap(testsupport.TestCase):
+class TestMap(test.TestCase):
def test_trivial_map_one_seq(self):
self.assertEqual(map(add_two, [1, 2, 3, 4]), [3, 4, 5, 6])
@@ -65,14 +67,14 @@
b = []
self.assertEqual(map(lambda x, y: x, a, b), a)
-class TestZip(testsupport.TestCase):
+class TestZip(test.TestCase):
def test_one_list(self):
self.assertEqual(zip([1,2,3]), [(1,), (2,), (3,)])
def test_three_lists(self):
self.assertEqual(zip([1,2,3], [1,2], [1,2,3]), [(1,1,1), (2,2,2)])
-class TestReduce(testsupport.TestCase):
+class TestReduce(test.TestCase):
def test_None(self):
self.assertRaises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None)
@@ -84,7 +86,7 @@
self.assertEqual(reduce(lambda x, y: x-y, [10, 2, 8]), 0)
self.assertEqual(reduce(lambda x, y: x-y, [2, 8], 10), 0)
-class TestFilter(testsupport.TestCase):
+class TestFilter(test.TestCase):
def test_None(self):
self.assertEqual(filter(None, ['a', 'b', 1, 0, None]), ['a', 'b', 1])
@@ -98,6 +100,6 @@
self.assertEqual(filter(lambda x: x != "a", "a small text"), " smll text")
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_funtional.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_funtional.py (original)
+++ pypy/trunk/src/pypy/module/test/test_funtional.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,9 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import map, filter, reduce, zip
-class TestMap(testsupport.TestCase):
+from pypy.tool import test
+
+class TestMap(test.TestCase):
def test_map_identity1(self):
a = ['1', 2, 3, 'b', None]
@@ -34,14 +36,14 @@
b = []
self.assertEqual(map(lambda x, y: x, a, b), a)
-class TestZip(testsupport.TestCase):
+class TestZip(test.TestCase):
def test_one_list(self):
self.assertEqual(zip([1,2,3]), [(1,), (2,), (3,)])
def test_three_lists(self):
self.assertEqual(zip([1,2,3], [1,2], [1,2,3]), [(1,1,1), (2,2,2)])
-class TestReduce(testsupport.TestCase):
+class TestReduce(test.TestCase):
def test_None(self):
self.assertRaises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None)
@@ -53,7 +55,7 @@
self.assertEqual(reduce(lambda x, y: x-y, [10, 2, 8]), 0)
self.assertEqual(reduce(lambda x, y: x-y, [2, 8], 10), 0)
-class TestFilter(testsupport.TestCase):
+class TestFilter(test.TestCase):
def test_None(self):
self.assertEqual(filter(None, ['a', 'b', 1, 0, None]), ['a', 'b', 1])
@@ -67,6 +69,6 @@
self.assertEqual(filter(lambda x: x != "a", "a small text"), " smll text")
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_map.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_map.py (original)
+++ pypy/trunk/src/pypy/module/test/test_map.py Wed Jun 18 16:01:28 2003
@@ -1,5 +1,6 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import map
+from pypy.tool import test
# trivial functions for testing
@@ -14,7 +15,7 @@
y = 1000
return x + y
-class TestMap(testsupport.TestCase):
+class TestMap(test.TestCase):
def test_map_no_arguments(self):
self.assertRaises(TypeError, map)
@@ -77,6 +78,6 @@
self.assertEqual(map(lambda x, y: x, a, b), a)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_minmax.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_minmax.py (original)
+++ pypy/trunk/src/pypy/module/test/test_minmax.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,8 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import min, max
+from pypy.tool import test
-class TestMin(testsupport.TestCase):
+class TestMin(test.TestCase):
def setUp(self):
pass
@@ -39,7 +40,7 @@
def test_min_empty(self):
self.assertRaises(ValueError, min, [])
-class TestMax(testsupport.TestCase):
+class TestMax(test.TestCase):
def setUp(self):
pass
@@ -78,4 +79,4 @@
self.assertRaises(ValueError, max, [])
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_range.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_range.py (original)
+++ pypy/trunk/src/pypy/module/test/test_range.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,8 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import range
+from pypy.tool import test
-class TestRange(testsupport.TestCase):
+class TestRange(test.TestCase):
def setUp(self):
pass
@@ -74,6 +75,6 @@
"""
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_reduce.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_reduce.py (original)
+++ pypy/trunk/src/pypy/module/test/test_reduce.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,8 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import reduce
+from pypy.tool import test
-class TestReduce(testsupport.TestCase):
+class TestReduce(test.TestCase):
def test_None(self):
self.assertRaises(TypeError, reduce, lambda x, y: x+y, [1,2,3], None)
@@ -14,6 +15,6 @@
self.assertEqual(reduce(lambda x, y: x-y, [2, 8], 10), 0)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_sysmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_sysmodule.py (original)
+++ pypy/trunk/src/pypy/module/test/test_sysmodule.py Wed Jun 18 16:01:28 2003
@@ -1,8 +1,9 @@
-import testsupport
+import autopath
+from pypy.tool import test
-class SysTests(testsupport.TestCase):
+class SysTests(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace()
self.sys_w = self.space.get_builtin_module(self.space.wrap("sys"))
def tearDown(self):
pass
@@ -12,5 +13,5 @@
self.failUnless_w(s.getattr(self.sys_w, s.wrap("stdout")))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_vars.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_vars.py (original)
+++ pypy/trunk/src/pypy/module/test/test_vars.py Wed Jun 18 16:01:28 2003
@@ -1,5 +1,6 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import map
+from pypy.tool import test
# trivial objects for testing
@@ -15,7 +16,7 @@
t1 = TrivialObject()
t1.do_something()
-class TestVars(testsupport.TestCase):
+class TestVars(test.TestCase):
def test_vars_no_arguments(self):
self.assertEqual(vars(), locals())
@@ -29,6 +30,6 @@
self.assertNotEqual(vars(t1), t.__dict__)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/module/test/test_zip.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_zip.py (original)
+++ pypy/trunk/src/pypy/module/test/test_zip.py Wed Jun 18 16:01:28 2003
@@ -1,7 +1,8 @@
-import testsupport
+import autopath
from pypy.module.builtin_app import zip
+from pypy.tool import test
-class TestZip(testsupport.TestCase):
+class TestZip(test.TestCase):
def test_zip_no_arguments(self):
self.assertRaises(TypeError, zip)
@@ -32,6 +33,6 @@
[('h', 1, 7), ('e', 2, 8), ('l', 3, 9), ('l', 4, 10)])
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Deleted: pypy/trunk/src/pypy/module/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Added: pypy/trunk/src/pypy/objspace/std/test/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/objspace/std/test/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_cpythonobject.py Wed Jun 18 16:01:28 2003
@@ -1,13 +1,14 @@
import unittest, sys, array
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std import cpythonobject
from pypy.objspace.std.objspace import OperationError
-class TestW_CPythonObject(testsupport.TestCase):
+class TestW_CPythonObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
# arbitrary always-wrapped object
self.stuff = array.array('b', [5,-2,77])
@@ -77,4 +78,4 @@
self.assertEquals(self.space.unwrap(w_result), 11)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Wed Jun 18 16:01:28 2003
@@ -1,11 +1,12 @@
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std.dictobject import W_DictObject
-class TestW_DictObject(testsupport.TestCase):
+class TestW_DictObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -80,4 +81,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py Wed Jun 18 16:01:28 2003
@@ -1,12 +1,13 @@
import sys
-import testsupport
+import autopath
from pypy.objspace.std import intobject as iobj
from pypy.objspace.std.objspace import FailedToImplement
+from pypy.tool import test
-class TestW_IntObject(testsupport.TestCase):
+class TestW_IntObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -286,4 +287,4 @@
self.assertEquals(self.space.unwrap(result), hex(x))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_iterobject.py Wed Jun 18 16:01:28 2003
@@ -1,11 +1,12 @@
-import testsupport
+import autopath
from pypy.objspace.std.iterobject import W_SeqIterObject
from pypy.objspace.std.objspace import NoValue
+from pypy.tool import test
-class TestW_IterObject(testsupport.TestCase):
+class TestW_IterObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -27,4 +28,4 @@
self.assertRaises(NoValue, self.space.next, w_iter)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_listobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_listobject.py Wed Jun 18 16:01:28 2003
@@ -1,13 +1,14 @@
#from __future__ import nested_scopes
-import testsupport
+import autopath
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.objspace import NoValue
+from pypy.tool import test
-class TestW_ListObject(testsupport.TestCase):
+class TestW_ListObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -119,4 +120,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_moduleobject.py Wed Jun 18 16:01:28 2003
@@ -1,11 +1,11 @@
-import testsupport
+import autopath
from pypy.objspace.std.moduleobject import W_ModuleObject
+from pypy.tool import test
-
-class TestW_ModuleObject(testsupport.TestCase):
+class TestW_ModuleObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -31,4 +31,4 @@
self.assertEqual_w(space.getattr(w_m, space.wrap('yy')), w_yy)
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_multimethod.py Wed Jun 18 16:01:28 2003
@@ -1,8 +1,7 @@
-import unittest
-import testsupport
+import autopath
from pypy.objspace.std.multimethod import *
-
+from pypy.tool import test
# default delegator
@@ -85,7 +84,7 @@
w_TypeError = 'w_TypeError'
-class TestMultiMethod(unittest.TestCase):
+class TestMultiMethod(test.TestCase):
def test_base(self):
space = FakeObjSpace()
@@ -133,4 +132,4 @@
if __name__ == '__main__':
- unittest.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_noneobject.py Wed Jun 18 16:01:28 2003
@@ -1,10 +1,11 @@
-import testsupport
+import autopath
+from pypy.tool import test
-class TestW_NoneObject(testsupport.TestCase):
+class TestW_NoneObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace()
def tearDown(self):
pass
@@ -21,4 +22,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_restricted_int.py Wed Jun 18 16:01:28 2003
@@ -1,8 +1,9 @@
import unittest
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std.restricted_int import *
-class Test_r_int(unittest.TestCase):
+class Test_r_int(test.TestCase):
def setUp(self):
pass
@@ -129,4 +130,4 @@
self.assertEquals(res, cmp)
if __name__ == '__main__':
- unittest.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py Wed Jun 18 16:01:28 2003
@@ -1,9 +1,10 @@
-import testsupport
+import autopath
+from pypy.tool import test
-class TestW_SliceObject(testsupport.TestCase):
+class TestW_SliceObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -32,4 +33,4 @@
w_slice.indices, w(10))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_stdobjspace.py Wed Jun 18 16:01:28 2003
@@ -1,9 +1,10 @@
-import testsupport
+import autopath
+from pypy.tool import test
-class TestW_StdObjSpace(testsupport.TestCase):
+class TestW_StdObjSpace(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -19,4 +20,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_stringobject.py Wed Jun 18 16:01:28 2003
@@ -1,14 +1,14 @@
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std import stringobject
-
from pypy.objspace.std.stringobject import \
string_richcompare, W_StringObject, EQ, LT, GT, NE, LE, GE
-class TestW_StringObject(testsupport.TestCase):
+class TestW_StringObject(test.TestCase):
def setUp(self):
- self.space = testsupport.objspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -115,4 +115,4 @@
self.assertEqual_w(space.getitem(w_str, w_slice), w('el'))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_tupleobject.py Wed Jun 18 16:01:28 2003
@@ -1,13 +1,14 @@
#from __future__ import nested_scopes
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std.tupleobject import W_TupleObject
from pypy.objspace.std.objspace import NoValue
-class TestW_TupleObject(testsupport.TestCase):
+class TestW_TupleObject(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -115,4 +116,4 @@
test1((5,7,1,4), -5, 11, 2, (5, 1))
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_typeobject.py Wed Jun 18 16:01:28 2003
@@ -1,10 +1,11 @@
-import testsupport
+import autopath
+from pypy.tool import test
from pypy.objspace.std.typeobject import PyMultimethodCode
-class TestPyMultimethodCode(testsupport.TestCase):
+class TestPyMultimethodCode(test.TestCase):
def setUp(self):
- self.space = testsupport.stdobjspace()
+ self.space = test.objspace('std')
def tearDown(self):
pass
@@ -55,4 +56,4 @@
if __name__ == '__main__':
- testsupport.main()
+ test.main()
Deleted: pypy/trunk/src/pypy/objspace/std/test/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Added: pypy/trunk/src/pypy/test_all.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/test_all.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,6 @@
+import tool.autopath
+from pypy.tool import test
+
+if __name__ == '__main__':
+ test.main(tool.autopath.pypydir)
+
Deleted: pypy/trunk/src/pypy/testall.py
==============================================================================
--- pypy/trunk/src/pypy/testall.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,56 +0,0 @@
-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, inc_names=[], exc_names=[]):
- testmods = []
- def callback(arg, dirname, names):
- if os.path.basename(dirname) == 'test':
- parname = os.path.basename(os.path.dirname(dirname))
- if ((not inc_names) or parname in inc_names) and parname not in exc_names:
- 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)
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
-
- inc_names = []
- exc_names = []
-
- for arg in argv[1:]:
- if arg.startswith('--include='):
- inc_names = arg[len('--include='):].split(',')
- elif arg.startswith('--exclude='):
- exc_names = arg[len('--exclude='):].split(',')
- else:
- raise Exception, "don't know arg " + arg
-
- runner = unittest.TextTestRunner()
- runner.run(find_tests(PYPYDIR, inc_names, exc_names))
-
-if __name__ == '__main__':
- main()
Deleted: pypy/trunk/src/pypy/testcts.py
==============================================================================
--- pypy/trunk/src/pypy/testcts.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,115 +0,0 @@
-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, inc_names=[], exc_names=[]):
- testmods = []
- def callback(arg, dirname, names):
- if os.path.basename(dirname) == 'test':
- parname = os.path.basename(os.path.dirname(dirname))
- if ((not inc_names) or parname in inc_names) and parname not in exc_names:
- 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)
-
-class MyTestResult(unittest.TestResult):
- def __init__(self):
- unittest.TestResult.__init__(self)
- self.successes = []
- def addSuccess(self, test):
- self.successes.append(test)
-
-
-class CtsTestRunner:
- def run(self, test):
- import pickle
-
- result = MyTestResult()
- sys.stdout = open('/dev/null', 'w')
- sys.stderr = open('/dev/null', 'w')
- test(result)
- sys.stdout = sys.__stdout__
- sys.stderr = sys.__stderr__
-
- ostatus = {}
- if os.path.exists('testcts.pickle'):
- ostatus = pickle.load(open('testcts.pickle','r'))
-
- status = {}
-
- for e in result.errors:
- name = e[0].__class__.__name__ + '.' + e[0]._TestCase__testMethodName
- status[name] = 'ERROR'
- for f in result.failures:
- name = f[0].__class__.__name__ + '.' + f[0]._TestCase__testMethodName
- status[name] = 'FAILURE'
- for s in result.successes:
- name = s.__class__.__name__ + '.' + s._TestCase__testMethodName
- status[name] = 'success'
-
- keys = status.keys()
- keys.sort()
-
- for k in keys:
- old = ostatus.get(k, 'success')
- if k in ostatus:
- del ostatus[k]
- new = status[k]
- if old != new:
- print k, 'has transitioned from', old, 'to', new
- elif new != 'success':
- print k, "is still a", new
-
- for k in ostatus:
- print k, 'was a', ostatus[k], 'was not run this time'
- status[k] = ostatus[k]
-
- pickle.dump(status, open('testcts.pickle','w'))
-
- return result
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
-
- inc_names = []
- exc_names = []
-
- os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace'
-
- for arg in argv[1:]:
- if arg.startswith('--include='):
- inc_names = arg[len('--include='):].split(',')
- elif arg.startswith('--exclude='):
- exc_names = arg[len('--exclude='):].split(',')
- else:
- raise Exception, "don't know arg " + arg
-
- runner = CtsTestRunner()
- runner.run(find_tests(PYPYDIR, inc_names, exc_names))
-
-
-if __name__ == '__main__':
- main()
Deleted: pypy/trunk/src/pypy/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/testsupport.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,52 +0,0 @@
-"""
-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
-import os
-import unittest
-
-try:
- head = this_path = os.path.abspath(__file__)
-except NameError:
- p = os.path.dirname(sys.argv[0])
- if not p:
- p = os.curdir
- head = this_path = os.path.abspath(p)
-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
-from pypy.interpreter.testtools import *
-
-TestCase = pypy.interpreter.unittest_w.IntTestCase
-AppTestCase = pypy.interpreter.unittest_w.AppTestCase
-main = unittest.main
-
-if __name__ == '__main__':
- runner = unittest.TextTestRunner()
- runner.run(get_tests_for_dir(this_path))
Deleted: pypy/trunk/src/pypy/testwice.py
==============================================================================
--- pypy/trunk/src/pypy/testwice.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,67 +0,0 @@
-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 is_flexible(dirname, modname):
- filecont = open('%s/%s.py'%(dirname,modname)).read()
- return filecont.find('testsupport.objspace') >= 0
-
-def find_tests(root, inc_names=[], exc_names=[]):
- testmods = []
- testwice = []
- def callback(arg, dirname, names):
- if os.path.basename(dirname) == 'test':
- parname = os.path.basename(os.path.dirname(dirname))
- if ((not inc_names) or parname in inc_names) and parname not in exc_names:
- 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)
- if is_flexible(dirname, file):
- testwice.append(package + '.' + file)
-
- os.path.walk(root, callback, None)
-
- tl = unittest.TestLoader()
-
- return tl.loadTestsFromNames(testmods), tl.loadTestsFromNames(testwice)
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
-
- inc_names = []
- exc_names = []
-
- for arg in argv[1:]:
- if arg.startswith('--include='):
- inc_names = arg[len('--include='):].split(',')
- elif arg.startswith('--exclude='):
- exc_names = arg[len('--exclude='):].split(',')
- else:
- raise Exception, "don't know arg " + arg
-
- runner = unittest.TextTestRunner()
- alltests, flexible = find_tests(PYPYDIR, inc_names, exc_names)
- os.environ['OBJSPACE'] = ''
- runner.run(alltests)
- os.environ['OBJSPACE'] = 'pypy.objspace.std.objspace.StdObjSpace'
- runner.run(flexible)
-
-if __name__ == '__main__':
- main()
Added: pypy/trunk/src/pypy/tool/__init__.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/tool/__init__.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1 @@
+#empty
Added: pypy/trunk/src/pypy/tool/autopath.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/tool/autopath.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,76 @@
+"""
+self cloning, automatic path configuration
+
+copy this into any subdirectory of pypy from which scripts need
+to be run, typically all of the test subdirs.
+The idea is that any such script simply issues
+
+ import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path.
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py)
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory.
+
+This module always provides these attributes:
+
+ pypydir pypy root directory path
+ this_dir directory where this autopath.py resides
+
+"""
+
+
+def __dirinfo(part):
+ """ return (partdir, this_dir) and insert parent of partdir
+ into sys.path. If the parent directories dont have the part
+ an EnvironmentError is raised."""
+
+ import sys, os
+ try:
+ head = this_dir = os.path.abspath(os.path.dirname(__file__))
+ except NameError:
+ head = this_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+ while head:
+ partdir = head
+ head, tail = os.path.split(head)
+ if tail == part:
+ if head not in sys.path:
+ sys.path.insert(0, head)
+ return partdir, this_dir
+ raise EnvironmentError, "'%s' missing in '%r'" % (pathpart,this_path)
+
+def __clone():
+ """ clone master version of autopath.y into all subdirs """
+ from os.path import join, walk
+ if not this_dir.endswith(join('pypy','tool')):
+ raise EnvironmentError("can only clone master version "
+ "'%s'" % join(pypydir, 'tool',_myname))
+
+
+ def sync_walker(arg, dirname, fnames):
+ if _myname in fnames:
+ fn = join(dirname, _myname)
+ f = open(fn, 'rwb+')
+ try:
+ if f.read() == arg:
+ print "checkok", fn
+ else:
+ print "syncing", fn
+ f.seek(0)
+ f.write(arg)
+ finally:
+ f.close()
+ s = open(join(pypydir, 'tool', _myname), 'rb').read()
+ walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+ __clone()
Added: pypy/trunk/src/pypy/tool/test.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/tool/test.py Wed Jun 18 16:01:28 2003
@@ -0,0 +1,283 @@
+import autopath
+import os, sys, unittest, re, warnings, unittest
+from unittest import TestCase, TestLoader
+
+import pypy.interpreter.unittest_w
+
+IntTestCase = pypy.interpreter.unittest_w.IntTestCase
+AppTestCase = pypy.interpreter.unittest_w.AppTestCase
+TestCase = IntTestCase
+
+class MyTestSuite(unittest.TestSuite):
+ def __call__(self, result):
+ """ execute the tests, invokes underlyning unittest.__call__"""
+
+ # XXX here is probably not the best place
+ # to check for test/objspace mismatch
+ count = self.countTestCases()
+ if not count:
+ return result
+
+ fm = getattr(self, 'frommodule','')
+ if fm and fm.startswith('pypy.objspace.std') and \
+ Options.spacename != 'std':
+ sys.stderr.write("\n%s skip for objspace %r" % (
+ fm, Options.spacename))
+ return result
+
+ if fm and Options.verbose==0:
+ sys.stderr.write('\n%s [%d]' %(fm, count))
+ result = unittest.TestSuite.__call__(self, result)
+ return result
+
+ def addTest(self, test, frommodule=None):
+ if test.countTestCases()>0:
+ test.frommodule = frommodule
+ unittest.TestSuite.addTest(self, test)
+
+ def __nonzero__(self):
+ return self.countTestCases()>0
+
+
+# register MyTestSuite to unittest
+unittest.TestLoader.suiteClass = MyTestSuite
+
+class MyTestResult(unittest.TestResult):
+ def __init__(self):
+ unittest.TestResult.__init__(self)
+ self.successes = []
+ def addSuccess(self, test):
+ self.successes.append(test)
+
+class CtsTestRunner:
+ def run(self, test):
+ import pickle
+
+ result = MyTestResult()
+ sys.stdout = open('/dev/null', 'w')
+ sys.stderr = open('/dev/null', 'w')
+ test(result)
+ sys.stdout = sys.__stdout__
+ sys.stderr = sys.__stderr__
+
+ ostatus = {}
+ if os.path.exists('testcts.pickle'):
+ ostatus = pickle.load(open('testcts.pickle','r'))
+
+ status = {}
+
+ for e in result.errors:
+ name = e[0].__class__.__name__ + '.' + e[0]._TestCase__testMethodName
+ status[name] = 'ERROR'
+ for f in result.failures:
+ name = f[0].__class__.__name__ + '.' + f[0]._TestCase__testMethodName
+ status[name] = 'FAILURE'
+ for s in result.successes:
+ name = s.__class__.__name__ + '.' + s._TestCase__testMethodName
+ status[name] = 'success'
+
+ keys = status.keys()
+ keys.sort()
+
+ for k in keys:
+ old = ostatus.get(k, 'success')
+ if k in ostatus:
+ del ostatus[k]
+ new = status[k]
+ if old != new:
+ print k, 'has transitioned from', old, 'to', new
+ elif new != 'success':
+ print k, "is still a", new
+
+ for k in ostatus:
+ print k, 'was a', ostatus[k], 'was not run this time'
+ status[k] = ostatus[k]
+
+ pickle.dump(status, open('testcts.pickle','w'))
+
+ return result
+
+def testsuite_from_main():
+ """ return test modules from __main__
+
+ """
+ loader = unittest.TestLoader()
+ m = __import__('__main__')
+ return loader.loadTestsFromModule(m)
+
+def testsuite_from_dir(root, filterfunc=None, recursive=0, loader=None):
+ """ return test modules that optionally match filterfunc.
+
+ all files matching the glob-pattern "test_*.py" are considered.
+ additionally their fully qualified python module path has
+ to be accepted by filterfunc (if it is not None).
+ """
+ if Options.verbose>2:
+ print >>sys.stderr, "scanning for test files in", root
+
+ if loader is None:
+ loader = unittest.TestLoader()
+
+ root = os.path.abspath(root)
+
+ suite = unittest.TestLoader.suiteClass()
+ for fn in os.listdir(root):
+ if fn.startswith('.'):
+ continue
+ fullfn = os.path.join(root, fn)
+ if os.path.isfile(fullfn) and \
+ fn.startswith('test_') and \
+ fn.endswith('.py'):
+ modpath = fullfn[len(autopath.pypydir)+1:-3]
+ modpath = 'pypy.' + modpath.replace(os.sep, '.')
+ if not filterfunc or filterfunc(modpath):
+ subsuite = loader.loadTestsFromName(modpath)
+ suite.addTest(subsuite, modpath)
+ elif recursive and os.path.isdir(fullfn):
+ subsuite = testsuite_from_dir(fullfn, filterfunc, 1, loader)
+ if subsuite:
+ suite._tests.extend(subsuite._tests)
+ return suite
+
+def objspace(name='', _spacecache={}):
+ """ return singleton ObjSpace instance.
+
+ this is configured via the environment variable OBJSPACE
+ """
+ name = name or Options.spacename or os.environ.get('OBJSPACE', 'trivial')
+ if name == 'std':
+ from pypy.objspace.std import Space
+ elif name == 'trivial':
+ from pypy.objspace.trivial import Space
+ else:
+ raise ValueError, "no objectspace named %s" % repr(name)
+
+ try:
+ return _spacecache[name]
+ except KeyError:
+ return _spacecache.setdefault(name, Space())
+
+class Options:
+ """ Options set by command line """
+ verbose = 0
+ spacename = ''
+ showwarning = 0
+ allspaces = []
+ testreldir = 0
+ runcts = 0
+
+class RegexFilterFunc:
+ """ stateful function to filter included/excluded strings via
+ a Regular Expression.
+
+ An 'excluded' regular expressions has a '%' prependend.
+ """
+
+ def __init__(self, *regex):
+ self.exclude = []
+ self.include = []
+ for x in regex:
+ if x[:1]=='%':
+ self.exclude.append(re.compile(x[1:]).search)
+ else:
+ self.include.append(re.compile(x).search)
+
+ def __call__(self, arg):
+ for exclude in self.exclude:
+ if exclude(arg):
+ return
+ if not self.include:
+ return arg
+ for include in self.include:
+ if include(arg):
+ return arg
+
+def print_usage():
+ print >>sys.stderr, """\
+%s [-chrvST] [regex1] [regex2] [...]
+
+ -c run CtsTestRunner (catches stdout and prints report after testing)
+ -h this help message
+ -r gather only tests relative to current dir
+ -v increase verbosity level (including unittest-verbosity)
+ -w enable warnings from warnings framework (default is off)
+ -S run in standard object space
+ -T run in trivial object space (default)
+
+ The regular expressions regex1, regex2 ... are matched
+ against the full python path of a test module. A leading
+ '%%' before a regex means that the matching result is to
+ be inverted.
+""" % sys.argv[0]
+ raise SystemExit(1)
+
+def process_options(argv=[]):
+ """ invoke this if you want to process test-switches from sys.argv"""
+
+ if not argv:
+ argv[:] = sys.argv[1:]
+
+ try:
+ import getopt
+ opts, args = getopt.getopt(argv, "chrvST")
+ except getopt.error, msg:
+ print msg
+ print "Try `python %s -h' for help" % sys.argv[0]
+ sys.exit(2)
+
+ for k,v in opts:
+ if k == '-h':
+ print_usage()
+ elif k == '-c':
+ Options.runcts = 1
+ elif k == '-r':
+ Options.testreldir = 1
+ elif k == '-w':
+ Options.showwarning = 1
+ elif k == '-h':
+ print_usage()
+ elif k == '-v':
+ Options.verbose += 1
+ elif k == '-S':
+ Options.spacename = 'std'
+ Options.allspaces.append('std')
+ elif k == '-T':
+ Options.spacename = 'trivial'
+ Options.allspaces.append('trivial')
+
+ return args
+
+def run_tests(suite):
+ for spacename in Options.allspaces or ['']:
+ run_tests_on_space(suite, spacename)
+
+def run_tests_on_space(suite, spacename=''):
+ """ run the suite on the given space """
+ if Options.runcts:
+ runner = CtsTestRunner() # verbosity=Options.verbose+1)
+ else:
+ runner = unittest.TextTestRunner(verbosity=Options.verbose+1)
+
+ if spacename:
+ Options.spacename = spacename
+
+ warnings.defaultaction = Options.showwarning and 'default' or 'ignore'
+ print >>sys.stderr, "running tests via", repr(objspace())
+ runner.run(suite)
+
+def main(root=None):
+ """ run this to test everything in the __main__ or
+ in the given root-directory (recursive)"""
+ args = process_options()
+ filterfunc = RegexFilterFunc(*args)
+ if Options.testreldir:
+ root = os.path.abspath('.')
+ if root is None:
+ suite = testsuite_from_main()
+ else:
+ suite = testsuite_from_dir(root, filterfunc, 1)
+ run_tests(suite)
+
+if __name__ == '__main__':
+ # test all of pypy
+ main(autopath.pypydir)
Deleted: pypy/trunk/src/pypy/tool/test_all.py
==============================================================================
--- pypy/trunk/src/pypy/tool/test_all.py Wed Jun 18 16:01:28 2003
+++ (empty file)
@@ -1,75 +0,0 @@
-#!/usr/bin/python
-
-import sys,os,glob,inspect, unittest
-from os.path import join as joinfn
-from os.path import basename, dirname, abspath
-sepline = '='*70
-
-
-def eval_dict_from(fn):
- os.chdir(dirname(fn))
- d = {}
- try:
- execfile(fn, d)
- except IOError:
- pass
- return d
-
-class exec_testfile:
- def __init__(self, modfn, testfn):
- self.testdict = eval_dict_from(testfn)
- self.moddict = eval_dict_from(modfn)
-
- for name, obj in self.testdict.items():
- if inspect.isclass(obj) and issubclass(obj, unittest.TestCase) and \
- name.startswith('Test'):
- self.exec_testclass(name, obj)
-
- def exec_testclass(self, name, obj):
- if name[4:] not in self.moddict.keys():
- print repr(name), "does not correspond to a class"
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(obj, 'test'))
- print "running unittest", name
- unittest.TextTestRunner().run(suite)
- print "finished"
-
-
-def filetests(path):
- """tests files on the given path"""
- testpath = joinfn(path, 'test')
- testfnames = glob.glob(testpath+os.sep+'test_*.py')
- fnames = glob.glob(path+os.sep+'*.py')
-
- for testfn in testfnames:
- print sepline
- modfn = joinfn(path, basename(testfn)[5:])
-
- if modfn not in fnames:
- print "testfile", basename(testfn), "has no", basename(modfn)
- else:
- fnames.remove(modfn)
- exec_testfile(modfn, testfn)
- #for fn in fnames:
- # print fn, "has no corresponding test?"
-
-def drive_tests(base):
- ctests = filetests(joinfn(base, 'interpreter'))
-
-if __name__=='__main__':
- path = dirname(abspath(sys.argv[0]))
- drive, path = os.path.splitdrive(path)
- path = path.split(os.sep)
-
- if 'pypy' not in path:
- raise SystemExit, "Need to be somewhere in pypy-tree"
-
- while path.pop() != 'pypy':
- pass
-
- path.insert(0, '/')
- path.append('pypy')
- path = drive + joinfn('/', *path)
- print path, dirname(path)
- sys.path.insert(0, dirname(path))
- drive_tests(path)
More information about the Pypy-commit
mailing list