Skip to content

Commit 66046ab

Browse files
committed
Fix unit tests and lint errors
1 parent 7e1cd13 commit 66046ab

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

cmd2_myplugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pkg_resources import get_distribution, DistributionNotFound
99

10-
from .myplugin import empty_decorator, MyPlugin
10+
from .myplugin import empty_decorator, MyPluginMixin
1111

1212
try:
1313
__version__ = get_distribution(__name__).version

cmd2_myplugin/myplugin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#
22
# coding=utf-8
3-
4-
import sys
3+
"""An example cmd2 plugin"""
54

65
import functools
76
from typing import Callable
@@ -18,7 +17,7 @@ def _empty_decorator(self, *args, **kwargs):
1817
return _empty_decorator
1918

2019

21-
class MyPlugin:
20+
class MyPluginMixin:
2221
"""A mixin class which adds a 'say' command to a cmd2 subclass
2322
2423
The order in which you add the mixin matters. Say you want to
@@ -52,7 +51,10 @@ def cmd2_myplugin_postloop_hook(self) -> None:
5251
"""Method to be called after the command loop finishes"""
5352
self.poutput("postloop hook")
5453

55-
def cmd2_myplugin_postparsing_hook(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
54+
def cmd2_myplugin_postparsing_hook(
55+
self,
56+
data: cmd2.plugin.PostparsingData
57+
) -> cmd2.plugin.PostparsingData:
5658
"""Method to be called after parsing user input, but before running the command"""
57-
self.poutput('in postparsing_hook')
59+
self.poutput('in postparsing hook')
5860
return data

tests/test_myplugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
######
1414

15-
class MyApp(cmd2.Cmd, cmd2_myplugin.SayMixin):
15+
class MyApp(cmd2_myplugin.MyPlugin, cmd2.Cmd):
1616
"""Simple subclass of cmd2.Cmd with our SayMixin plugin included."""
1717
def __init__(self, *args, **kwargs):
1818
super().__init__(*args, **kwargs)
@@ -46,11 +46,11 @@ def test_say(capsys):
4646
# call our initialization function instead of using a fixture
4747
app = init_app()
4848
# run our mixed in command
49-
app.onecmd_plus_hooks('say')
49+
app.onecmd_plus_hooks('say hello')
5050
# use the capsys fixture to retrieve the output on stdout and stderr
5151
out, err = capsys.readouterr()
5252
# make our assertions
53-
assert out == 'just ran the say command from a plugin\n'
53+
assert out == 'in postparsing hook\nhello\n'
5454
assert not err
5555

5656
def test_decorator(capsys):
@@ -61,5 +61,5 @@ def test_decorator(capsys):
6161
# use the capsys fixture to retrieve the output on stdout and stderr
6262
out, err = capsys.readouterr()
6363
# make our assertions
64-
assert out == 'in the empty decorator\nrunning the empty command\n'
64+
assert out == 'in postparsing hook\nin the empty decorator\nrunning the empty command\n'
6565
assert not err

0 commit comments

Comments
 (0)