def test_bad_input(bad_input, diag): code, desc = bad_input token_stream = tokenize(code) parser = Parser(token_stream, diag) parse_method = getattr(parser, desc['hook']) with pytest.raises(DumbSyntaxError): parse_method()
def test_eof_handling(diag): code = '' token_stream = tokenize(code) parser = Parser(token_stream, diag) # Current token is EOF, so the next advance() method call # should cause an error. with pytest.raises(DumbEOFError): parser.advance()
def test_output_ast(good_input, diag): code, desc = good_input token_stream = tokenize(code) parser = Parser(token_stream, diag) parse_method = getattr(parser, desc['hook']) ast = parse_method() if 'root' in desc: tree_desc = desc['root'] verify_tree(ast, tree_desc) else: forest_desc = desc['forest'] verify_forest(ast, forest_desc)
def get_loc_list(code): tokens = tokenize(code) t1, t2 = itertools.tee(tokens, 2) loc = extract_field(t1, 'loc') return list(loc)
def get_kind_list(code): tokens = tokenize(code) return list(extract_field(tokens, 'kind'))