[pypy-svn] r10918 - in pypy/dist: lib-python-2.3.4/test pypy/lib/test2

hpk at codespeak.net hpk at codespeak.net
Wed Apr 20 15:08:24 CEST 2005


Author: hpk
Date: Wed Apr 20 15:08:24 2005
New Revision: 10918

Modified:
   pypy/dist/lib-python-2.3.4/test/conftest.py
   pypy/dist/pypy/lib/test2/conftest.py
Log:
lib/test2 is enabled again but only for running tests 
against CPython.  There also is a test map now just
for the lib/test2 hierarchy.  

test_sha.py and test_itertools.py pass but the latter 
fails one test on CPython because of our particular 
pypy/lib/itertools.py slice implementation (i think) 

Note that just running 'python test_itertools.py' 
will suceed because it doesn't use our 'pypy/lib/itertools.py' 
implementation. 



Modified: pypy/dist/lib-python-2.3.4/test/conftest.py
==============================================================================
--- pypy/dist/lib-python-2.3.4/test/conftest.py	(original)
+++ pypy/dist/lib-python-2.3.4/test/conftest.py	Wed Apr 20 15:08:24 2005
@@ -44,24 +44,6 @@
             raise KeyboardInterrupt 
         raise
     
-class RegrDirectory(py.test.collect.Directory): 
-    def run(self): 
-        l = []
-        items = testmap.items() 
-        items.sort(lambda x,y: cmp(x[0].lower(), y[0].lower()))
-        for name, testdecl in items: 
-            if testdecl.enabled: 
-                l.append(name) 
-        return l 
-
-    def join(self, name): 
-        if name not in testmap: 
-            raise NameError(name) 
-        testdecl = testmap[name]
-        return testdecl.testclass(mydir.join(name), parent=self) 
-
-Directory = RegrDirectory
-
 w_testlist = None 
 
 def hack_test_support(space): 
@@ -625,3 +607,23 @@
     'test_zlib.py'           : TestDecl(False, UTModuleMainTest),
         #ImportError: zlib
 }
+
+class RegrDirectory(py.test.collect.Directory): 
+    testmap = testmap
+    def run(self): 
+        l = []
+        items = self.testmap.items() 
+        items.sort(lambda x,y: cmp(x[0].lower(), y[0].lower()))
+        for name, testdecl in items: 
+            if testdecl.enabled: 
+                l.append(name) 
+        return l 
+
+    def join(self, name): 
+        if name not in self.testmap: 
+            raise NameError(name) 
+        testdecl = self.testmap[name]
+        return testdecl.testclass(self.fspath.join(name), parent=self) 
+
+Directory = RegrDirectory
+

Modified: pypy/dist/pypy/lib/test2/conftest.py
==============================================================================
--- pypy/dist/pypy/lib/test2/conftest.py	(original)
+++ pypy/dist/pypy/lib/test2/conftest.py	Wed Apr 20 15:08:24 2005
@@ -6,7 +6,7 @@
 
 ModuleType = type(sys)
 
-def make_cpy_module(dottedname, filepath, force=False): 
+def make_cpy_module(dottedname, filepath, force=True): 
     try:
         if force: 
             raise KeyError 
@@ -14,62 +14,87 @@
     except KeyError: 
         mod = ModuleType(dottedname)
         execfile(str(filepath), mod.__dict__)
+        #print "setting sys.modules[%s] = %s" % (dottedname, mod)
         sys.modules[dottedname] = mod
         return mod    
 
 libtest = py.path.local(pypy.__file__).dirpath()
 libtest = libtest.dirpath('lib-python-2.3.4', 'test')
-#conftest = libtest.join('conftest.py').pyimport()
+libconftest = libtest.join('conftest.py').getpymodule()  # read())
 
-def Module(fspath, parent=None): 
-    if option.allpypy: 
-        return conftest.Module(fspath, parent=parent) 
-    return UnittestModuleOnCPython(fspath, parent=parent) 
+testlist = None 
+doctestmodulelist = None
 
