summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-10-29 23:47:23 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-10-29 23:47:23 (GMT)
commit749afa95ce28ffded9c6f75c776dae15cade6ecb (patch)
tree2f4dc1c45dd98f3df23dff00d3f62ec74cdbb3ac /Lib
parent105df5d75b2e8e07acc7f52477a50b2fcaa82a3c (diff)
downloadcpython-749afa95ce28ffded9c6f75c776dae15cade6ecb.zip
cpython-749afa95ce28ffded9c6f75c776dae15cade6ecb.tar.gz
cpython-749afa95ce28ffded9c6f75c776dae15cade6ecb.tar.bz2
Move test_imp over to file context managers.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_imp.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index b291ded..3aa0fc0 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -55,27 +55,27 @@ class ImportTests(unittest.TestCase):
def test_find_module_encoding(self):
for mod, encoding, _ in self.test_strings:
- fd = imp.find_module('module_' + mod, self.test_path)[0]
- self.assertEqual(fd.encoding, encoding)
+ with imp.find_module('module_' + mod, self.test_path)[0] as fd:
+ self.assertEqual(fd.encoding, encoding)
def test_issue1267(self):
for mod, encoding, _ in self.test_strings:
fp, filename, info = imp.find_module('module_' + mod,
self.test_path)
- self.assertNotEqual(fp, None)
- self.assertEqual(fp.encoding, encoding)
- self.assertEqual(fp.tell(), 0)
- self.assertEqual(fp.readline(), '# test %s encoding\n'
- % encoding)
- fp.close()
+ with fp:
+ self.assertNotEqual(fp, None)
+ self.assertEqual(fp.encoding, encoding)
+ self.assertEqual(fp.tell(), 0)
+ self.assertEqual(fp.readline(), '# test %s encoding\n'
+ % encoding)
fp, filename, info = imp.find_module("tokenize")
- self.assertNotEqual(fp, None)
- self.assertEqual(fp.encoding, "utf-8")
- self.assertEqual(fp.tell(), 0)
- self.assertEqual(fp.readline(),
- '"""Tokenization help for Python programs.\n')
- fp.close()
+ with fp:
+ self.assertNotEqual(fp, None)
+ self.assertEqual(fp.encoding, "utf-8")
+ self.assertEqual(fp.tell(), 0)
+ self.assertEqual(fp.readline(),
+ '"""Tokenization help for Python programs.\n')
def test_issue3594(self):
temp_mod_name = 'test_imp_helper'
@@ -140,15 +140,15 @@ class ImportTests(unittest.TestCase):
with open(temp_mod_name + '.py', 'w') as file:
file.write('a = 1\n')
file, filename, info = imp.find_module(temp_mod_name)
- self.assertIsNotNone(file)
- self.assertTrue(filename[:-3].endswith(temp_mod_name))
- self.assertEqual(info[0], '.py')
- self.assertEqual(info[1], 'U')
- self.assertEqual(info[2], imp.PY_SOURCE)
-
- mod = imp.load_module(temp_mod_name, file, filename, info)
- self.assertEqual(mod.a, 1)
- file.close()
+ with file:
+ self.assertIsNotNone(file)
+ self.assertTrue(filename[:-3].endswith(temp_mod_name))
+ self.assertEqual(info[0], '.py')
+ self.assertEqual(info[1], 'U')
+ self.assertEqual(info[2], imp.PY_SOURCE)
+
+ mod = imp.load_module(temp_mod_name, file, filename, info)
+ self.assertEqual(mod.a, 1)
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
self.assertEqual(mod.a, 1)