Skip to content

Commit 94b6723

Browse files
committed
Get all tests in past.builtins.test_builtins passing again on Py2
This disables the execfile() reimplementation on Py2. The Py3 one is still broken.
1 parent 45da4e0 commit 94b6723

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

past/builtins/misc.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def apply(f, *args, **kw):
1818
import __builtin__
1919
apply = __builtin__.apply
2020
cmp = __builtin__.cmp
21+
execfile = __builtin__.execfile
2122
intern = __builtin__.intern
2223
raw_input = __builtin__.raw_input
2324
reload = __builtin__.reload
@@ -30,50 +31,52 @@ def apply(f, *args, **kw):
3031
def execfile(filename, myglobals=None, mylocals=None):
3132
"""
3233
A version of execfile() that handles unicode filenames.
33-
3434
From IPython.
35+
36+
WARNING: This doesn't seem to work. We may need to use inspect to
37+
get the globals and locals dicts from the calling context.
3538
"""
3639
mylocals = mylocals if (mylocals is not None) else myglobals
3740
exec_(compile(open(filename).read(), filename, 'exec'),
3841
myglobals, mylocals)
3942

40-
else:
41-
def execfile(filename, myglobals=None, mylocals=None):
42-
"""
43-
A version of execfile() for Py2 that handles unicode filenames.
44-
This is useful if "from __future__ import unicode_literals" is in
45-
effect.
46-
47-
From IPython.
48-
"""
49-
if sys.platform == 'win32':
50-
# The rstrip() is necessary b/c trailing whitespace in
51-
# files will cause an IndentationError in Python 2.6
52-
# (this was fixed in 2.7). See IPython issue 1027.
53-
scripttext = __builtin__.open(filename).read().rstrip() + '\n'
54-
# compile converts unicode filename to str assuming
55-
# ascii. Let's do the conversion before calling compile
56-
if isinstance(filename, unicode):
57-
filename = filename.encode(unicode, 'replace')
58-
# else:
59-
# filename = filename
60-
exec_(compile(scripttext, filename, 'exec') in glob, loc)
61-
else:
62-
if isinstance(filename, unicode):
63-
filename = filename.encode(sys.getfilesystemencoding())
64-
else:
65-
filename = filename
66-
if mylocals is not None:
67-
if myglobals is not None:
68-
__builtin__.execfile(filename, myglobals, mylocals)
69-
else:
70-
raise ValueError(
71-
'globals argument is required if locals is passed')
72-
else:
73-
if myglobals is not None:
74-
__builtin__.execfile(filename, myglobals)
75-
else:
76-
__builtin__.execfile(filename)
43+
# else:
44+
# def execfile(filename, myglobals=None, mylocals=None):
45+
# """
46+
# A version of execfile() for Py2 that handles unicode filenames.
47+
# This is useful if "from __future__ import unicode_literals" is in
48+
# effect.
49+
#
50+
# From IPython.
51+
# """
52+
# if sys.platform == 'win32':
53+
# # The rstrip() is necessary b/c trailing whitespace in
54+
# # files will cause an IndentationError in Python 2.6
55+
# # (this was fixed in 2.7). See IPython issue 1027.
56+
# scripttext = __builtin__.open(filename).read().rstrip() + '\n'
57+
# # compile converts unicode filename to str assuming
58+
# # ascii. Let's do the conversion before calling compile
59+
# if isinstance(filename, unicode):
60+
# filename = filename.encode(unicode, 'replace')
61+
# # else:
62+
# # filename = filename
63+
# exec_(compile(scripttext, filename, 'exec') in glob, loc)
64+
# else:
65+
# if isinstance(filename, unicode):
66+
# filename = filename.encode(sys.getfilesystemencoding())
67+
# else:
68+
# filename = filename
69+
# if mylocals is not None:
70+
# if myglobals is not None:
71+
# __builtin__.execfile(filename, myglobals, mylocals)
72+
# else:
73+
# raise ValueError(
74+
# 'globals argument is required if locals is passed')
75+
# else:
76+
# if myglobals is not None:
77+
# __builtin__.execfile(filename, myglobals)
78+
# else:
79+
# __builtin__.execfile(filename)
7780

7881
if PY3:
7982
__all__ = ['apply', 'cmp', 'execfile', 'intern', 'raw_input',

past/tests/test_builtins.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,20 @@ def __coerce__(self, other):
268268
self.assertRaises(OverflowError, coerce, 0.5, int("12345" * 1000))
269269

270270
def test_compile(self):
271-
compile('print 1\n', '', 'exec')
271+
compile('print(1)\n', '', 'exec')
272272
bom = '\xef\xbb\xbf'
273-
compile(bom + 'print 1\n', '', 'exec')
273+
compile(bom + 'print(1)\n', '', 'exec')
274274
compile(source='pass', filename='?', mode='exec')
275275
compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
276276
compile('pass', '?', dont_inherit=1, mode='exec')
277277
self.assertRaises(TypeError, compile)
278-
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'badmode')
279-
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'single', 0xff)
278+
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
279+
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)
280280
self.assertRaises(TypeError, compile, chr(0), 'f', 'exec')
281281
self.assertRaises(TypeError, compile, 'pass', '?', 'exec',
282282
mode='eval', source='0', filename='tmp')
283283
if True: # Was: if have_unicode:
284-
compile(unicode('print u"\xc3\xa5"\n', 'utf8'), '', 'exec')
284+
compile(unicode('print(u"\xc3\xa5"\n)', 'utf8'), '', 'exec')
285285
self.assertRaises(TypeError, compile, unichr(0), 'f', 'exec')
286286
self.assertRaises(ValueError, compile, unicode('a = 1'), 'f', 'bad')
287287

@@ -484,8 +484,7 @@ def keys(self):
484484
if True:
485485
# with check_py3k_warnings(("execfile.. not supported in 3.x",
486486
# DeprecationWarning)):
487-
# execfile(TESTFN)
488-
pass
487+
execfile(TESTFN)
489488

490489
def test_execfile(self):
491490
global numruns
@@ -988,9 +987,9 @@ def gen():
988987

989988
def test_oct(self):
990989
self.assertEqual(oct(100), '0144')
991-
self.assertEqual(oct(100), '0144L')
990+
# self.assertEqual(oct(100L), '0144L')
992991
self.assertEqual(oct(-100), '-0144')
993-
self.assertEqual(oct(-100), '-0144L')
992+
# self.assertEqual(oct(-100L), '-0144L')
994993
self.assertRaises(TypeError, oct, ())
995994

996995
def write_testfile(self):
@@ -1235,12 +1234,12 @@ def test_input_and_raw_input(self):
12351234
# SF 876178: make sure input() respect future options.
12361235
sys.stdin = io.BytesIO(b'1/2')
12371236
sys.stdout = io.BytesIO()
1238-
exec(compile('print input()', 'test_builtin_tmp', 'exec'))
1237+
exec(compile('print(input())', 'test_builtin_tmp', 'exec'))
12391238
sys.stdin.seek(0, 0)
1240-
exec(compile('from __future__ import division;print input()',
1239+
exec(compile('from __future__ import division;print(input())',
12411240
'test_builtin_tmp', 'exec'))
12421241
sys.stdin.seek(0, 0)
1243-
exec(compile('print input()', 'test_builtin_tmp', 'exec'))
1242+
exec(compile('print(input())', 'test_builtin_tmp', 'exec'))
12441243
# The result we expect depends on whether new division semantics
12451244
# are already in effect.
12461245
if 1/2 == 0:

0 commit comments

Comments
 (0)