File: example.py

package info (click to toggle)
cmd2 2.5.11%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,244 kB
  • sloc: python: 19,643; makefile: 73; sh: 67; javascript: 30
file content (40 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (3)
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
39
40
#
# coding=utf-8
# import cmd2
import cmd2_ext_test

import cmd2
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()