Monday, June 9, 2014

Unit testing

Spent a pleasant 4 hours writing a detailed unit test driver for utilities.py, the module into which I have chucked everything to do with QFile and QFileDialog and friends. The testing turned up several bugs, which is what it's all about.

This was the module for which I developed my variation on defaultdict, of which I was quite proud. Proud enough that I also posted it in reddit/r/python. And today in exercising the functions that use that clever class, I discovered that it wasn't working! Well, it did work in the sense that it always returned correct answers, but it didn't in the sense that it wasn't doing any caching of results. It always calculated the result anew for every key, quite the opposite of a cache.

This was due to my misunderstanding what the Python docs were saying about defaultdict. In my defense I'll say that the Python writeup is not all that clear. But still, just stepping through the code a couple of times to verify it did what I thought, would have revealed instantly that it didn't. Anyway, I went and updated both this blog and the reddit posting.

That was one bug. Several others were simple typos and mis-codings in code that hadn't be executed yet, typically the code that logged errors. Then I found what looks a lot like a bug in PyQt 5.3. I've posted it to the mailing list and we'll see. The test case I posted is so simple it's hard to imagine how it could be an error by me.

No comments: