Refactor test into python script