Improved test architecture.

* Capture stdout
* Global function for calling command line scripts
* pep8