-
-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathtest_interpreter.py
More file actions
55 lines (38 loc) · 1.81 KB
/
test_interpreter.py
File metadata and controls
55 lines (38 loc) · 1.81 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
import unittest
from bpython.curtsiesfrontend import interpreter
from bpython.curtsiesfrontend.repl import bad_empty_lines_removed
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)
class TestPreprocessing(unittest.TestCase):
def test_bad_empty_lines_removed(self):
self.assertEqual(bad_empty_lines_removed("def foo():\n"
" return 1\n"
"\n"
" pass\n"),
"def foo():\n"
" return 1\n"
" pass\n")