Attempt to move some common functionality in a function.
Made test.py into a proper unittest