Refactor test builder logic

Lots of Python code was copied and pasted into each `SConscript` script under the `tests` directory. This collection of changes factors all that common code out. The result is that individual `SConscript` scripts become dramatically smaller. They also become less flexible, though, as my refactoring is highly customized to the specific way I observed things being done right now. If we need more flexibility in the future, we can certainly make any necessary changes to allow that.