Skip to content

Commit 55ce0e7

Browse files
committed
add test for interpreter
1 parent 8aca9a5 commit 55ce0e7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

bpython/test/test_interpreter.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import unittest
2+
3+
from bpython.curtsiesfrontend import interpreter
4+
from curtsies.fmtfuncs import *
5+
6+
class TestInterpreter(unittest.TestCase):
7+
def test_syntaxerror(self):
8+
i = interpreter.Interp()
9+
a = []
10+
11+
def append_to_a(message):
12+
a.append(message)
13+
14+
i.write = append_to_a
15+
i.runsource('1.1.1.1')
16+
17+
expected = ''+u''+u' File '+green(u'"<input>"')+u', line '+bold(magenta(u'1'))+u'\n'+u' '+u'1.1'+u'.'+u'1.1'+u'\n'+u' '+u' '+u'^'+u'\n'+bold(red(u'SyntaxError'))+u': '+cyan(u'invalid syntax')+u'\n'
18+
19+
self.assertEquals(str(plain('').join(a)), str(expected))
20+
self.assertEquals(plain('').join(a), expected)
21+
22+
def test_traceback(self):
23+
i = interpreter.Interp()
24+
a = []
25+
26+
def append_to_a(message):
27+
a.append(message)
28+
29+
i.write = append_to_a
30+
31+
def f():
32+
return 1/0
33+
34+
def g():
35+
return f()
36+
37+
i.runsource('g()')
38+
39+
expected = u'Traceback (most recent call last):\n'+''+u' File '+green(u'"<input>"')+u', line '+bold (magenta(u'1'))+u', in '+cyan(u'<module>')+u'\n'+''+bold(red(u'NameError'))+u': '+cyan(u"name 'g' is not defined")+u'\n'
40+
41+
self.assertEquals(str(plain('').join(a)), str(expected))
42+
self.assertEquals(plain('').join(a), expected)

0 commit comments

Comments
 (0)