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
42 lines (28 loc) · 1.31 KB
/
test_interpreter.py
File metadata and controls
42 lines (28 loc) · 1.31 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
import unittest
from bpython.curtsiesfrontend import interpreter
from curtsies.fmtfuncs import *
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 = ''+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'
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 = 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'
self.assertEquals(str(plain('').join(a)), str(expected))
self.assertEquals(plain('').join(a), expected)