-class Directory(py.test.collect.Directory): 
-    def run(self): 
-        return []
-
-class UnittestModuleOnCPython(py.test.collect.Module): 
-    def _prepare(self): 
-        mod = make_cpy_module('unittest', libtest.join('pypy_unittest.py'), force=True) 
-        sys.modules['unittest'] = mod 
+def hack_test_support_cpython(): 
+    global testlist, doctestmodulelist 
+    if testlist is None: 
+        testlist = []
+        doctestmodulelist = []
+        mod = make_cpy_module('unittest', libtest.join('pypy_unittest.py', force=True))
         mod.raises = py.test.raises 
-        self.TestCase = mod.TestCase 
+
+        def hack_run_unittest(*classes): 
+            testlist.extend(list(classes))
+        def hack_run_doctest(name, verbose=None): 
+            doctestmodulelist.append(name) 
+            
+        from test import test_support 
+        test_support.run_unittest = hack_run_unittest 
+        test_support.run_doctest = hack_run_doctest  
+    return sys.modules['unittest']
+
+class UTModuleOnCPython(py.test.collect.Module): 
+    def __init__(self, fspath, parent): 
+        super(UTModuleOnCPython, self).__init__(fspath, parent) 
+        mod = hack_test_support_cpython() 
+        self.TestCaseClass = getattr(mod, 'TestCase') 
+        
+        name = self.fspath.purebasename 
+        mod = self._obj = make_cpy_module(name, self.fspath, force=True) 
+
+        # hack out the test case classes for this module 
+        testlist[:] = []
+        mod.test_main() 
+        
+        self._testcases = [(cls.__name__, cls) for cls in testlist]
+        self._testcases.sort() 
        
     def run(self): 
-        self._prepare() 
-        try: 
-            iterable = self._cache 
-        except AttributeError: 
-            iterable = self._cache = list(self._iter())
-        return list(iterable) 
+        return [x[0] for x in self._testcases]
 
-    def _iter(self): 
-        name = self.fspath.purebasename 
-        mod = make_cpy_module(name, self.fspath) 
-        print mod
-        tlist = conftest.app_list_testmethods(mod, self.TestCase, [])
-        for (setup, teardown, methods) in tlist: 
-            for name, method in methods: 
-                yield CpyTestCaseMethod(self.fspath, name, method, 
-                                        setup, teardown) 
-
-class CpyTestCaseMethod(py.test.Item): 
-    def __init__(self, fspath, name, method, setup, teardown): 
-        self.name = name  
-        extpy = py.path.extpy(fspath, name) 
-        super(CpyTestCaseMethod, self).__init__(extpy) 
-        self.method = method 
-        self.setup = setup 
-        self.teardown = teardown 
+    def join(self, name): 
+        for x,cls in self._testcases: 
+            if x == name: 
+                return UTTestCase(name, parent=self, cls=cls) 
 
-    def run(self, driver):      
-        self.setup() 
+class UTTestCaseMethod(py.test.Function): 
+    def run(self): 
+        method = self.obj
+        setup = method.im_self.setUp 
+        teardown = method.im_self.tearDown
+        setup() 
         try: 
-            self.execute() 
+            method() 
         finally: 
-            self.teardown() 
+            teardown()
+
+class UTTestCaseInstance(py.test.collect.Instance): 
+    Function = UTTestCaseMethod 
+
+class UTTestCase(py.test.collect.Class): 
+    Instance = UTTestCaseInstance 
+
+    def __init__(self, name, parent, cls): 
+        super(UTTestCase, self).__init__(name, parent) 
+        self._obj = cls 
+
+TestDecl = libconftest.TestDecl 
+
+testmap = {
+    'test_itertools.py' : TestDecl(True, UTModuleOnCPython), 
+    'test_sha.py'        : TestDecl(True, UTModuleOnCPython), 
+}
+
+class Directory(libconftest.Directory): 
+    testmap = testmap 
 
-    def execute(self): 
-        return self.method() 



More information about the Pypy-commit mailing list