← 返回首页
import sys import re import unittest from curtsies.fmtfuncs import bold, green, magenta, cyan, red, plain from unittest import mock from bpython.curtsiesfrontend import interpreter pypy = "PyPy" in sys.version def remove_ansi(s): return re.sub(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]".encode("ascii"), b"", s) class TestInterpreter(unittest.TestCase): def interp_errlog(self): i = interpreter.Interp() a = [] i.write = a.append return i, a def err_lineno(self, a): strings = [x.__unicode__() for x in a] for line in reversed(strings): clean_line = remove_ansi(line) m = re.search(r"line (\d+)[,]", clean_line) if m: return int(m.group(1)) return None def test_syntaxerror(self): i, a = self.interp_errlog() i.runsource("1.1.1.1") if sys.version_info[:2] >= (3, 10): expected = ( " File " + green('""') + ", line " + bold(magenta("1")) + "\n 1.1.1.1\n ^^^^^\n" + bold(red("SyntaxError")) + ": " + cyan("invalid syntax. Perhaps you forgot a comma?") + "\n" ) elif (3, 8)