|
1 | 1 | importsys |
2 | | -importre |
3 | 2 | importunittest |
4 | 3 |
|
5 | 4 | fromcurtsies.fmtfuncsimportbold,green,magenta,cyan,red,plain |
6 | | -fromunittestimportmock |
7 | 5 |
|
8 | 6 | frombpython.curtsiesfrontendimportinterpreter |
9 | 7 |
|
10 | 8 | pypy="PyPy"insys.version |
11 | 9 |
|
12 | 10 |
|
13 | | -defremove_ansi(s): |
14 | | -returnre.sub(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]".encode("ascii"),b"",s) |
| 11 | +classInterpreter(interpreter.Interp): |
| 12 | +def__init__(self): |
| 13 | +super().__init__() |
| 14 | +self.a= [] |
15 | 15 |
|
| 16 | +defwrite(self,data): |
| 17 | +self.a.append(data) |
16 | 18 |
|
17 | | -classTestInterpreter(unittest.TestCase): |
18 | | -definterp_errlog(self): |
19 | | -i=interpreter.Interp() |
20 | | -a= [] |
21 | | -i.write=a.append |
22 | | -returni,a |
23 | | - |
24 | | -deferr_lineno(self,a): |
25 | | -strings= [x.__unicode__()forxina] |
26 | | -forlineinreversed(strings): |
27 | | -clean_line=remove_ansi(line) |
28 | | -m=re.search(r"line (\d+)[,]",clean_line) |
29 | | -ifm: |
30 | | -returnint(m.group(1)) |
31 | | -returnNone |
32 | 19 |
|
| 20 | +classTestInterpreter(unittest.TestCase): |
33 | 21 | deftest_syntaxerror(self): |
34 | | -i,a=self.interp_errlog() |
| 22 | +i=Interpreter() |
35 | 23 |
|
36 | 24 | i.runsource("1.1.1.1") |
37 | 25 |
|
@@ -96,11 +84,12 @@ def test_syntaxerror(self): |
96 | 84 | +"\n" |
97 | 85 | ) |
98 | 86 |
|
| 87 | +a=i.a |
99 | 88 | self.assertMultiLineEqual(str(plain("").join(a)),str(expected)) |
100 | 89 | self.assertEqual(plain("").join(a),expected) |
101 | 90 |
|
102 | 91 | deftest_traceback(self): |
103 | | -i,a=self.interp_errlog() |
| 92 | +i=Interpreter() |
104 | 93 |
|
105 | 94 | deff(): |
106 | 95 | return1/0 |
@@ -142,6 +131,7 @@ def gfunc(): |
142 | 131 | +"\n" |
143 | 132 | ) |
144 | 133 |
|
| 134 | +a=i.a |
145 | 135 | self.assertMultiLineEqual(str(plain("").join(a)),str(expected)) |
146 | 136 | self.assertEqual(plain("").join(a),expected) |
147 | 137 |
|
|