[Yum-devel] urlgrabber unit tests [was: urlgrabber/test base_test_code.py, 1.3, 1.4 runtests.py, 1.3, 1.4 test_byterange.py, 1.3, 1.4 test_grabber.py, 1.10, 1.11 test_keepalive.py, 1.2, 1.3 test_mirror.py, 1.4, 1.5]

Michael Stenner mstenner at linux.duke.edu
Thu Mar 18 05:02:55 UTC 2004


On Wed, Mar 17, 2004 at 11:03:38PM -0500, seth vidal wrote:
> so:
> 1. the tests are very pretty, yay michael.

You'd have to see the "standard" unit tests to fully appreciate the
improvement :)

> 2. I'm a rube, I want to learn how to do unittests properly should I
> just read this code to find out how?

Don't look at base_test_code.py.  That's the magic that I do to "fix"
unittest.py.  Look in any of the test_*.py files.  Probably the
clearest (because the actual tests are the simplest and least
distracting) are in test_keepalive.py.  Take a look at HTTPErrorTests
and CorruptionTests.

Here's the basic summary (I didn't find the docs very clear):

 * there are two major types of conceptual objects (which do not
   correspond as well as one might like to python objects):
   - test cases
   - test suites

   Test suites are simply containers that hold other test suites
   and/or test cases.

 * each test cases is EXACTLY one test, possibly with some setup and
   teardown code before and after.

 * a class derived from TestCase was originally intended to contain a
   single test, but it often contains more (each "test_" method is one
   test) as in the classes I refer to.

 * each of these TestCase classes gets magically transformed into a
   test suite by the command makeSuite (in the unittest package, or I
   have UGmakeSuite in base_test_code).

   Now, after this conversion, each of these classes (CorruptionTests,
   for example) has been turned into a test suite.

 * You can then make higher level test suites which contain these
   sub-suites.  For example, each of the test_*.py files builds a suite
   containing all of the suites-from-classes.

 * finally, in runtests.py, a top-level suite is made from each of
   these suites-from-files.  This master suite is then run.

I hope this is helpful.

					-Michael
-- 
  Michael D. Stenner                            mstenner at ece.arizona.edu
  ECE Department, the University of Arizona                 520-626-1619
  1230 E. Speedway Blvd., Tucson, AZ 85721-0104                 ECE 524G



More information about the Yum-devel mailing list