Skip to content

Commit ec8a32e

Browse files
add failing test for #369
1 parent 79d55fa commit ec8a32e

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

bpython/curtsies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def main(args=None, locals_=None, banner=None):
4545
interp = None
4646
paste = None
4747
if exec_args:
48-
assert options, "don't pass in exec_args without options"
48+
if not options:
49+
raise ValueError("don't pass in exec_args without options")
4950
exit_value = 0
5051
if options.type:
5152
paste = curtsies.events.PasteEvent()

bpython/test/test_args.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import sys
3+
import unittest
4+
from mock import Mock, MagicMock
5+
try:
6+
from unittest import skip
7+
except ImportError:
8+
def skip(f):
9+
return lambda self: None
10+
11+
from bpython import config, repl, cli, autocomplete
12+
13+
class TestFutureImports(unittest.TestCase):
14+
15+
def test_interactive(self):
16+
pass
17+

bpython/test/test_curtsies_painting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def setup_config():
1818

1919
class TestCurtsiesPainting(FormatStringTest):
2020
def setUp(self):
21-
self.refresh_requests = []
2221
self.repl = Repl(config=setup_config())
2322
self.repl.rl_history = History() # clear history
2423
self.repl.height, self.repl.width = (5, 10)

bpython/test/test_curtsies_repl.py

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
import unittest
2-
import sys
1+
import code
32
import os
3+
import sys
4+
import tempfile
5+
from contextlib import contextmanager
6+
from StringIO import StringIO
7+
8+
import unittest
9+
try:
10+
from unittest import skip
11+
except ImportError:
12+
def skip(f):
13+
return lambda self: None
14+
415
py3 = (sys.version_info[0] == 3)
516

6-
from bpython.curtsiesfrontend import repl
17+
from bpython.curtsiesfrontend import repl as curtsiesrepl
718
from bpython import config
19+
from bpython import args
820

921
def setup_config(conf):
1022
config_struct = config.Struct()
@@ -18,11 +30,7 @@ def setup_config(conf):
1830
class TestCurtsiesRepl(unittest.TestCase):
1931

2032
def setUp(self):
21-
self.config = setup_config({'editor':'true'})
22-
self.repl = repl.Repl(config=self.config)
23-
os.environ['PAGER'] = 'true'
24-
self.repl.width = 50
25-
self.repl.height = 20
33+
self.repl = create_repl()
2634

2735
def test_buffer_finished_will_parse(self):
2836
self.repl.buffer = ['1 + 1']
@@ -43,6 +51,48 @@ def test_external_communication(self):
4351
self.repl.send_current_block_to_external_editor()
4452
self.repl.send_session_to_external_editor()
4553

54+
@contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy
55+
def captured_output():
56+
new_out, new_err = StringIO(), StringIO()
57+
old_out, old_err = sys.stdout, sys.stderr
58+
try:
59+
sys.stdout, sys.stderr = new_out, new_err
60+
yield sys.stdout, sys.stderr
61+
finally:
62+
sys.stdout, sys.stderr = old_out, old_err
63+
64+
def create_repl(**kwargs):
65+
config = setup_config({'editor':'true'})
66+
repl = curtsiesrepl.Repl(config=config, **kwargs)
67+
os.environ['PAGER'] = 'true'
68+
repl.width = 50
69+
repl.height = 20
70+
return repl
71+
72+
class TestFutureImports(unittest.TestCase):
73+
74+
def test_repl(self):
75+
repl = create_repl()
76+
with captured_output() as (out, err):
77+
repl.push('from __future__ import division')
78+
repl.push('1 / 2')
79+
self.assertEqual(out.getvalue(), '0.5\n')
80+
81+
@skip('Failing - this is issue #369')
82+
def test_interactive(self):
83+
interp = code.InteractiveInterpreter(locals={})
84+
with captured_output() as (out, err):
85+
with tempfile.NamedTemporaryFile(suffix='.py') as f:
86+
f.write('from __future__ import division\n')
87+
f.write('print 1/2\n')
88+
f.flush()
89+
args.exec_code(interp, [f.name])
90+
91+
repl = create_repl(interp=interp)
92+
repl.push('1 / 2')
93+
94+
self.assertEqual(out.getvalue(), '0.5\n0.5\n')
95+
4696

4797
if __name__ == '__main__':
4898
unittest.main()

0 commit comments

Comments
 (0)