Skip to content

Commit aea557a

Browse files
fix bpython#366 and fix bpython#367
adds tests for and fixes external communication, and turns off welcome banner if help key is disabled
1 parent b23e480 commit aea557a

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ def __init__(self,
238238
if interp is None:
239239
interp = code.InteractiveInterpreter(locals=locals_)
240240
if banner is None:
241-
banner = _('Welcome to bpython! Press <%s> for help.') % config.help_key
241+
if config.help_key:
242+
banner = _('Welcome to bpython!') + ' ' + (_('Press <%s> for help.') % config.help_key)
243+
else:
244+
banner = None
242245
config.autocomplete_mode = autocomplete.SIMPLE # only one implemented currently
243246
if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1:
244247
config.cli_suggestion_width = 1
@@ -1261,7 +1264,7 @@ def show_source(self):
12611264
self.pager(source)
12621265

12631266
def help_text(self):
1264-
return self.version_help_text() + '\n' + self.key_help_text()
1267+
return (self.version_help_text() + '\n' + self.key_help_text()).encode('utf8')
12651268

12661269
def version_help_text(self):
12671270
return (('bpython-curtsies version %s' % bpython.__version__) + ' ' +

bpython/test/test_curtsies_painting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_startup(self):
3838

3939
def test_enter_text(self):
4040
[self.repl.add_normal_character(c) for c in '1 + 1']
41-
screen = fsarray([cyan('>>> ') + bold(blue('1')+cyan(' ')+
42-
yellow('+') + cyan(' ') + green('1')), cyan('welcome')])
41+
screen = fsarray([cyan('>>> ') + bold(green('1')+cyan(' ')+
42+
yellow('+') + cyan(' ') + green('1')), cyan('Welcome to')])
4343
self.assert_paint(screen, (0, 9))
4444

4545
def test_run_line(self):

bpython/test/test_curtsies_repl.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import unittest
22
import sys
3+
import os
34
py3 = (sys.version_info[0] == 3)
45

56
from bpython.curtsiesfrontend import repl
7+
from bpython import config
8+
9+
def setup_config(conf):
10+
config_struct = config.Struct()
11+
config.loadini(config_struct, os.devnull)
12+
for key, value in conf.items():
13+
if not hasattr(config_struct, key):
14+
raise ValueError("%r is not a valid config attribute", (key,))
15+
setattr(config_struct, key, value)
16+
return config_struct
617

718
class TestCurtsiesRepl(unittest.TestCase):
819

920
def setUp(self):
10-
self.repl = repl.Repl()
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
1126

1227
def test_buffer_finished_will_parse(self):
1328
self.repl.buffer = ['1 + 1']
@@ -23,5 +38,11 @@ def test_buffer_finished_will_parse(self):
2338
self.repl.buffer = ['def foo(x):', ' return 1', '']
2439
self.assertTrue(self.repl.buffer_finished_will_parse(), (True, True))
2540

41+
def test_external_communication(self):
42+
self.assertEqual(type(self.repl.help_text()), type(b''))
43+
self.repl.send_current_block_to_external_editor()
44+
self.repl.send_session_to_external_editor()
45+
46+
2647
if __name__ == '__main__':
2748
unittest.main()

0 commit comments

Comments
 (0)