Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-26175: Fix SpooledTemporaryFile IOBase abstract #3249

Closed
Prev Previous commit
Next Next commit
Refactor tests to more reliably test abstract
  • Loading branch information
GFernie committed Sep 30, 2017
commit fb283621685da73771256d8eb51dabf19fe71378
41 changes: 14 additions & 27 deletions Lib/test/test_tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,34 +982,21 @@ def test_basic(self):
f = self.do_create(max_size=100, pre="a", suf=".txt")
self.assertFalse(f._rolled)

def test_iobase_abstract(self):
# SpooledTemporaryFile should implement the IOBase abstract
iobase_abstract = (
'close',
'closed',
'fileno',
'flush',
'isatty',
'read',
'readable',
'readinto',
'readline',
'readlines',
'seek',
'seekable',
'tell',
'truncate',
'write',
'writable',
'writelines',
'__del__',
def test_is_iobase(self):
# SpooledTemporaryFile should implement io.IOBase
self.assertIsInstance(self.do_create(), io.IOBase)

def test_iobase_interface(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests are not very interesting. It would be better to test the methods operate properly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It literally delegates everything to the underlying file.

The existing tests should cover the behaviors. The new behaviors are intended to flesh out the API so that SpooledTemporaryFile, and these tests seem to cover that.

# SpooledTemporaryFile should implement the io.IOBase interface.
# IOBase does not declare read(), readinto(), or write(), but
# they should be considered part of the interface.
iobase_abstract = {'read', 'readinto', 'write'}
spooledtempfile_abstract = set(dir(tempfile.SpooledTemporaryFile))
missing_attributes = iobase_abstract - spooledtempfile_abstract
self.assertFalse(
missing_attributes,
'io.IOBase attributes missing from SpooledTemporaryFile'
)
f = self.do_create()
for attribute in iobase_abstract:
self.assertTrue(
hasattr(f, attribute),
'{} attribute missing'.format(attribute)
)

def test_del_on_close(self):
# A SpooledTemporaryFile is deleted when closed
Expand Down