Enhancements: expect/result syntax sugar and better Mock.__repr__

Bug #278244 reported by Daniel
2
Affects Status Importance Assigned to Milestone
Mocker
Invalid
Undecided
Gustavo Niemeyer

Bug Description

I have written two new methods for the Mock class that make it easier to perform expect(x).result(y). In addition, it adds a convenient way to 'inject' results into a sub-expression while constructing a larger test expression. Example syntax (sugar):

These are equivalent:

sweet: mock.func(arg) << value
sour: expect(mock.func(arg)).result(value)

And these are equivalent:

sweet: (mock.func(arg) >> value).value_func()
sour: expect(mock.func(arg)).result(value); value.value_func()

Implementation attached.

I have also included a __repr__ function for the Mock class that makes it easier to debug test failures. I know it should technically be submitted as a separate bug, but I'm lazy.

Revision history for this message
Daniel (millerdev) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

By design, Mock objects do not have any special syntax attached to themselves, because that would conflict with the implementation of the same methods on real objects.

Changed in mocker:
assignee: nobody → Gustavo Niemeyer (niemeyer)
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.