Add unit tests for existing modules

Status: done

Add unit tests for existing modules that currently lack unit tests. This includes:

Test framework

The testing framework provided by the unittest module in Python's standard library has some shortcomings.

The biggest limitation is that there is no convenient way to parameterize tests. There are two cases for this:

  1. Test multiple implementations of an interface against the same test code (a small, fixed number of cases). For example, test PlashObjectCapabilityProtocol when used with a glib-based event dispatcher and when used with a poll()-based event dispatcher.

  2. Test against a large number of cases, e.g. encoding/decoding X protocol messages in X11ProxySpike.

(1) can be done using inheritance, but that is limited. Inheritance can't generalise in more than one direction without becoming unwieldy. Inheritance is usually best avoided.

(2) can be done using a simple "for" loop, but when it fails, the traceback doesn't show which subtest was being used, and one failure blocks all further failures. (The full set of failures and successes can be useful for diagnosing a problem.) A partial solution is a wrapper function which re-throws all subtests' exceptions with descriptions (see subtests() in scratch/x11-proxy/server_test.py).

Other issues:

Test discovery (i.e. searching for tests in Python modules and directories of modules) is the most well-known failing of unittest.

Other test frameworks:

Parts not done

Tests for these areas:

StoryTest1 (last edited 2008-05-05 16:26:56 by MarkSeaborn)