[pypy-svn] rev 557 - in pypy/trunk/src/pypy: . appspace/test interpreter/test module/test objspace/std/test

mwh at codespeak.net mwh at codespeak.net
Tue May 27 15:17:37 CEST 2003


Author: mwh
Date: Tue May 27 15:17:36 2003
New Revision: 557

Added:
   pypy/trunk/src/pypy/appspace/test/testsupport.py
Removed:
   pypy/trunk/src/pypy/appspace/test/setpath.py
Modified:
   pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py
   pypy/trunk/src/pypy/appspace/test/test_complexobject.py
   pypy/trunk/src/pypy/interpreter/test/testsupport.py
   pypy/trunk/src/pypy/module/test/testsupport.py
   pypy/trunk/src/pypy/objspace/std/test/testsupport.py
   pypy/trunk/src/pypy/testsupport.py
Log:
testsupport tweaks.

appspace tests probably bust, please hold the line.


Deleted: pypy/trunk/src/pypy/appspace/test/setpath.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/test/setpath.py	Tue May 27 15:17:36 2003
+++ (empty file)
@@ -1,15 +0,0 @@
-import sys, os
-
-dirname = os.path.dirname
-
-testdir   = dirname(os.path.abspath(__file__))
-parentdir = dirname(testdir)
-rootdir   = dirname(parentdir)
-
-del dirname
-
-sys.path.insert(0, rootdir)
-
-# rootdir should probably be one level up, since then you
-# could really import pypy.appsapce... and not just from
-# appspace... 

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	Tue May 27 15:17:36 2003
@@ -14,11 +14,11 @@
 import sys
 import types
 import unittest
+import testsupport
 
 try:
-    import setpath
-    from appspace import cmathmodule
-    from appspace.complexobject import complex as pycomplex
+    from pypy.appspace import cmathmodule
+    from pypy.appspace.complexobject import complex as pycomplex
 except ImportError:
     import cmathmodule
     from complexobject import complex as pycomplex

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	Tue May 27 15:17:36 2003
@@ -160,13 +160,13 @@
             self.assert_(equal(dc, dp))
 
             if not equal(z1c, complex(0,0)): 
-                try:
+#                try:
                     qc = z0c/z1c
                     qp = z0p/z1p
                     self.assert_(equal(qc, qp))
-                except AssertionError:
-                    print "c: (%s/%s) = (%s)" % (z0c, z1c, qc)
-                    print "py:(%s/%s) = (%s)" % (z0p, z1p, qp)
+#                except AssertionError:
+#                    print "c: (%s/%s) = (%s)" % (z0c, z1c, qc)
+#                    print "py:(%s/%s) = (%s)" % (z0p, z1p, qp)
 
                 
     def test_special(self):
@@ -195,16 +195,16 @@
             self.assert_(equal(mc, mp))
 
             if not equal(z1c, complex(0,0)): 
-                try:
+#                try:
                     ddc, mmc = divmod(z0c, z1c)
                     self.assert_(ddc*z1c + mmc == z0c)
                     ddp, mmp = divmod(z0p, z1p)
                     # self.assert_(ddp*z1p + mmp == z0p)
                     self.assert_(equal(ddc, ddp))
                     self.assert_(equal(mmc, mmp))
-                except AssertionError:
-                    print "c: divmod(%s,%s) = (%s,%s)" % (z0c, z1c, ddc,mmc)
-                    print "py:divmod(%s,%s) = (%s,%s)" % (z0p, z1p, ddp,mmp)
+#                except AssertionError:
+#                    print "c: divmod(%s,%s) = (%s,%s)" % (z0c, z1c, ddc,mmc)
+#                    print "py:divmod(%s,%s) = (%s,%s)" % (z0p, z1p, ddp,mmp)
 
 
     def test_mod(self):
@@ -216,13 +216,13 @@
             self.assert_(equal(mc, mp))
 
             if not equal(z1c, complex(0,0)): 
-                try:
+#                try:
                     rc = z0c%z1c
                     rp = z0p%z1p
                     self.assert_(equal(rc, rp))
-                except AssertionError:
-                    print "c: %s%%%s = %s" % (z0c, z1c, rc)
-                    print "py:%s%%%s = %s" % (z0p, z1p, rp)
+#                except AssertionError:
+#                    print "c: %s%%%s = %s" % (z0c, z1c, rc)
+#                    print "py:%s%%%s = %s" % (z0p, z1p, rp)
                     
 
     def test_pow(self):

Added: pypy/trunk/src/pypy/appspace/test/testsupport.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/appspace/test/testsupport.py	Tue May 27 15:17:36 2003
@@ -0,0 +1,63 @@
+"""
+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:
+    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
+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])))

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 15:17:36 2003
@@ -26,7 +26,10 @@
 try:
     head = this_path = os.path.abspath(__file__)
 except NameError:
-    head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+    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:

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 15:17:36 2003
@@ -26,7 +26,10 @@
 try:
     head = this_path = os.path.abspath(__file__)
 except NameError:
-    head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+    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:

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 15:17:36 2003
@@ -26,7 +26,10 @@
 try:
     head = this_path = os.path.abspath(__file__)
 except NameError:
-    head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+    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:

Modified: pypy/trunk/src/pypy/testsupport.py
==============================================================================
--- pypy/trunk/src/pypy/testsupport.py	(original)
+++ pypy/trunk/src/pypy/testsupport.py	Tue May 27 15:17:36 2003
@@ -26,7 +26,10 @@
 try:
     head = this_path = os.path.abspath(__file__)
 except NameError:
-    head = this_path = os.path.abspath(os.path.dirname(sys.argv[0]))
+    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:


More information about the Pypy-commit mailing list