class TestLexer(TestCase): def setUp(self): self.lexer = MyLexer() def _test(self, data, ref): self.lexer.input(data) self._test_impl(data, ref) def _test_impl(self, data, ref): res = [] while True: tok = self.lexer.token() if not tok: break res.append(tok.type) if isstring(ref): ref = split(ref) try: assert_equal(res, ref) except AssertionError, e: cnt = 0 for i, j in zip(res, ref): if not i == j: break cnt += 1 print "Break at index", cnt raise e
class TestLexer(TestCase): def setUp(self): self.lexer = MyLexer() def _test(self, data, ref): self.lexer.input(data) self._test_impl(data, ref) def _test_impl(self, data, ref): res = [] while True: tok = self.lexer.token() if not tok: break res.append(tok.type) if is_string(ref): ref = split(ref) try: assert_equal(res, ref) except AssertionError: e = extract_exception() cnt = 0 for i, j in zip(res, ref): if not i == j: break cnt += 1 print("Break at index %d" % cnt) raise e def _get_tokens(self, data): self.lexer.input(data) return [t for t in self.lexer.token_stream]
def setUp(self): self.lexer = MyLexer()