summaryrefslogtreecommitdiff
path: root/tests/test_execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-10-26 10:34:56 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-10-26 10:34:56 -0400
commit9b8e67fe48ca5d9d1d6e1a7f03eac625388cc7c7 (patch)
tree721cbf5feaa985459a02535bd20a2a98c1ceb479 /tests/test_execfile.py
parentafc7a3856f9e85d1516822c80deeab0fed41532a (diff)
downloadpython-coveragepy-git-9b8e67fe48ca5d9d1d6e1a7f03eac625388cc7c7.tar.gz
Use with-open everywhere
Diffstat (limited to 'tests/test_execfile.py')
-rw-r--r--tests/test_execfile.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index 3a92ff76..63fb919d 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -66,7 +66,8 @@ class RunFileTest(CoverageTest):
a = 1
print("a is %r" % a)
#""")
- abrupt = open("abrupt.py").read()
+ with open("abrupt.py") as f:
+ abrupt = f.read()
self.assertEqual(abrupt[-1], '#')
run_python_file("abrupt.py", ["abrupt.py"])
self.assertEqual(self.stdout(), "a is 1\n")
@@ -113,10 +114,9 @@ class RunPycFileTest(CoverageTest):
pycfile = self.make_pyc()
# Jam Python 2.1 magic number into the .pyc file.
- fpyc = open(pycfile, "r+b")
- fpyc.seek(0)
- fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))
- fpyc.close()
+ with open(pycfile, "r+b") as fpyc:
+ fpyc.seek(0)
+ fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))
with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"):
run_python_file(pycfile, [pycfile])