summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-08-12 00:43:29 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-08-12 00:43:29 (GMT)
commit016880229a369a3fb419f3eed28b6db7c342fe71 (patch)
tree9b11de5c197bc556dd515e035327673765cd4871 /Lib/test
parent41eaedd3613cebc83e6b9925499369992c7a7770 (diff)
downloadcpython-016880229a369a3fb419f3eed28b6db7c342fe71.zip
cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.gz
cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.bz2
Kill execfile(), use exec() instead
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_builtin.py55
-rw-r--r--Lib/test/test_multibytecodec.py2
-rw-r--r--Lib/test/test_pkg.py2
-rw-r--r--Lib/test/test_univnewlines.py7
4 files changed, 2 insertions, 64 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index a4ae21a..b430822 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -11,10 +11,6 @@ warnings.filterwarnings("ignore", "hex../oct.. of negative int",
warnings.filterwarnings("ignore", "integer argument expected",
DeprecationWarning, "unittest")
-# count the number of test runs.
-# used to skip running test_execfile() multiple times
-numruns = 0
-
class Squares:
def __init__(self, max):
@@ -399,57 +395,6 @@ class BuiltinTest(unittest.TestCase):
return 1 # used to be 'a' but that's no longer an error
self.assertRaises(TypeError, eval, 'dir()', globals(), C())
- # Done outside of the method test_z to get the correct scope
- z = 0
- f = open(TESTFN, 'w')
- f.write('z = z+1\n')
- f.write('z = z*2\n')
- f.close()
- execfile(TESTFN)
-
- def test_execfile(self):
- global numruns
- if numruns:
- return
- numruns += 1
-
- globals = {'a': 1, 'b': 2}
- locals = {'b': 200, 'c': 300}
-
- self.assertEqual(self.__class__.z, 2)
- globals['z'] = 0
- execfile(TESTFN, globals)
- self.assertEqual(globals['z'], 2)
- locals['z'] = 0
- execfile(TESTFN, globals, locals)
- self.assertEqual(locals['z'], 2)
-
- class M:
- "Test mapping interface versus possible calls from execfile()."
- def __init__(self):
- self.z = 10
- def __getitem__(self, key):
- if key == 'z':
- return self.z
- raise KeyError
- def __setitem__(self, key, value):
- if key == 'z':
- self.z = value
- return
- raise KeyError
-
- locals = M()
- locals['z'] = 0
- execfile(TESTFN, globals, locals)
- self.assertEqual(locals['z'], 2)
-
- unlink(TESTFN)
- self.assertRaises(TypeError, execfile)
- self.assertRaises(TypeError, execfile, TESTFN, {}, ())
- import os
- self.assertRaises(IOError, execfile, os.curdir)
- self.assertRaises(IOError, execfile, "I_dont_exist")
-
def test_exec(self):
g = {}
exec('z = 1', g)
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py
index 32c48fb..c2f34e5 100644
--- a/Lib/test/test_multibytecodec.py
+++ b/Lib/test/test_multibytecodec.py
@@ -49,7 +49,7 @@ class Test_MultibyteCodec(unittest.TestCase):
try:
for enc in ALL_CJKENCODINGS:
print('# coding:', enc, file=io.open(TESTFN, 'w'))
- execfile(TESTFN)
+ exec(open(TESTFN).read())
finally:
test_support.unlink(TESTFN)
diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py
index 1a3f2a9..907359b 100644
--- a/Lib/test/test_pkg.py
+++ b/Lib/test/test_pkg.py
@@ -63,7 +63,7 @@ def runtest(hier, code):
sys.path.insert(0, root)
if verbose: print("sys.path =", sys.path)
try:
- execfile(fname, globals(), {})
+ exec(open(fname).read(), globals(), {})
except:
traceback.print_exc(file=sys.stdout)
finally:
diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py
index ae4c442..7810cae 100644
--- a/Lib/test/test_univnewlines.py
+++ b/Lib/test/test_univnewlines.py
@@ -78,13 +78,6 @@ class TestGenericUnivNewlines(unittest.TestCase):
data = fp.readlines()
self.assertEqual(data, DATA_SPLIT[1:])
- def test_execfile(self):
- namespace = {}
- execfile(test_support.TESTFN, namespace)
- func = namespace['line3']
- self.assertEqual(func.__code__.co_firstlineno, 3)
- self.assertEqual(namespace['line4'], FATX)
-
class TestNativeNewlines(TestGenericUnivNewlines):
NEWLINE = None