forked from bpython/bpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interpreter.py
More file actions
53 lines (37 loc) · 1.46 KB
/
test_interpreter.py
File metadata and controls
53 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import unicode_literals
try:
import unittest2 as unittest
except ImportError:
import unittest
from bpython.curtsiesfrontend import interpreter
from curtsies.fmtfuncs import bold, green, magenta, cyan, red, plain
class TestInterpreter(unittest.TestCase):
def test_syntaxerror(self):
i = interpreter.Interp()
a = []
def append_to_a(message):
a.append(message)
i.write = append_to_a
i.runsource('1.1.1.1')
expected = ' File ' + green('"<input>"') + ', line ' + \
bold(magenta('1')) + '\n 1.1.1.1\n ^\n' + \
bold(red('SyntaxError')) + ': ' + cyan('invalid syntax') + '\n'
self.assertEquals(str(plain('').join(a)), str(expected))
self.assertEquals(plain('').join(a), expected)
def test_traceback(self):
i = interpreter.Interp()
a = []
def append_to_a(message):
a.append(message)
i.write = append_to_a
def f():
return 1/0
def g():
return f()
i.runsource('g()')
expected = 'Traceback (most recent call last):\n File ' + \
green('"<input>"') + ', line ' + bold(magenta('1')) + ', in ' + \
cyan('<module>') + '\n' + bold(red('NameError')) + ': ' + \
cyan("name 'g' is not defined") + '\n'
self.assertEquals(str(plain('').join(a)), str(expected))
self.assertEquals(plain('').join(a), expected)