mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
#11700: proxy object close methods can now be called multiple times
This makes them work like the close provided by regular file objects.
This commit is contained in:
parent
05ff990401
commit
c88bce1580
3 changed files with 25 additions and 5 deletions
|
@ -297,6 +297,13 @@ class TestMailbox(TestBase):
|
|||
self.assertEqual(data1.decode('ascii').replace(os.linesep, '\n'),
|
||||
_sample_message)
|
||||
|
||||
def test_get_file_can_be_closed_twice(self):
|
||||
# Issue 11700
|
||||
key = self._box.add(_sample_message)
|
||||
f = self._box.get_file(key)
|
||||
f.close()
|
||||
f.close()
|
||||
|
||||
def test_iterkeys(self):
|
||||
# Get keys using iterkeys()
|
||||
self._check_iteration(self._box.keys, do_keys=True, do_values=False)
|
||||
|
@ -1862,8 +1869,12 @@ class TestProxyFileBase(TestBase):
|
|||
|
||||
def _test_close(self, proxy):
|
||||
# Close a file
|
||||
self.assertFalse(proxy.closed)
|
||||
proxy.close()
|
||||
self.assertRaises(AttributeError, lambda: proxy.close())
|
||||
self.assertTrue(proxy.closed)
|
||||
# Issue 11700 subsequent closes should be a no-op.
|
||||
proxy.close()
|
||||
self.assertTrue(proxy.closed)
|
||||
|
||||
|
||||
class TestProxyFile(TestProxyFileBase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue