[Python-checkins] r86003 - python/branches/py3k/Lib/test/test_float.py

brian.curtin python-checkins at python.org
Sun Oct 31 02:03:45 CEST 2010


Author: brian.curtin
Date: Sun Oct 31 02:03:45 2010
New Revision: 86003

Log:
Fix ResourceWarning. Use context manager to properly close file.


Modified:
   python/branches/py3k/Lib/test/test_float.py

Modified: python/branches/py3k/Lib/test/test_float.py
==============================================================================
--- python/branches/py3k/Lib/test/test_float.py	(original)
+++ python/branches/py3k/Lib/test/test_float.py	Sun Oct 31 02:03:45 2010
@@ -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
-
-            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')


More information about the Python-checkins mailing list