Add test of system.rebuild_modules.

Further refactoring of the test suite to reduce duplication.  Also
cleaned up patching to patch the local module names and not the global
or non-local.