diff Lib/test/test_float.py @ 65785:736f3a10d173

Fix ResourceWarning. Use context manager to properly close file.
author Brian Curtin <brian.curtin@gmail.com>
date Sun, 31 Oct 2010 00:03:45 +0000
parents eafe07d40eb7
children 9fe76c26ea9f
line wrap: on
line diff
--- a/Lib/test/test_float.py	Sat Oct 30 23:56:45 2010 +0000
+++ b/Lib/test/test_float.py	Sun Oct 31 00:03:45 2010 +0000
@@ -540,17 +540,18 @@
 
     @requires_IEEE_754
     def test_format_testfile(self):
-        for line in open(format_testfile):
-            if line.startswith('--'):
-                continue
-            line = line.strip()
-            if not line:
-                continue
+        with open(format_testfile) as testfile:
+            for line in testfile:
+                if line.startswith('--'):
+                    continue
+                line = line.strip()
+                if not line:
+                    continue
 
-            lhs, rhs = map(str.strip, line.split('->'))
-            fmt, arg = lhs.split()
-            self.assertEqual(fmt % float(arg), rhs)
-            self.assertEqual(fmt % -float(arg), '-' + rhs)
+                lhs, rhs = map(str.strip, line.split('->'))
+                fmt, arg = lhs.split()
+                self.assertEqual(fmt % float(arg), rhs)
+                self.assertEqual(fmt % -float(arg), '-' + rhs)
 
     def test_issue5864(self):
         self.assertEquals(format(123.456, '.4'), '123.5')