[TIP] Announcing Expecter Gadget

Ryan Freckleton ryan.freckleton at gmail.com
Sun Mar 7 12:44:40 PST 2010

--Ryan E. Freckleton

On Sat, Mar 6, 2010 at 8:15 PM, Gary Bernhardt <gary.bernhardt at gmail.com> wrote:
> I've recently released Expecter Gadget, an expectation (assertion)
> library. It provides a nicer syntax than bare asserts or
> assertEquals-style functions (IMO). It provides this syntax:
>    expect(my_number) == 5
> It supports all of the comparison operators and has
> context-manager-based exception expectations, like those in recent
> versions of nose. You can find examples in the README on PyPI [1].
> There isn't yet support for expectations like "this should contain
> that", or "this should be contained by that" (which are not the same
> type of assertion, by the way!), but adding expectations is very easy.
> The recent discussion about AST transformations for pretty assertion
> failure messages reminded me to post this. That technique seems pretty
> complicated. Expecter Gadget is currently only 62 executable lines of
> code, took only an hour to write, gives pretty error messages for
> free, and also eliminates the ambiguity between expected and actual
> values. (You're stating an expectation about some value you got, so
> the expect() always goes around that.)
> The code is on BitBucket [2]. What do you guys think?
> [1] http://pypi.python.org/pypi/expecter
> [2] bitbucket.org/garybernhardt/expecter-gadget
> --
> Gary
> http://blog.extracheese.org
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

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.

Ryan E. Freckleton

More information about the testing-in-python mailing list