Serial testing code in Python