[TIP] Announcing Expecter Gadget
Gary Bernhardt
gary.bernhardt at gmail.com
Sun Mar 7 13:29:09 PST 2010
On Sun, Mar 7, 2010 at 12:44 PM, Ryan Freckleton
<ryan.freckleton at gmail.com> wrote:
> Very cool! You're right, this is a much simpler approach than AST.
> Assuming we can get all the edge cases covered (which appears to be
> the current case), I think it's a better solution.
>
> I'll try to gnaw on the best way to do containment assertions.
Sadly, there's no way we can use the "in" operator for containment expectations:
expect(actual) in ['option1', 'option2']
won't work because __contains__ is called on the list. This is my best
shot so far:
expect(my_list).contains(my_obj)
expect(my_obj).is_in(my_list)
Both are needed regardless of the syntax, because they're different
assertions: one talks about what the list should be; one talks about
where the item should be. These definitely don't thrill me, although
they'll each be only two lines long. They would also match the
isinstance assertion I added:
expect(my_obj).isinstance(MyClass)
(Although I hesitated to add that because isinstance checks are evil,
evil, evil! ;)
--
Gary
http://blog.extracheese.org
More information about the testing-in-python
mailing list