summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-04-17 19:30:18 -0700
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-04-17 19:30:18 -0700
commit9697bf1858c6ef06e13bdfd3dfaea6d0376d9a6a (patch)
treecaef34b8dbc7389b249876d182e1ec6629f02db3
parentb3e6625001e64a2516eba33ca526d45e25d1ca5f (diff)
downloadcmd2-git-9697bf1858c6ef06e13bdfd3dfaea6d0376d9a6a.tar.gz
Cleaned up __init__.py
Removed things which were only needed for unit tests from __init__.py - Converted to importing from cmd2.cmd2.<foo> within the relevant unit tests
-rw-r--r--cmd2/__init__.py7
-rw-r--r--tests/test_cmd2.py18
-rw-r--r--tests/test_parsing.py36
-rw-r--r--tests/test_transcript.py10
4 files changed, 34 insertions, 37 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py
index 18b80585..8e744e03 100644
--- a/cmd2/__init__.py
+++ b/cmd2/__init__.py
@@ -1,8 +1,5 @@
#
# -*- coding: utf-8 -*-
#
-from .cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes, AddSubmenu, cast
-from .cmd2 import _which, get_paste_buffer, __version__, POSIX_SHLEX, STRIP_QUOTES_FOR_NON_POSIX
-from .cmd2 import can_clip, disable_clip, with_category, categorize
-from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
-from .cmd2 import ParserManager, History, HistoryItem, EmptyStatement, CmdResult
+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
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index daa58a06..35ef4c0f 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -105,8 +105,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.POSIX_SHLEX else "non-POSIX",
- "True" if cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.POSIX_SHLEX else "False"))
+ "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"))
assert out == expected
@@ -643,18 +643,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.can_clip,
+@pytest.mark.skipif(not cmd2.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.get_paste_buffer()) == expected
+ assert normalize(cmd2.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.get_paste_buffer()) == expected
+ assert normalize(cmd2.cmd2.get_paste_buffer()) == expected
def test_base_timing(base_app, capsys):
@@ -1310,7 +1310,7 @@ optional arguments:
reason="cmd2._which function only used on Mac and Linux")
def test_which_editor_good():
editor = 'vi'
- path = cmd2._which(editor)
+ path = cmd2.cmd2._which(editor)
# Assert that the vi editor was found because it should exist on all Mac and Linux systems
assert path
@@ -1318,7 +1318,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._which(editor)
+ path = cmd2.cmd2._which(editor)
# Assert that the editor wasn't found because no notepad.exe on non-Windows systems ;-)
assert path is None
@@ -1345,7 +1345,7 @@ def multiline_app():
return app
def test_multiline_complete_empty_statement_raises_exception(multiline_app):
- with pytest.raises(cmd2.EmptyStatement):
+ with pytest.raises(cmd2.cmd2.EmptyStatement):
multiline_app._complete_statement('')
def test_multiline_complete_statement_without_terminator(multiline_app):
@@ -1363,7 +1363,7 @@ def test_multiline_complete_statement_without_terminator(multiline_app):
def test_clipboard_failure(capsys):
# Force cmd2 clipboard to be disabled
- cmd2.disable_clip()
+ cmd2.cmd2.disable_clip()
app = cmd2.Cmd()
# Redirect command output to the clipboard when a clipboard isn't present
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index e2367a37..2682ec68 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -16,8 +16,8 @@ import pytest
@pytest.fixture
def hist():
- from cmd2 import HistoryItem
- h = cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
+ from cmd2.cmd2 import HistoryItem
+ h = cmd2.cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
return h
# Case-sensitive parser
@@ -25,12 +25,12 @@ def hist():
def parser():
c = cmd2.Cmd()
c.multilineCommands = ['multiline']
- 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,
- preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
- shortcuts=c.shortcuts)
+ c.parser_manager = cmd2.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,
+ preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
+ shortcuts=c.shortcuts)
return c.parser_manager.main_parser
# Case-sensitive ParserManager
@@ -38,12 +38,12 @@ def parser():
def cs_pm():
c = cmd2.Cmd()
c.multilineCommands = ['multiline']
- 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,
- preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
- shortcuts=c.shortcuts)
+ c.parser_manager = cmd2.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,
+ preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
+ shortcuts=c.shortcuts)
return c.parser_manager
@@ -77,7 +77,7 @@ def test_history_get(hist):
def test_cast():
- cast = cmd2.cast
+ cast = cmd2.cmd2.cast
# Boolean
assert cast(True, True) == True
@@ -101,7 +101,7 @@ def test_cast():
def test_cast_problems(capsys):
- cast = cmd2.cast
+ cast = cmd2.cmd2.cast
expected = 'Problem setting parameter (now {}) to {}; incorrect type?\n'
@@ -327,8 +327,8 @@ def test_parse_input_redirect_from_unicode_filename(input_parser):
def test_empty_statement_raises_exception():
app = cmd2.Cmd()
- with pytest.raises(cmd2.EmptyStatement):
+ with pytest.raises(cmd2.cmd2.EmptyStatement):
app._complete_statement('')
- with pytest.raises(cmd2.EmptyStatement):
+ with pytest.raises(cmd2.cmd2.EmptyStatement):
app._complete_statement(' ')
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index e25d8532..8ee5f3f6 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -15,10 +15,10 @@ from unittest import mock
import pytest
import cmd2
-from cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes
+from cmd2 import set_posix_shlex, set_strip_quotes
from .conftest import run_cmd, StdOut, normalize
-class CmdLineApp(Cmd):
+class CmdLineApp(cmd2.Cmd):
MUMBLES = ['like', '...', 'um', 'er', 'hmmm', 'ahh']
MUMBLE_FIRST = ['so', 'like', 'well']
@@ -82,7 +82,7 @@ class CmdLineApp(Cmd):
self.poutput(' '.join(output))
-class DemoApp(Cmd):
+class DemoApp(cmd2.Cmd):
hello_parser = argparse.ArgumentParser()
hello_parser.add_argument('-n', '--name', help="your name")
@cmd2.with_argparser_and_unknown_args(hello_parser)
@@ -189,7 +189,7 @@ now: --->
assert out == expected
-class TestMyAppCase(Cmd2TestCase):
+class TestMyAppCase(cmd2.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(Cmd2TestCase):
+ class TestMyAppCase(cmd2.cmd2.Cmd2TestCase):
cmdapp = app
testcase = TestMyAppCase()