blob: 649f86271b6b59637e17f85b07b8ae067179411e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#
# coding=utf-8
# import cmd2
import cmd2
import cmd2_ext_test
import cmd2.py_bridge
class Example(cmd2.Cmd):
"""An class to show how to use a plugin"""
def __init__(self, *args, **kwargs):
# gotta have this or neither the plugin or cmd2 will initialize
super().__init__(*args, **kwargs)
def do_something(self, arg):
self.last_result = 5
self.poutput('this is the something command')
class ExampleTester(cmd2_ext_test.ExternalTestMixin, Example):
def __init__(self, *args, **kwargs):
# gotta have this or neither the plugin or cmd2 will initialize
super().__init__(*args, **kwargs)
if __name__ == '__main__':
app = ExampleTester()
try:
app.fixture_setup()
out = app.app_cmd("something")
assert isinstance(out, cmd2.CommandResult)
assert out.data == 5
finally:
app.fixture_teardown()
|