refactoring python parser

Add some tests and refactoring