[pypy-svn] r7364 - in pypy/trunk/src/pypy: appspace appspace/test module/test

arigo at codespeak.net arigo at codespeak.net
Thu Nov 18 12:07:01 CET 2004


Author: arigo
Date: Thu Nov 18 12:07:01 2004
New Revision: 7364

Added:
   pypy/trunk/src/pypy/appspace/test/no_test_stringmodule.py
      - copied unchanged from r7360, pypy/trunk/src/pypy/appspace/test/test_stringmodule.py
   pypy/trunk/src/pypy/module/test/applevel_in_cpython.py
Removed:
   pypy/trunk/src/pypy/appspace/test/test_stringmodule.py
Modified:
   pypy/trunk/src/pypy/appspace/cmathmodule.py
   pypy/trunk/src/pypy/appspace/test/test_cmathmodule.py
   pypy/trunk/src/pypy/appspace/test/test_complexobject.py
Log:
Fixed the tests in appspace; most of them didn't import.

Directly testing the class 'complex' buried in __builtin__module.py is funny,
beacuse it's difficult to import this __builtin__module.py directly into
CPython.  Well, it's not impossible, given sufficiently obscure hacks.  Yadda
yadda boum.  Committing applevel_in_cpython.py for that purpose, i.e.: testing
directly in CPython some of the app-level code written in the
module/*module.py files.

That's obviously a wrong solution.  We need something more like splitting the
module/*module.py into several files (e.g. class complex:...) and most of them
could just be imported in CPython too.



Modified: pypy/trunk/src/pypy/appspace/cmathmodule.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/cmathmodule.py	(original)
+++ pypy/trunk/src/pypy/appspace/cmathmodule.py	Thu Nov 18 12:07:01 2004
@@ -6,7 +6,6 @@
 # much code borrowed from mathmodule.c
 
 import math
-from complexobject import complex
 
 M_PI = 3.141592653589793239
 

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	Thu Nov 18 12:07:01 2004
@@ -15,20 +15,22 @@
 import unittest
 import autopath
 
-#try:
 from pypy.tool import testit
 from pypy.appspace import cmathmodule
-from pypy.appspace.complexobject import complex as pycomplex
-#except ImportError:
-#    import cmathmodule
-#    from pypy.complexobject import complex as pycomplex
+from pypy.appspace.test.test_complexobject import equal
 
-from pypy.appspace.test.test_complexobject import equal, enumerate
+def enumerate():
+    valueRange = [-12.34, -3, -1, -0.5, 0, 0.5, 1, 3, 12.34]
+    res = []
+    for x0 in valueRange:
+        for y0 in valueRange:
+            z = complex(x0,y0)
+            res.append(z)
+    return res
 
 
-if 0:    # DISABLED -- we know it works all right and don't want to see them
-         #             take time any more for the time being
-  class TestCMathModule(testit.TestCase):
+
+class TestCMathModule(testit.TestCase):
 
     def assertAEqual(self, a, b):
         if not equal(a, b):
@@ -37,35 +39,26 @@
     def test_funcs(self):
         "Compare many functions with CPython."
         
-        for (z0c, z1c, z0p, z1p) in enumerate():
-            mc = z0c*z1c
-            mp = z0p*z1p
-            self.assertAEqual(mc, mp)
+        for z in enumerate():
 
             for op in "sqrt acos acosh asin asinh atan atanh cos cosh exp".split():
-                if op == "atan" and equal(z0c, complex(0,-1)) or equal(z0c, complex(0,1)):
+                if op == "atan" and equal(z, complex(0,-1)) or equal(z, complex(0,1)):
                     continue
-                if op == "atanh" and equal(z0c, complex(-1,0)) or equal(z0c, complex(1,0)):
+                if op == "atanh" and equal(z, complex(-1,0)) or equal(z, complex(1,0)):
                     continue
-                op0 = cmath.__dict__[op](z0c)
-                op1 = cmathmodule.__dict__[op](z0p)
+                op0 = cmath.__dict__[op](z)
+                op1 = cmathmodule.__dict__[op](z)
                 self.assertAEqual(op0, op1)
 
-            # check divisions
-            if equal(z0c, complex(0,0)) or equal(z1c, complex(0,0)):
-                continue
-            self.assertAEqual(mc/z0c, mp/z0p)
-            self.assertAEqual(mc/z1c, mp/z1p)
-
 
     def test_log_log10(self):
         "Compare log/log10 functions with CPython."
         
-        for (z0c, z1c, z0p, z1p) in enumerate():
+        for z in enumerate():
             for op in "log log10".split():
-                if z0p != 0:
-                    op0 = cmath.__dict__[op](z0c)
-                    op1 = cmathmodule.__dict__[op](z0p)
+                if z != 0:
+                    op0 = cmath.__dict__[op](z)
+                    op1 = cmathmodule.__dict__[op](z)
                     self.assertAEqual(op0, op1)
 
 

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	Thu Nov 18 12:07:01 2004
@@ -27,7 +27,10 @@
 import unittest
 
 from pypy.tool import testit
-from pypy.appspace.complexobject import complex as pycomplex
+#from pypy.appspace.complexobject import complex as pycomplex
+from pypy.module.test.applevel_in_cpython import applevel_in_cpython
+our_own_builtin = applevel_in_cpython('__builtin__')
+pycomplex = our_own_builtin.complex
     
 
 try:
@@ -60,7 +63,7 @@
 
 
 def enumerate():
-    valueRange = xrange(-3, 3)
+    valueRange = [-3, -0.5, 0, 1]
     res = []
     for x0 in valueRange:
         for y0 in valueRange:
@@ -76,9 +79,7 @@
 
 
 
-if 0:    # DISABLED -- we know it works all right and don't want to see them
-         #             take time any more for the time being
-  class TestComplex(unittest.TestCase):
+class TestComplex(unittest.TestCase):
 
     def assertAEqual(self, a, b):
         if not equal(a, b):

Deleted: /pypy/trunk/src/pypy/appspace/test/test_stringmodule.py
==============================================================================
--- /pypy/trunk/src/pypy/appspace/test/test_stringmodule.py	Thu Nov 18 12:07:01 2004
+++ (empty file)
@@ -1,39 +0,0 @@
-#!/usr/bin/env python
-
-
-"""
-Test module for functions in stringmodule.py
-
-"""
-
-import string as c_py_string
-import unittest
-
-import autopath
-from pypy.tool import testit
-from pypy.appspace import string as pypy_string
-
-class TestStringmodule(unittest.TestCase):
-    def regression(self, sFuncname, *args, **kwargs):
-        try:
-            c_py_res = getattr(c_py_string, sFuncname)(*args, **kwargs)
-        except Exception, ce:
-            c_py_res = ce.__class__
-        
-        try:
-            pypy_res = getattr(pypy_string, sFuncname)(*args, **kwargs)
-        except Exception, pe:
-            pypy_res = pe.__class__
-        
-        self.assertEqual(c_py_res, pypy_res, 'not equal \n1:<%s>\n2:<%s>' % (c_py_res, pypy_res))
-
-
-    def test_maketrans(self):
-        self.regression('maketrans','','')
-        self.regression('maketrans','a','b')
-        self.regression('maketrans','aa','bb')
-        self.regression('maketrans','aa','')
-
-
-if __name__ == "__main__":
-    testit.main()
\ No newline at end of file

Added: pypy/trunk/src/pypy/module/test/applevel_in_cpython.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/applevel_in_cpython.py	Thu Nov 18 12:07:01 2004
@@ -0,0 +1,55 @@
+"""
+Hack to (partially) import the app-level parts of PyPy modules
+directly in CPython, when the goal is to test these app-level parts and
+not necessarily PyPy's interpretation of them.
+"""
+
+import autopath, new, sys
+
+
+def applevel_in_cpython(modulename):
+    try:
+        real_mod = __import__(modulename)
+    except ImportError:
+        real_mod = None
+
+    class DunnoType:
+        def __repr__(self):
+            return "<this would come from interp-level if we had one>"
+    Dunno = DunnoType()
+
+    def ouack_eval(s):
+        return {
+            'space.w_None': None,
+            'space.w_False': False,
+            'space.w_True': True,
+            'space.w_type': type,
+            'space.w_object': object,
+            'space.wrap(unicode)': unicode,
+            'space.wrap(file)': file,
+            }.get(s, Dunno)
+
+    def ouack_execfile(s):
+        pass
+
+    class OuackModule:
+        def __getattr__(self, name):
+            return getattr(real_mod, name, Dunno)
+    ouack_module = OuackModule()
+    ouack_module._issubtype = issubclass
+
+
+    from os.path import join
+    filename = join(autopath.pypydir, 'module', '%smodule.py' % modulename)
+    mod = new.module('applevel_in_cpython:%s' % modulename)
+    mod.__dict__.update({
+        '__file__': filename,
+        '__interplevel__eval': ouack_eval,
+        '__interplevel__execfile': ouack_execfile,
+        })
+    sys.modules['__interplevel__'] = ouack_module
+    try:
+        execfile(filename, mod.__dict__)
+    finally:
+        del sys.modules['__interplevel__']
+    return mod



More information about the Pypy-commit mailing list