In reading the lollerskates code, there are a couple of places where exception handling might not be doing what is intended, or in some cases what is needed.
In particular, the offset file, if it exists, should be read-write and the first line should contain a numeric value. The get_last_offset function returns 0, if the file is absent, but improperly returns None (after catching an IOError, and writing a message to stdout). What should it do (if eg, file were not readable)? TBD -- options are: 1. return 0, and proceed as if file were missing 2. propagate the exception, with or without the message 3. skip file processing on that log 4. accumulate errors someplace and report via email, then as 1. BTW, if the file is zero length or contains non-numeric, the current code raises ValueError (which is not caught in get_last_offset), so that might be called a different bug. I actually coded t_lollerskates to verify that behavior. Fixing that will fail test999a_setup; so then the test-code will have to be updated. So, calling that a bug, here's a unittest for a. demonstrating the bug, in existing code b. confirming the fix, when fixed c. permanent regression test to ensure bug stays fixed code to be inserted into my t_lollerskates.py, available at http://www.kernel-panic.org/Members/jgsack/misc/jloller.tgz Note: I forgot to say that the unittest framework gives a bit more output when run with -v, as ./t_lollerskates.py -v === class tcRegression1(u.TestCase): def setUp(s): fil = "./states/bogus.offset" if os.path.isfile(fil): os.unlink(fil) os.close(os.open(fil,os.O_CREAT, 0200)) def testR1a(s): """get_last_offset return code """ rc=ll.get_last_offset("bogus") s.assertEquals(rc,0, "expect offset 0 for non readable file. got %s" % rc) #maybe it should be more like this: # where badFileError is some module-defined exception # s.assertRaises(ll.badFileError, ll.get_last_offset("bogus")) === ..jim -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
