[pypy-svn] rev 619 - in pypy/trunk/src/pypy/interpreter: . test

mwh at codespeak.net mwh at codespeak.net
Tue May 27 19:33:08 CEST 2003


Author: mwh
Date: Tue May 27 19:32:59 2003
New Revision: 619

Modified:
   pypy/trunk/src/pypy/interpreter/main.py
   pypy/trunk/src/pypy/interpreter/test/test_main.py
Log:
rehash main.py slightly to enable rewrite of test_main;
rewrite test_main so it works when part of a larger suite.


Modified: pypy/trunk/src/pypy/interpreter/main.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/main.py	(original)
+++ pypy/trunk/src/pypy/interpreter/main.py	Tue May 27 19:32:59 2003
@@ -3,10 +3,10 @@
 from pypy.interpreter import executioncontext, baseobjspace, pyframe
 import sys
 
-def run_string(source, fname):
-    space = None   # in case StdObjSpace.__init__() crashes
+def run_string(source, fname, space=None):
     try:
-        space = StdObjSpace()
+        if space is None:
+            space = StdObjSpace()
 
         compile = space.builtin.compile
         w=space.wrap
@@ -27,9 +27,9 @@
     else:
         ec.eval_frame(frame)
 
-def run_file(fname):
+def run_file(fname, space=None):
     istring = open(fname).read()
-    run_string(istring, fname)
+    run_string(istring, fname, space)
 
 def main(argv=None):
     if argv is None:

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	Tue May 27 19:32:59 2003
@@ -17,14 +17,15 @@
 capture = StringIO()
 
 def checkoutput(expected_output,f,*args):
-    import sys
-    oldout = sys.stdout
+    space = testsupport.objspace()
+    w_sys = space.get_builtin_module(space.wrap("sys"))
+    w_oldout = space.getattr(w_sys, space.wrap("stdout"))
+    capture.reset()
+    space.setattr(w_sys, space.wrap("stdout"), space.wrap(capture))
     try:
-        capture.reset()
-        sys.stdout = capture
-        f(*args)
+        f(*(args + (space,)))
     finally:
-        sys.stdout = oldout
+        space.setattr(w_sys, space.wrap("stdout"), w_oldout)
 
     return capture.getvalue() == expected_output
 


More information about the Pypy-commit mailing list