There's an opportunity to add a method to our class that will make our testing code just a bit nicer to work with.
class Clumper():
def __init__(self, blob):
self.blob = blob
def __len__(self):
return len(self.blob)
...
This will allow us to refactor this test:
def test_headtail_size():
data = [{'i': i} for i in range(10)]
c = Clumper(data)
assert len(c.head(10).collect()) == 10
assert len(c.tail(10).collect()) == 10
assert len(c.head(5).collect()) == 5
assert len(c.tail(5).collect()) == 5
Into this test:
def test_headtail_size():
data = [{'i': i} for i in range(10)]
c = Clumper(data)
assert len(c.head(10)) == 10
assert len(c.tail(10)) == 10
assert len(c.head(5)) == 5
assert len(c.tail(5)) == 5
This is a whole lot better. But we're not done yet!