diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) |
commit | 92f60ed82a302035009835a8d63ff714118a96ad (patch) | |
tree | a119000028c02ecf0317859d0bcda37fe4c505b4 /Lib/test/test_shutil.py | |
parent | 73315e92009c88acf53e497a0b9fcd93cd735aed (diff) | |
download | cpython-92f60ed82a302035009835a8d63ff714118a96ad.zip cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.gz cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.bz2 |
More proper closing of files
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r-- | Lib/test/test_shutil.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index baa1943..81c9036 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -285,7 +285,8 @@ class TestShutil(unittest.TestCase): if hasattr(os, "link"): os.link(src, dst) self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - self.assertEqual(open(src,'r').read(), 'cheddar') + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') os.remove(dst) # Using `src` here would mean we end up with a symlink pointing @@ -293,7 +294,8 @@ class TestShutil(unittest.TestCase): # TESTFN/cheese. os.symlink('cheese', dst) self.assertRaises(shutil.Error, shutil.copyfile, src, dst) - self.assertEqual(open(src,'r').read(), 'cheddar') + with open(src, 'r') as f: + self.assertEqual(f.read(), 'cheddar') os.remove(dst) finally: try: @@ -690,9 +692,11 @@ class TestMove(unittest.TestCase): pass def _check_move_file(self, src, dst, real_dst): - contents = open(src, "rb").read() + with open(src, "rb") as f: + contents = f.read() shutil.move(src, dst) - self.assertEqual(contents, open(real_dst, "rb").read()) + with open(real_dst, "rb") as f: + self.assertEqual(contents, f.read()) self.assertFalse(os.path.exists(src)) def _check_move_dir(self, src, dst, real_dst): |