mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Fix ResourceWarning. Use context manager to properly close file.
This commit is contained in:
parent
3ddcaafbbf
commit
076623bf0a
1 changed files with 11 additions and 10 deletions
|
|
@ -540,17 +540,18 @@ def test_format(self):
|
|||
|
||||
@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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue