Skip to content

Commit

Permalink
add a magic __len__ method and the corresponding test
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Mar 4, 2015
1 parent 07c68c8 commit 923772f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_writebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def test_empty_write_buffer(self):
self.assertEquals(s, b"")
c = x.get_chunk(4096)
self.assertEquals(c, b"")
self.assertEquals(len(x), 0)

def test_write_buffer1(self):
b = self._make_test_buffer()
s = bytes(b)
self.assertEquals(len(b), 9)
self.assertEquals(s, b"123456789")
self.assertFalse(b.is_empty())
self.assertEquals(b._total_length, 9)
Expand Down
3 changes: 3 additions & 0 deletions tornadis/write_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __str__(self):
def __bytes__(self):
return self._tobytes()

def __len__(self):
return self._total_length

def _tobytes(self):
"""Serializes the write buffer into a single string (bytes).
Expand Down

0 comments on commit 923772f

Please sign in to comment.