summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-10-31 00:03:45 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-10-31 00:03:45 (GMT)
commit076623bf0a2f50417059b736d8d378efa2059c95 (patch)
tree3a4584ad01a71b98729666d80d4c484a8188f767 /Lib/test/test_float.py
parent3ddcaafbbfc02a5210d7f8143c6d7487aa97ad03 (diff)
downloadcpython-076623bf0a2f50417059b736d8d378efa2059c95.zip
cpython-076623bf0a2f50417059b736d8d378efa2059c95.tar.gz
cpython-076623bf0a2f50417059b736d8d378efa2059c95.tar.bz2
Fix ResourceWarning. Use context manager to properly close file.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index ac5fc33..61e71fc 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -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')