[pypy-svn] r9997 - in pypy/dist/pypy/module: builtin test

hpk at codespeak.net hpk at codespeak.net
Mon Mar 21 17:25:53 CET 2005


Author: hpk
Date: Mon Mar 21 17:25:53 2005
New Revision: 9997

Modified:
   pypy/dist/pypy/module/builtin/app_io.py
   pypy/dist/pypy/module/test/test_builtin.py
Log:
execfile() needs to work with both dos/unix lineending-styles


Modified: pypy/dist/pypy/module/builtin/app_io.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_io.py	(original)
+++ pypy/dist/pypy/module/builtin/app_io.py	Mon Mar 21 17:25:53 2005
@@ -12,7 +12,7 @@
             loc = caller.f_locals
     elif loc is None:
         loc = glob
-    f = file(filename)
+    f = file(filename, 'rU')
     try:
         source = f.read()
     finally:

Modified: pypy/dist/pypy/module/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/module/test/test_builtin.py	(original)
+++ pypy/dist/pypy/module/test/test_builtin.py	Mon Mar 21 17:25:53 2005
@@ -397,3 +397,32 @@
             space.wrap(fn), w_dict, space.w_None)
         w_value = space.getitem(w_dict, space.wrap('i'))
         assert self.space.eq_w(w_value, space.wrap(42))
+
+    def test_execfile_different_lineendings(self): 
+        space = self.space
+        from pypy.tool.udir import udir
+        d = udir.ensure('lineending', dir=1)
+        dos = d.join('dos.py') 
+        f = dos.open('wb') 
+        f.write("x=3\r\n\r\ny=4\r\n")
+        f.close() 
+        space.appexec([space.wrap(str(dos))], """
+            (filename): 
+                d = {}
+                execfile(filename, d)
+                assert d['x'] == 3
+                assert d['y'] == 4
+        """)
+
+        unix = d.join('unix.py')
+        f = unix.open('wb') 
+        f.write("x=5\n\ny=6\n")
+        f.close() 
+
+        space.appexec([space.wrap(str(unix))], """
+            (filename): 
+                d = {}
+                execfile(filename, d)
+                assert d['x'] == 5
+                assert d['y'] == 6
+        """)



More information about the Pypy-commit mailing list