Skip to content
icco edited this page Nov 4, 2010 · 3 revisions

Turtle

Included in testify is a very simple mock/stubbing library called turtle.

Rather than being based on the standard mocking and stubbing frameworks out there, turtle assumes that most objects don't need to behave like anything. Every attribute exists, and every function call succeeds and returns another turtle object. In fact, it is "Turtles all the way down."

So for example:

In [1]: from testify.utils import turtle

In [2]: my_thing = turtle.Turtle()

In [3]: my_thing.do_stuff_for_me()
Out[3]: <testify.utils.turtle.Turtle object at 0x149eef0>

In [4]: my_thing.is_a_bool = True

In [5]: my_thing.is_a_bool
Out[5]: True

For convenience, you can also set attributes during initialization:

In [7]: other_thing = turtle.Turtle(is_a_foo=True, do_something=lambda : None)

In [8]: other_thing.is_a_foo
Out[8]: True

In [9]: other_thing.do_something()

Your turtle can be extended anyway you like, but if you start needing to do things that are too complicated, you might want to rethink your interfaces.

Clone this wiki locally