Skip to content

Commit 1666a7d

Browse files
authored
Merge pull request #3 from python-cmd2/fix_bugs
Fixed bug do to change in how help works in cmd2
2 parents 05220be + 9139ec7 commit 1666a7d

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

cmd2_submenu/submenu.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def complete_submenu(_self, text, line, begidx, endidx):
183183
_self.display_matches = copy.copy(submenu.display_matches)
184184

185185
original_do_help = cmd_obj.do_help
186-
original_complete_help = cmd_obj.complete_help
186+
original_complete_help_command = cmd_obj.complete_help_command
187187

188188
def help_submenu(_self, line):
189189
"""
@@ -209,7 +209,7 @@ def _complete_submenu_help(_self, text, line, begidx, endidx):
209209
endidx - line.index(tokens[1]),
210210
)
211211
else:
212-
return original_complete_help(_self, text, line, begidx, endidx)
212+
return original_complete_help_command(_self, text, line, begidx, endidx)
213213

214214
if self.create_subclass:
215215
class _Cmd(cmd_obj):

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
packages=['cmd2_submenu'],
2626

2727
python_requires='>=3.4',
28-
install_requires=['cmd2 >= 0.9.4, <=2'],
28+
install_requires=['cmd2 >= 0.9.6, <=2'],
2929
setup_requires=['setuptools_scm'],
3030

3131
classifiers=[

tests/conftest.py

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
#
22
# coding=utf-8
3-
4-
class StdOut(object):
5-
""" Toy class for replacing self.stdout in cmd2.Cmd instances for unit testing. """
6-
def __init__(self):
7-
self.buffer = ''
8-
9-
def write(self, s):
10-
self.buffer += s
11-
12-
def read(self):
13-
raise NotImplementedError
14-
15-
def clear(self):
16-
self.buffer = ''
17-
183
def normalize(block):
194
""" Normalize a block of text to perform comparison.
205
@@ -27,9 +12,9 @@ def normalize(block):
2712

2813

2914
def run_cmd(app, cmd):
30-
""" Clear StdOut buffer, run the command, extract the buffer contents, """
15+
""" Clear StdSim buffer, run the command, extract the buffer contents, """
3116
app.stdout.clear()
3217
app.onecmd_plus_hooks(cmd)
33-
out = app.stdout.buffer
18+
out = app.stdout.getvalue()
3419
app.stdout.clear()
3520
return normalize(out)

tests/test_submenu.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from cmd2 import cmd2
1212
import cmd2_submenu
13-
from conftest import run_cmd, StdOut, normalize
14-
13+
from conftest import run_cmd, normalize
14+
from cmd2.utils import StdSim
1515

1616
class SecondLevelB(cmd2.Cmd):
1717
"""To be used as a second level command class. """
@@ -88,32 +88,32 @@ def complete_say(self, text, line, begidx, endidx):
8888
@pytest.fixture
8989
def submenu_app():
9090
app = SubmenuApp()
91-
app.stdout = StdOut()
92-
second_level_cmd.stdout = StdOut()
93-
second_level_b_cmd.stdout = StdOut()
91+
app.stdout = StdSim(app.stdout)
92+
second_level_cmd.stdout = StdSim(app.stdout)
93+
second_level_b_cmd.stdout = StdSim(app.stdout)
9494
return app
9595

9696

9797
@pytest.fixture
9898
def secondlevel_app():
9999
app = SecondLevel()
100-
app.stdout = StdOut()
100+
app.stdout = StdSim(app.stdout)
101101
return app
102102

103103

104104
@pytest.fixture
105105
def secondlevel_app_b():
106106
app = SecondLevelB()
107-
app.stdout = StdOut()
107+
app.stdout = StdSim(app.stdout)
108108
return app
109109

110110
def run_submenu_cmd(app, second_level_app, cmd):
111-
""" Clear StdOut buffers, run the command, extract the buffer contents."""
111+
""" Clear StdSim buffers, run the command, extract the buffer contents."""
112112
app.stdout.clear()
113113
second_level_app.stdout.clear()
114114
app.onecmd_plus_hooks(cmd)
115-
out1 = app.stdout.buffer
116-
out2 = second_level_app.stdout.buffer
115+
out1 = app.stdout.getvalue()
116+
out2 = second_level_app.stdout.getvalue()
117117
app.stdout.clear()
118118
second_level_app.stdout.clear()
119119
return normalize(out1), normalize(out2)

0 commit comments

Comments
 (0)