]> granicus.if.org Git - python/commitdiff
Fix ResourceWarning. Use context manager to properly close file.
authorBrian Curtin <brian.curtin@gmail.com>
Sun, 31 Oct 2010 00:03:45 +0000 (00:03 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Sun, 31 Oct 2010 00:03:45 +0000 (00:03 +0000)
Lib/test/test_float.py

index ac5fc336a6229ab19f977fba2c94d1d5be6c7db1..61e71fcd14a1cdcc8fadda56a09b95375e82e70d 100644 (file)
@@ -540,17 +540,18 @@ class FormatTestCase(unittest.TestCase):
 
     @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
-
-            lhs, rhs = map(str.strip, line.split('->'))
-            fmt, arg = lhs.split()
-            self.assertEqual(fmt % float(arg), rhs)
-            self.assertEqual(fmt % -float(arg), '-' + rhs)
+        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)
 
     def test_issue5864(self):
         self.assertEquals(format(123.456, '.4'), '123.5')