summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_filecmp.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-05-04 00:18:50 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-05-04 00:18:50 (GMT)
commit3d678e3b12b376dbb1f65fdff11b0c14bcc93bc6 (patch)
treea327367e1eb631099da2e49b909e716a3012509e /Lib/test/test_filecmp.py
parentf24600eb64ab0e643f49b961c1cbe3fbe957807a (diff)
downloadcpython-3d678e3b12b376dbb1f65fdff11b0c14bcc93bc6.zip
cpython-3d678e3b12b376dbb1f65fdff11b0c14bcc93bc6.tar.gz
cpython-3d678e3b12b376dbb1f65fdff11b0c14bcc93bc6.tar.bz2
use with blocks to make sure files are closed
Diffstat (limited to 'Lib/test/test_filecmp.py')
-rw-r--r--Lib/test/test_filecmp.py30
1 files changed, 12 insertions, 18 deletions
diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py
index d434c0a..429e3ff 100644
--- a/Lib/test/test_filecmp.py
+++ b/Lib/test/test_filecmp.py
@@ -14,13 +14,11 @@ class FileCompareTestCase(unittest.TestCase):
self.name_diff = support.TESTFN + '-diff'
data = 'Contents of file go here.\n'
for name in [self.name, self.name_same, self.name_diff]:
- output = open(name, 'w')
- output.write(data)
- output.close()
+ with open(name, 'w') as output:
+ output.write(data)
- output = open(self.name_diff, 'a+')
- output.write('An extra line.\n')
- output.close()
+ with open(self.name_diff, 'a+') as output:
+ output.write('An extra line.\n')
self.dir = tempfile.gettempdir()
def tearDown(self):
@@ -71,13 +69,11 @@ class DirCompareTestCase(unittest.TestCase):
fn = 'FiLe' # Verify case-insensitive comparison
else:
fn = 'file'
- output = open(os.path.join(dir, fn), 'w')
- output.write(data)
- output.close()
+ with open(os.path.join(dir, fn), 'w') as output:
+ output.write(data)
- output = open(os.path.join(self.dir_diff, 'file2'), 'w')
- output.write('An extra file.\n')
- output.close()
+ with open(os.path.join(self.dir_diff, 'file2'), 'w') as output:
+ output.write('An extra file.\n')
def tearDown(self):
for dir in (self.dir, self.dir_same, self.dir_diff):
@@ -104,9 +100,8 @@ class DirCompareTestCase(unittest.TestCase):
"Comparing directory to same fails")
# Add different file2
- output = open(os.path.join(self.dir, 'file2'), 'w')
- output.write('Different contents.\n')
- output.close()
+ with open(os.path.join(self.dir, 'file2'), 'w') as output:
+ output.write('Different contents.\n')
self.assertFalse(filecmp.cmpfiles(self.dir, self.dir_same,
['file', 'file2']) ==
@@ -178,9 +173,8 @@ class DirCompareTestCase(unittest.TestCase):
self._assert_report(d.report, expected_report)
# Add different file2
- output = open(os.path.join(self.dir_diff, 'file2'), 'w')
- output.write('Different contents.\n')
- output.close()
+ with open(os.path.join(self.dir_diff, 'file2'), 'w') as output:
+ output.write('Different contents.\n')
d = filecmp.dircmp(self.dir, self.dir_diff)
self.assertEqual(d.same_files, ['file'])
self.assertEqual(d.diff_files, ['file2'])