convert raw test code to functions

for correct use of nose
fix typo
raise Exception when ply fails but only warns
import PLY and PyParsing only when needed

thus avoiding to require that both be installed