VERBAL = args.quiet test_regex = "(def)[\t ]+[a-zA-Z_][a-zA-Z0-9_]+[\t ]*:[\t ]*\n" # Make sure there's not a problem with the above regular expression # in its most basic form before beginning the tests assert re.match(test_regex, "def foo:\n") # Set up the parse map regex_table = ( ("def", "(def)[\t ]+", ParseMap.IGNORE), ("func_name", "[a-zA-Z_][a-zA-Z0-9_]+", ParseMap.LITERAL), ("endl", "[\t ]*:[\t ]*\n", ParseMap.IGNORE), ) parser = ParseMap(regex_table) parser.assert_match(test_regex) passing_tests = {"def foo:\n": "foo", "def f2oo:\n": "f2oo", "def foo3 : \n": "foo3"} failing_tests = ("def 1foo:\n", "def\tfoo:", "def:") for test in passing_tests: result = parser.parse(test) if result["func_name"] != passing_tests[test]: raise Exception for test in failing_tests: try: result = parser.parse(test) raise Exception except ParseMapError: continue