logo

... test.


We've got a base project going for us, which is nice. But let's add some proper unit tests as well as some code formatters! Note; you can find the live repository for this project here.


Notes

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!


Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.