[csw-maintainers] [checkpkg] Check unit test interface

Maciej (Matchek) Bliziński maciej at opencsw.org
Thu Oct 13 11:20:50 CEST 2011


If you don't care about checks in checkpkg, you can stop reading now.

I recently attended PyCon Ireland 2011, and one of the talks inspired
me to improve the check unit test interface in checkpkg.  It's the
"with" statement, which allows to easily surround a block of code with
e.g. setup and teardown code.  It's commonly used for opening files,
but I found a way to use it in unit testing.

In checkpkg unit tests, if you want to check for 2 conditions, you
need to write two test functions.  Currently, to write one test
function, you need to create one unit test class.  You can define more
than one function if you want to, but then you have to explicitly
register each new test function.

An example of an old check unit test: http://pastie.org/2687765

In the new helper class, you use the "with" statement, which takes
care of setup, run, and teardown of each test.

An example of a new check unit test: http://pastie.org/2687767

The main advantage I see is that it's easier to group test functions
in classes without worrying about registering them - the abstraction
is cleaner that way.

If you want to comment on any specific line in the code:
http://codereview.appspot.com/5275041/ (click "view side-by-side diffs")

Any thoughts?

Maciej


More information about the maintainers mailing list