Skip to content

Fix #194 #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add test for interpreter
  • Loading branch information
mlauter committed Sep 4, 2014
commit 55ce0e753ae5d5ad73f7319e7fd7cb933e1649c4
42 changes: 42 additions & 0 deletions bpython/test/test_interpreter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)