summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/__init__.py4
-rw-r--r--cmd2/argcomplete_bridge.py42
-rwxr-xr-xexamples/alias_startup.py4
-rwxr-xr-xexamples/arg_print.py6
-rwxr-xr-xexamples/argparse_example.py2
-rwxr-xr-xexamples/environment.py2
-rwxr-xr-xexamples/event_loops.py2
-rwxr-xr-xexamples/example.py2
-rwxr-xr-xexamples/help_categories.py2
-rwxr-xr-xexamples/paged_output.py4
-rwxr-xr-xexamples/persistent_history.py2
-rwxr-xr-xexamples/pirate.py2
-rwxr-xr-xexamples/python_scripting.py2
-rwxr-xr-xexamples/remove_unused.py2
-rwxr-xr-xexamples/subcommands.py71
-rwxr-xr-xexamples/submenus.py2
-rwxr-xr-xexamples/tab_autocompletion.py4
-rwxr-xr-xexamples/tab_completion.py4
-rwxr-xr-xexamples/table_display.py2
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/test_argparse.py2
-rw-r--r--tests/test_cmd2.py20
-rw-r--r--tests/test_completion.py2
-rw-r--r--tests/test_parsing.py18
-rw-r--r--tests/test_submenu.py2
-rw-r--r--tests/test_transcript.py8
26 files changed, 128 insertions, 87 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py
index 773eba37..cea82e57 100644
--- a/cmd2/__init__.py
+++ b/cmd2/__init__.py
@@ -1,8 +1,8 @@
#
# -*- coding: utf-8 -*-
#
-from .cmd2 import __version__, Cmd, set_posix_shlex, set_strip_quotes, AddSubmenu, CmdResult, categorize
-from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
+# from .cmd2 import __version__, Cmd, set_posix_shlex, set_strip_quotes, AddSubmenu, CmdResult, categorize
+# from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
# Used for tab completion and word breaks. Do not change.
QUOTES = ['"', "'"]
diff --git a/cmd2/argcomplete_bridge.py b/cmd2/argcomplete_bridge.py
index 93b3cbbb..f1ed910e 100644
--- a/cmd2/argcomplete_bridge.py
+++ b/cmd2/argcomplete_bridge.py
@@ -2,7 +2,9 @@
"""Hijack the ArgComplete's bash completion handler to return AutoCompleter results"""
import argcomplete
+from contextlib import redirect_stdout
import copy
+from io import StringIO
import os
import shlex
import sys
@@ -162,7 +164,13 @@ class CompletionFinder(argcomplete.CompletionFinder):
comp_point = int(os.environ["COMP_POINT"])
comp_line = argcomplete.ensure_str(comp_line)
- ### SWAPPED FOR AUTOCOMPLETER
+
+ ##############################
+ # SWAPPED FOR AUTOCOMPLETER
+ #
+ # Replaced with our own tokenizer function
+ ##############################
+
# cword_prequote, cword_prefix, cword_suffix, comp_words, last_wordbreak_pos = split_line(comp_line, comp_point)
tokens, _, begidx, endidx = tokens_for_completion(comp_line, comp_point)
@@ -172,7 +180,11 @@ class CompletionFinder(argcomplete.CompletionFinder):
# 2: python <script> [args]
# 3: python -m <module> [args]
start = int(os.environ["_ARGCOMPLETE"]) - 1
- ### SWAPPED FOR AUTOCOMPLETER
+ ##############################
+ # SWAPPED FOR AUTOCOMPLETER
+ #
+ # Applying the same token dropping to our tokens
+ ##############################
# comp_words = comp_words[start:]
tokens = tokens[start:]
@@ -183,11 +195,20 @@ class CompletionFinder(argcomplete.CompletionFinder):
# "\nSUFFIX: {!r}".format(cword_suffix),
# "\nWORDS:", comp_words)
- ### SWAPPED FOR AUTOCOMPLETER
+ ##############################
+ # SWAPPED FOR AUTOCOMPLETER
+ #
+ # Replaced with our own completion function and customizing the returned values
+ ##############################
# completions = self._get_completions(comp_words, cword_prefix, cword_prequote, last_wordbreak_pos)
- completions = completer.complete_command(tokens, tokens[-1], comp_line, begidx, endidx)
- if completions is not None:
+ # capture stdout from the autocompleter
+ result = StringIO()
+ with redirect_stdout(result):
+ completions = completer.complete_command(tokens, tokens[-1], comp_line, begidx, endidx)
+ outstr = result.getvalue()
+
+ if completions:
# If any completion has a space in it, then quote all completions
# this improves the user experience so they don't nede to go back and add a quote
if ' ' in ''.join(completions):
@@ -196,6 +217,17 @@ class CompletionFinder(argcomplete.CompletionFinder):
argcomplete.debug("\nReturning completions:", completions)
output_stream.write(ifs.join(completions).encode(argcomplete.sys_encoding))
+ elif outstr:
+ # if there are no completions, but we got something from stdout, try to print help
+
+ # trick the bash completion into thinking there are 2 completions that are unlikely
+ # to ever match.
+ outstr = outstr.replace('\n', ' ').replace('\t', ' ').replace(' ', ' ').strip()
+ # generate a filler entry that should always sort first
+ filler = ' {0:><{width}}'.format('', width=len(outstr))
+ outstr = ifs.join([filler, outstr])
+
+ output_stream.write(outstr.encode(argcomplete.sys_encoding))
else:
# if completions is None we assume we don't know how to handle it so let bash
# go forward with normal filesystem completion
diff --git a/examples/alias_startup.py b/examples/alias_startup.py
index 30764c27..a02972b6 100755
--- a/examples/alias_startup.py
+++ b/examples/alias_startup.py
@@ -6,10 +6,10 @@
"""
import argparse
-import cmd2
+from cmd2 import cmd2
import pyparsing
-from cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
+from cmd2.cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
class AliasAndStartup(cmd2.Cmd):
diff --git a/examples/arg_print.py b/examples/arg_print.py
index 18fa483f..90df053a 100755
--- a/examples/arg_print.py
+++ b/examples/arg_print.py
@@ -11,10 +11,8 @@ It also serves as an example of how to create command aliases (shortcuts).
"""
import argparse
-import cmd2
-import pyparsing
-
-from cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
+from cmd2 import cmd2
+from cmd2.cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
class ArgumentAndOptionPrinter(cmd2.Cmd):
diff --git a/examples/argparse_example.py b/examples/argparse_example.py
index e9b377ba..e8afef5c 100755
--- a/examples/argparse_example.py
+++ b/examples/argparse_example.py
@@ -14,7 +14,7 @@ verifying that the output produced matches the transcript.
import argparse
import sys
-from cmd2 import Cmd, with_argparser, with_argument_list
+from cmd2.cmd2 import Cmd, with_argparser, with_argument_list
class CmdLineApp(Cmd):
diff --git a/examples/environment.py b/examples/environment.py
index c245f55d..af452e4e 100755
--- a/examples/environment.py
+++ b/examples/environment.py
@@ -4,7 +4,7 @@
A sample application for cmd2 demonstrating customized environment parameters
"""
-from cmd2 import Cmd
+from cmd2.cmd2 import Cmd
class EnvironmentApp(Cmd):
diff --git a/examples/event_loops.py b/examples/event_loops.py
index 53d3ca2b..a76c5d91 100755
--- a/examples/event_loops.py
+++ b/examples/event_loops.py
@@ -6,7 +6,7 @@ This is an example of how to use cmd2 in a way so that cmd2 doesn't own the inne
This opens up the possibility of registering cmd2 input with event loops, like asyncio, without occupying the main loop.
"""
-import cmd2
+from cmd2 import cmd2
class Cmd2EventBased(cmd2.Cmd):
diff --git a/examples/example.py b/examples/example.py
index 612d81e5..1fc6bf6d 100755
--- a/examples/example.py
+++ b/examples/example.py
@@ -14,7 +14,7 @@ the transcript.
import random
import argparse
-from cmd2 import Cmd, with_argparser
+from cmd2.cmd2 import Cmd, with_argparser
class CmdLineApp(Cmd):
diff --git a/examples/help_categories.py b/examples/help_categories.py
index cfb5f253..7adedb51 100755
--- a/examples/help_categories.py
+++ b/examples/help_categories.py
@@ -4,7 +4,7 @@
A sample application for tagging categories on commands.
"""
-from cmd2 import Cmd, categorize, __version__, with_argparser, with_category
+from cmd2.cmd2 import Cmd, categorize, __version__, with_argparser, with_category
import argparse
diff --git a/examples/paged_output.py b/examples/paged_output.py
index bb410af6..9396f04e 100755
--- a/examples/paged_output.py
+++ b/examples/paged_output.py
@@ -3,8 +3,8 @@
"""A simple example demonstrating the using paged output via the ppaged() method.
"""
-import cmd2
-from cmd2 import with_argument_list
+from cmd2 import cmd2
+from cmd2.cmd2 import with_argument_list
class PagedOutput(cmd2.Cmd):
diff --git a/examples/persistent_history.py b/examples/persistent_history.py
index 61e26b9c..251dbd67 100755
--- a/examples/persistent_history.py
+++ b/examples/persistent_history.py
@@ -5,7 +5,7 @@
This will allow end users of your cmd2-based application to use the arrow keys and Ctrl+r in a manner which persists
across invocations of your cmd2 application. This can make it much easier for them to use your application.
"""
-import cmd2
+from cmd2 import cmd2
class Cmd2PersistentHistory(cmd2.Cmd):
diff --git a/examples/pirate.py b/examples/pirate.py
index 7fe3884b..2daa8631 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -7,7 +7,7 @@ presented as part of her PyCon 2010 talk.
It demonstrates many features of cmd2.
"""
import argparse
-from cmd2 import Cmd, with_argparser
+from cmd2.cmd2 import Cmd, with_argparser
class Pirate(Cmd):
diff --git a/examples/python_scripting.py b/examples/python_scripting.py
index 7e2cf345..865cf052 100755
--- a/examples/python_scripting.py
+++ b/examples/python_scripting.py
@@ -17,7 +17,7 @@ This application and the "scripts/conditional.py" script serve as an example for
import argparse
import os
-import cmd2
+from cmd2 import cmd2
class CmdLineApp(cmd2.Cmd):
diff --git a/examples/remove_unused.py b/examples/remove_unused.py
index 8a567123..dfe0a055 100755
--- a/examples/remove_unused.py
+++ b/examples/remove_unused.py
@@ -9,7 +9,7 @@ name, they just won't clutter the help menu.
Commands can also be removed entirely by using Python's "del".
"""
-import cmd2
+from cmd2 import cmd2
class RemoveUnusedBuiltinCommands(cmd2.Cmd):
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 75c0733e..01f5b218 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -1,18 +1,56 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# coding=utf-8
+# PYTHON_ARGCOMPLETE_OK
"""A simple example demonstrating how to use Argparse to support subcommands.
This example shows an easy way for a single command to have many subcommands, each of which takes different arguments
and provides separate contextual help.
"""
+from cmd2.argcomplete_bridge import CompletionFinder
+from cmd2.argparse_completer import AutoCompleter
import argparse
-import cmd2
-from cmd2 import with_argparser
-
sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
+# create the top-level parser for the base command
+base_parser = argparse.ArgumentParser(prog='base')
+base_subparsers = base_parser.add_subparsers(title='subcommands', help='subcommand help')
+
+# create the parser for the "foo" subcommand
+parser_foo = base_subparsers.add_parser('foo', help='foo help')
+parser_foo.add_argument('-x', type=int, default=1, help='integer')
+parser_foo.add_argument('y', type=float, help='float')
+
+# create the parser for the "bar" subcommand
+parser_bar = base_subparsers.add_parser('bar', help='bar help')
+
+bar_subparsers = parser_bar.add_subparsers(title='layer3', help='help for 3rd layer of commands')
+parser_bar.add_argument('z', help='string')
+
+bar_subparsers.add_parser('apple', help='apple help')
+bar_subparsers.add_parser('artichoke', help='artichoke help')
+bar_subparsers.add_parser('cranberries', help='cranberries help')
+
+# create the parser for the "sport" subcommand
+parser_sport = base_subparsers.add_parser('sport', help='sport help')
+sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport')
+setattr(sport_arg, 'arg_choices', sport_item_strs)
+
+# Set both a function and tab completer for the "sport" subcommand
+
+if __name__ == '__main__':
+ with open('out.txt', 'a') as f:
+ f.write('Here 1')
+ f.flush()
+ completer = CompletionFinder()
+ completer(base_parser, AutoCompleter(base_parser))
+
+
+from cmd2 import cmd2
+from cmd2.cmd2 import with_argparser
+
+
class SubcommandsExample(cmd2.Cmd):
"""
Example cmd2 application where we a base command which has a couple subcommands
@@ -35,33 +73,8 @@ class SubcommandsExample(cmd2.Cmd):
"""sport subcommand of base command"""
self.poutput('Sport is {}'.format(args.sport))
- # create the top-level parser for the base command
- base_parser = argparse.ArgumentParser(prog='base')
- base_subparsers = base_parser.add_subparsers(title='subcommands', help='subcommand help')
-
- # create the parser for the "foo" subcommand
- parser_foo = base_subparsers.add_parser('foo', help='foo help')
- parser_foo.add_argument('-x', type=int, default=1, help='integer')
- parser_foo.add_argument('y', type=float, help='float')
parser_foo.set_defaults(func=base_foo)
-
- # create the parser for the "bar" subcommand
- parser_bar = base_subparsers.add_parser('bar', help='bar help')
parser_bar.set_defaults(func=base_bar)
-
- bar_subparsers = parser_bar.add_subparsers(title='layer3', help='help for 3rd layer of commands')
- parser_bar.add_argument('z', help='string')
-
- bar_subparsers.add_parser('apple', help='apple help')
- bar_subparsers.add_parser('artichoke', help='artichoke help')
- bar_subparsers.add_parser('cranberries', help='cranberries help')
-
- # create the parser for the "sport" subcommand
- parser_sport = base_subparsers.add_parser('sport', help='sport help')
- sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport')
- setattr(sport_arg, 'arg_choices', sport_item_strs)
-
- # Set both a function and tab completer for the "sport" subcommand
parser_sport.set_defaults(func=base_sport)
@with_argparser(base_parser)
diff --git a/examples/submenus.py b/examples/submenus.py
index 44b17f33..27c8cb10 100755
--- a/examples/submenus.py
+++ b/examples/submenus.py
@@ -11,7 +11,7 @@ of the submenu. Nesting of the submenus is done with the cmd2.AddSubmenu() decor
from __future__ import print_function
import sys
-import cmd2
+from cmd2 import cmd2
from IPython import embed
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py
index a1a8daee..02c48ca5 100755
--- a/examples/tab_autocompletion.py
+++ b/examples/tab_autocompletion.py
@@ -10,8 +10,8 @@ import argparse
import itertools
from typing import List
-import cmd2
-from cmd2 import with_argparser, with_category, argparse_completer
+from cmd2 import cmd2, argparse_completer
+from cmd2.cmd2 import with_argparser, with_category
actors = ['Mark Hamill', 'Harrison Ford', 'Carrie Fisher', 'Alec Guinness', 'Peter Mayhew',
'Anthony Daniels', 'Adam Driver', 'Daisy Ridley', 'John Boyega', 'Oscar Isaac',
diff --git a/examples/tab_completion.py b/examples/tab_completion.py
index 919e9560..30fa283d 100755
--- a/examples/tab_completion.py
+++ b/examples/tab_completion.py
@@ -4,8 +4,8 @@
"""
import argparse
-import cmd2
-from cmd2 import with_argparser, with_argument_list
+from cmd2 import cmd2
+from cmd2.cmd2 import with_argparser, with_argument_list
# List of strings used with flag and index based completion functions
food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato']
diff --git a/examples/table_display.py b/examples/table_display.py
index 2e6ea804..5d168408 100755
--- a/examples/table_display.py
+++ b/examples/table_display.py
@@ -12,7 +12,7 @@ WARNING: This example requires the tabulate module.
"""
import functools
-import cmd2
+from cmd2 import cmd2
import tabulate
# Format to use with tabulate module when displaying tables
diff --git a/tests/conftest.py b/tests/conftest.py
index ed76cba9..0a42d833 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -10,7 +10,7 @@ import sys
from pytest import fixture
from unittest import mock
-import cmd2
+from cmd2 import cmd2
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
try:
diff --git a/tests/test_argparse.py b/tests/test_argparse.py
index 6a9a93a7..e23c5d17 100644
--- a/tests/test_argparse.py
+++ b/tests/test_argparse.py
@@ -5,7 +5,7 @@ Cmd2 testing for argument parsing
import argparse
import pytest
-import cmd2
+from cmd2 import cmd2
from unittest import mock
from .conftest import run_cmd, StdOut
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 48f50bdc..c8955497 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -21,7 +21,7 @@ try:
except ImportError:
from unittest import mock
-import cmd2
+from cmd2 import cmd2
from .conftest import run_cmd, normalize, BASE_HELP, BASE_HELP_VERBOSE, \
HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT, SHOW_LONG, StdOut
@@ -109,8 +109,8 @@ def test_base_show_readonly(base_app):
Strip Quotes after splitting arguments: {}
""".format(base_app.terminators, base_app.allow_cli_args, base_app.allow_redirection,
- "POSIX" if cmd2.cmd2.POSIX_SHLEX else "non-POSIX",
- "True" if cmd2.cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.cmd2.POSIX_SHLEX else "False"))
+ "POSIX" if cmd2.POSIX_SHLEX else "non-POSIX",
+ "True" if cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.POSIX_SHLEX else "False"))
assert out == expected
@@ -647,18 +647,18 @@ def test_pipe_to_shell_error(base_app, capsys):
assert err.startswith("EXCEPTION of type '{}' occurred with message:".format(expected_error))
-@pytest.mark.skipif(not cmd2.cmd2.can_clip,
+@pytest.mark.skipif(not cmd2.can_clip,
reason="Pyperclip could not find a copy/paste mechanism for your system")
def test_send_to_paste_buffer(base_app):
# Test writing to the PasteBuffer/Clipboard
run_cmd(base_app, 'help >')
expected = normalize(BASE_HELP)
- assert normalize(cmd2.cmd2.get_paste_buffer()) == expected
+ assert normalize(cmd2.get_paste_buffer()) == expected
# Test appending to the PasteBuffer/Clipboard
run_cmd(base_app, 'help history >>')
expected = normalize(BASE_HELP + '\n' + HELP_HISTORY)
- assert normalize(cmd2.cmd2.get_paste_buffer()) == expected
+ assert normalize(cmd2.get_paste_buffer()) == expected
def test_base_timing(base_app, capsys):
@@ -1314,7 +1314,7 @@ optional arguments:
reason="cmd2._which function only used on Mac and Linux")
def test_which_editor_good():
editor = 'vi'
- path = cmd2.cmd2._which(editor)
+ path = cmd2._which(editor)
# Assert that the vi editor was found because it should exist on all Mac and Linux systems
assert path
@@ -1322,7 +1322,7 @@ def test_which_editor_good():
reason="cmd2._which function only used on Mac and Linux")
def test_which_editor_bad():
editor = 'notepad.exe'
- path = cmd2.cmd2._which(editor)
+ path = cmd2._which(editor)
# Assert that the editor wasn't found because no notepad.exe on non-Windows systems ;-)
assert path is None
@@ -1349,7 +1349,7 @@ def multiline_app():
return app
def test_multiline_complete_empty_statement_raises_exception(multiline_app):
- with pytest.raises(cmd2.cmd2.EmptyStatement):
+ with pytest.raises(cmd2.EmptyStatement):
multiline_app._complete_statement('')
def test_multiline_complete_statement_without_terminator(multiline_app):
@@ -1367,7 +1367,7 @@ def test_multiline_complete_statement_without_terminator(multiline_app):
def test_clipboard_failure(capsys):
# Force cmd2 clipboard to be disabled
- cmd2.cmd2.disable_clip()
+ cmd2.disable_clip()
app = cmd2.Cmd()
# Redirect command output to the clipboard when a clipboard isn't present
diff --git a/tests/test_completion.py b/tests/test_completion.py
index cf45f281..2c600018 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -12,7 +12,7 @@ import argparse
import os
import sys
-import cmd2
+from cmd2 import cmd2
import pytest
from .conftest import complete_tester, StdOut
from examples.subcommands import SubcommandsExample
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 2682ec68..b61e2d06 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -8,16 +8,14 @@ problematic because they worked properly for some versions of pyparsing but not
Copyright 2017 Todd Leonhardt <todd.leonhardt@gmail.com>
Released under MIT license, see LICENSE file
"""
-import sys
-
-import cmd2
+from cmd2 import cmd2
import pytest
@pytest.fixture
def hist():
from cmd2.cmd2 import HistoryItem
- h = cmd2.cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
+ h = cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
return h
# Case-sensitive parser
@@ -25,7 +23,7 @@ def hist():
def parser():
c = cmd2.Cmd()
c.multilineCommands = ['multiline']
- c.parser_manager = cmd2.cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
+ c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
@@ -38,7 +36,7 @@ def parser():
def cs_pm():
c = cmd2.Cmd()
c.multilineCommands = ['multiline']
- c.parser_manager = cmd2.cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
+ c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
@@ -77,7 +75,7 @@ def test_history_get(hist):
def test_cast():
- cast = cmd2.cmd2.cast
+ cast = cmd2.cast
# Boolean
assert cast(True, True) == True
@@ -101,7 +99,7 @@ def test_cast():
def test_cast_problems(capsys):
- cast = cmd2.cmd2.cast
+ cast = cmd2.cast
expected = 'Problem setting parameter (now {}) to {}; incorrect type?\n'
@@ -327,8 +325,8 @@ def test_parse_input_redirect_from_unicode_filename(input_parser):
def test_empty_statement_raises_exception():
app = cmd2.Cmd()
- with pytest.raises(cmd2.cmd2.EmptyStatement):
+ with pytest.raises(cmd2.EmptyStatement):
app._complete_statement('')
- with pytest.raises(cmd2.cmd2.EmptyStatement):
+ with pytest.raises(cmd2.EmptyStatement):
app._complete_statement(' ')
diff --git a/tests/test_submenu.py b/tests/test_submenu.py
index fbb9857b..db334daa 100644
--- a/tests/test_submenu.py
+++ b/tests/test_submenu.py
@@ -4,7 +4,7 @@ Cmd2 testing for argument parsing
"""
import pytest
-import cmd2
+from cmd2 import cmd2
from .conftest import run_cmd, StdOut, normalize
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index 8ee5f3f6..4f821c06 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -14,8 +14,8 @@ import random
from unittest import mock
import pytest
-import cmd2
-from cmd2 import set_posix_shlex, set_strip_quotes
+from cmd2 import cmd2
+from cmd2.cmd2 import set_posix_shlex, set_strip_quotes
from .conftest import run_cmd, StdOut, normalize
class CmdLineApp(cmd2.Cmd):
@@ -189,7 +189,7 @@ now: --->
assert out == expected
-class TestMyAppCase(cmd2.cmd2.Cmd2TestCase):
+class TestMyAppCase(cmd2.Cmd2TestCase):
CmdApp = CmdLineApp
CmdApp.testfiles = ['tests/transcript.txt']
@@ -293,7 +293,7 @@ def test_transcript(request, capsys, filename, feedback_to_output):
def test_parse_transcript_expected(expected, transformed):
app = CmdLineApp()
- class TestMyAppCase(cmd2.cmd2.Cmd2TestCase):
+ class TestMyAppCase(cmd2.Cmd2TestCase):
cmdapp = app
testcase = TestMyAppCase()