[pypy-svn] r11497 - in pypy/dist: lib-python-2.3.4/test pypy/objspace/std

hpk at codespeak.net hpk at codespeak.net
Wed Apr 27 01:19:00 CEST 2005


Author: hpk
Date: Wed Apr 27 01:19:00 2005
New Revision: 11497

Modified:
   pypy/dist/lib-python-2.3.4/test/conftest.py
   pypy/dist/pypy/objspace/std/objspace.py
Log:
- extend test declarations to allow specification 
  oldstyle=True, first example: test_compare.py 

  specifying oldstyle=True will let a test run with 
  a default metaclass implementing oldstyle classes 

  by default tests are run with all new style. 
  


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 27 01:19:00 2005
@@ -137,7 +137,16 @@
         if name == 'apprun': 
             return RunAppFileItem(name, parent=self, fspath=self.fspath) 
 
-class RunAppFileItem(py.test.Item): 
+class TestDeclMixin(object): 
+    def testdecl(self): 
+        current = self.parent 
+        while current is not None: 
+            if hasattr(current, 'testdecl'): 
+                return current.testdecl 
+            current = self.sparent 
+    testdecl = property(testdecl) 
+
+class RunAppFileItem(py.test.Item, TestDeclMixin): 
     """ simple run a module file at app level, fail the test 
         if running the appfile results in an OperationError. 
     """
@@ -146,16 +155,26 @@
         self.fspath = fspath 
         self.space = getmyspace()
 
+
     def getfspath(self): 
         if self.parent.testdecl.modified: 
             return pypydir.join('lib', 'test2', self.fspath.basename) 
         else: 
             return self.fspath # unmodified regrtest
 
+    def run_file(self, fspath): 
+        space = self.space 
+        if self.testdecl.oldstyle: 
+            space.enable_old_style_classes_as_default_metaclass() 
+        try: 
+            run_file(str(fspath), space) 
+        finally: 
+            space.enable_new_style_classes_as_default_metaclass() 
+
     def run(self): 
         fspath = self.getfspath() 
         try: 
-            run_file(str(fspath), self.space) 
+            self.run_file(fspath) 
         except OperationError, e: 
             space = self.space 
             if space and e.match(space, space.w_KeyboardInterrupt): 
@@ -216,7 +235,13 @@
             fspath = pypydir.join('lib', 'test2', self.fspath.basename) 
         else: 
             fspath = self.fspath 
-        w_mod = make_module(space, name, fspath) 
+
+        if self.testdecl.oldstyle: 
+            space.enable_old_style_classes_as_default_metaclass() 
+        try:  
+            w_mod = make_module(space, name, fspath) 
+        finally: 
+            space.enable_new_style_classes_as_default_metaclass() 
 
         # hack out testcases 
         space.appexec([w_mod, w_testlist], """ 
@@ -308,7 +333,7 @@
 
 class TestDecl: 
     """ Test Declaration.""" 
-    def __init__(self, enabled, testclass, modified=False): 
+    def __init__(self, enabled, testclass, modified=False, oldstyle=False): 
         """ if modified is True, the actual test item 
             needs to be taken from the pypy/lib/test2 
             hierarchy.  
@@ -316,6 +341,7 @@
         self.enabled = enabled 
         self.testclass = testclass 
         self.modified = modified 
+        self.oldstyle = True 
 
 testmap = {
     'test_MimeWriter.py'     : TestDecl(False, OutputTestModule),
@@ -375,7 +401,7 @@
     'test_codeop.py'         : TestDecl(True,  UTTestMainModule),
     'test_coercion.py'       : TestDecl(False, OutputTestModule),
     'test_commands.py'       : TestDecl(True,  UTTestMainModule),
-    'test_compare.py'        : TestDecl(True,  OutputTestModule),
+    'test_compare.py'        : TestDecl(True,  OutputTestModule, oldstyle=True),
     'test_compile.py'        : TestDecl(True,  UTTestMainModule),
     'test_complex.py'        : TestDecl(False, UTTestMainModule),
         #rev 10840: at least one test fails, after several hours I gave up waiting for the rest

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Wed Apr 27 01:19:00 2005
@@ -98,6 +98,14 @@
     def enable_old_style_classes_as_default_metaclass(self):
         self.setitem(self.builtin.w_dict, self.wrap('__metaclass__'), self.w_classobj)
 
+    def enable_new_style_classes_as_default_metaclass(self):
+        space = self
+        try: 
+            self.delitem(self.builtin.w_dict, self.wrap('__metaclass__')) 
+        except OperationError, e: 
+            if not e.match(space, space.w_KeyError): 
+                raise 
+
     def setup_old_style_classes(self):
         """NOT_RPYTHON"""
         from pypy.module import classobjinterp



More information about the Pypy-commit mailing list