def check_token(code, tokens): """Make sure that all tokens appears in code in order""" lx = XonshLexer() tks = list(lx.get_tokens(code)) for tk in tokens: while tks: if tk == tks[0]: break tks = tks[1:] else: msg = "Token {!r} missing: {!r}".format(tk, list(lx.get_tokens(code))) pytest.fail(msg) break
def factory(code, tokens): """Make sure that all tokens appears in code in order""" lx = XonshLexer() tks = list(lx.get_tokens(code)) for tk in tokens: while tks: if tk == tks[0]: break tks = tks[1:] else: msg = f"Token {tk!r} missing: {list(lx.get_tokens(code))!r}" pytest.fail(msg) break