cardiff: Code refactoring

Let's move many functions from cardiff.py to utils.py to get them used
by the testing tool. This make also the main program easier to read.
cardiff: Adding nosetests

Adding nosetests inside cardiff to make it more robust