summaryrefslogtreecommitdiff
path: root/tests_isolated/test_commandset
diff options
context:
space:
mode:
Diffstat (limited to 'tests_isolated/test_commandset')
-rw-r--r--tests_isolated/test_commandset/conftest.py17
-rw-r--r--tests_isolated/test_commandset/test_argparse_subcommands.py6
-rw-r--r--tests_isolated/test_commandset/test_categories.py6
-rw-r--r--tests_isolated/test_commandset/test_commandset.py12
4 files changed, 23 insertions, 18 deletions
diff --git a/tests_isolated/test_commandset/conftest.py b/tests_isolated/test_commandset/conftest.py
index 037be199..d6968575 100644
--- a/tests_isolated/test_commandset/conftest.py
+++ b/tests_isolated/test_commandset/conftest.py
@@ -7,10 +7,10 @@ from contextlib import redirect_stderr, redirect_stdout
from typing import List, Optional, Union
from unittest import mock
+from cmd2_ext_test import ExternalTestMixin
from pytest import fixture
import cmd2
-from cmd2_ext_test import ExternalTestMixin
from cmd2.utils import StdSim
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
@@ -26,9 +26,9 @@ except ImportError:
pass
-def verify_help_text(cmd2_app: cmd2.Cmd,
- help_output: Union[str, List[str]],
- verbose_strings: Optional[List[str]] = None) -> None:
+def verify_help_text(
+ cmd2_app: cmd2.Cmd, help_output: Union[str, List[str]], verbose_strings: Optional[List[str]] = None
+) -> None:
"""This function verifies that all expected commands are present in the help text.
:param cmd2_app: instance of cmd2.Cmd
@@ -157,12 +157,7 @@ def base_app():
# These are odd file names for testing quoting of them
-odd_file_names = [
- 'nothingweird',
- 'has spaces',
- '"is_double_quoted"',
- "'is_single_quoted'"
-]
+odd_file_names = ['nothingweird', 'has spaces', '"is_double_quoted"', "'is_single_quoted'"]
def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Optional[str]:
@@ -181,6 +176,7 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti
Matches are stored in app.completion_matches
These matches also have been sorted by complete()
"""
+
def get_line():
return line
@@ -199,6 +195,7 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti
class WithCommandSets(ExternalTestMixin, cmd2.Cmd):
"""Class for testing custom help_* methods which override docstring help."""
+
def __init__(self, *args, **kwargs):
super(WithCommandSets, self).__init__(*args, **kwargs)
diff --git a/tests_isolated/test_commandset/test_argparse_subcommands.py b/tests_isolated/test_commandset/test_argparse_subcommands.py
index bd2bed42..d71c3670 100644
--- a/tests_isolated/test_commandset/test_argparse_subcommands.py
+++ b/tests_isolated/test_commandset/test_argparse_subcommands.py
@@ -9,7 +9,8 @@ import argparse
import pytest
import cmd2
-from .conftest import run_cmd, WithCommandSets
+
+from .conftest import WithCommandSets, run_cmd
class SubcommandSet(cmd2.CommandSet):
@@ -65,8 +66,7 @@ class SubcommandSet(cmd2.CommandSet):
@pytest.fixture
def subcommand_app():
- app = WithCommandSets(auto_load_commands=False,
- command_sets=[SubcommandSet(1)])
+ app = WithCommandSets(auto_load_commands=False, command_sets=[SubcommandSet(1)])
return app
diff --git a/tests_isolated/test_commandset/test_categories.py b/tests_isolated/test_commandset/test_categories.py
index c266e0d4..ae31d6a1 100644
--- a/tests_isolated/test_commandset/test_categories.py
+++ b/tests_isolated/test_commandset/test_categories.py
@@ -12,6 +12,7 @@ from cmd2 import CommandSet, with_default_category
@with_default_category('Default Category')
class MyBaseCommandSet(CommandSet):
"""Defines a default category for all sub-class CommandSets"""
+
def __init__(self, _: Any):
super(MyBaseCommandSet, self).__init__()
@@ -20,6 +21,7 @@ class ChildInheritsParentCategories(MyBaseCommandSet):
"""
This subclass doesn't declare any categories so all commands here are also categorized under 'Default Category'
"""
+
def do_hello(self, _: cmd2.Statement):
self._cmd.poutput('Hello')
@@ -33,6 +35,7 @@ class ChildOverridesParentCategoriesNonHeritable(MyBaseCommandSet):
This subclass overrides the 'Default Category' from the parent, but in a non-heritable fashion. Sub-classes of this
CommandSet will not inherit this category and will, instead, inherit 'Default Category'
"""
+
def do_goodbye(self, _: cmd2.Statement):
self._cmd.poutput('Goodbye')
@@ -42,6 +45,7 @@ class GrandchildInheritsGrandparentCategory(ChildOverridesParentCategoriesNonHer
This subclass's parent class declared its default category non-heritable. Instead, it inherits the category defined
by the grandparent class.
"""
+
def do_aloha(self, _: cmd2.Statement):
self._cmd.poutput('Aloha')
@@ -52,6 +56,7 @@ class ChildOverridesParentCategories(MyBaseCommandSet):
This subclass is decorated with a default category that is heritable. This overrides the parent class's default
category declaration.
"""
+
def do_bonjour(self, _: cmd2.Statement):
self._cmd.poutput('Bonjour')
@@ -61,6 +66,7 @@ class GrandchildInheritsHeritable(ChildOverridesParentCategories):
This subclass's parent declares a default category that overrides its parent. As a result, commands in this
CommandSet will be categorized under 'Heritable Category'
"""
+
def do_monde(self, _: cmd2.Statement):
self._cmd.poutput('Monde')
diff --git a/tests_isolated/test_commandset/test_commandset.py b/tests_isolated/test_commandset/test_commandset.py
index 21cce8bf..b6761642 100644
--- a/tests_isolated/test_commandset/test_commandset.py
+++ b/tests_isolated/test_commandset/test_commandset.py
@@ -11,9 +11,10 @@ import pytest
import cmd2
from cmd2 import utils
-from .conftest import complete_tester, WithCommandSets
from cmd2.exceptions import CommandSetRegistrationError
+from .conftest import WithCommandSets, complete_tester
+
class CommandSetBase(cmd2.CommandSet):
pass
@@ -51,9 +52,8 @@ class CommandSetA(CommandSetBase):
def do_cranberry(self, ns: argparse.Namespace, unknown: List[str]):
self._cmd.poutput('Cranberry {}!!'.format(ns.arg1))
if unknown and len(unknown):
- self._cmd.poutput('Unknown: ' + ', '.join(['{}']*len(unknown)).format(*unknown))
- self._cmd.last_result = {'arg1': ns.arg1,
- 'unknown': unknown}
+ self._cmd.poutput('Unknown: ' + ', '.join(['{}'] * len(unknown)).format(*unknown))
+ self._cmd.last_result = {'arg1': ns.arg1, 'unknown': unknown}
def help_cranberry(self):
self._cmd.stdout.write('This command does diddly squat...\n')
@@ -63,7 +63,7 @@ class CommandSetA(CommandSetBase):
def do_durian(self, args: List[str]):
"""Durian Command"""
self._cmd.poutput('{} Arguments: '.format(len(args)))
- self._cmd.poutput(', '.join(['{}']*len(args)).format(*args))
+ self._cmd.poutput(', '.join(['{}'] * len(args)).format(*args))
self._cmd.last_result = {'args': args}
def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> List[str]:
@@ -567,6 +567,7 @@ def test_subcommands(command_sets_manual):
command_sets_manual.unregister_command_set(veg_cmds)
command_sets_manual.unregister_command_set(base_cmds)
+
def test_nested_subcommands(command_sets_manual):
base_cmds = LoadableBase(1)
pasta_cmds = LoadablePastaStir(1)
@@ -614,6 +615,7 @@ def test_nested_subcommands(command_sets_manual):
class AppWithSubCommands(cmd2.Cmd):
"""Class for testing usage of `as_subcommand_to` decorator directly in a Cmd2 subclass."""
+
def __init__(self, *args, **kwargs):
super(AppWithSubCommands, self).__init__(*args, **kwargs)