mirror of https://github.com/mahmoud/boltons.git
Implment __len__ magic method
This commit is contained in:
parent
5c45f57961
commit
0f9581cd85
|
@ -172,6 +172,9 @@ class SpooledIOBase(object):
|
|||
self.seek(pos)
|
||||
return val
|
||||
|
||||
def __len__(self):
|
||||
return self.len
|
||||
|
||||
def __iter__(self):
|
||||
yield self.readline()
|
||||
|
||||
|
|
|
@ -197,15 +197,17 @@ class TestSpooledBytesIO(TestCase, BaseTestMixin, AssertionsMixin):
|
|||
self.assertEqual(f.getvalue(), test_str)
|
||||
|
||||
def test_len_no_rollover(self):
|
||||
"""Make sure len property works with in-memory flo"""
|
||||
"""Make sure len works with in-memory flo"""
|
||||
self.spooled_flo.write(self.test_str)
|
||||
self.assertEqual(self.spooled_flo.len, len(self.test_str))
|
||||
self.assertEqual(len(self.spooled_flo), len(self.test_str))
|
||||
|
||||
def test_len_rollover(self):
|
||||
"""Make sure len property works with on-disk flo"""
|
||||
"""Make sure len works with on-disk flo"""
|
||||
self.spooled_flo.write(self.test_str)
|
||||
self.spooled_flo.rollover()
|
||||
self.assertEqual(self.spooled_flo.len, len(self.test_str))
|
||||
self.assertEqual(len(self.spooled_flo), len(self.test_str))
|
||||
|
||||
def test_invalid_type(self):
|
||||
"""Ensure TypeError raised when writing unicode to SpooledBytesIO"""
|
||||
|
|
Loading…
Reference in New Issue