Skip to content

Commit 9697bf1

Browse files
committed
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
1 parent b3e6625 commit 9697bf1

4 files changed

Lines changed: 34 additions & 37 deletions

File tree

cmd2/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#
22
# -*- coding: utf-8 -*-
33
#
4-
from .cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes, AddSubmenu, cast
5-
from .cmd2 import _which, get_paste_buffer, __version__, POSIX_SHLEX, STRIP_QUOTES_FOR_NON_POSIX
6-
from .cmd2 import can_clip, disable_clip, with_category, categorize
7-
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args
8-
from .cmd2 import ParserManager, History, HistoryItem, EmptyStatement, CmdResult
4+
from .cmd2 import __version__, Cmd, set_posix_shlex, set_strip_quotes, AddSubmenu, CmdResult, categorize
5+
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category

tests/test_cmd2.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def test_base_show_readonly(base_app):
105105
Strip Quotes after splitting arguments: {}
106106
107107
""".format(base_app.terminators, base_app.allow_cli_args, base_app.allow_redirection,
108-
"POSIX" if cmd2.POSIX_SHLEX else "non-POSIX",
109-
"True" if cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.POSIX_SHLEX else "False"))
108+
"POSIX" if cmd2.cmd2.POSIX_SHLEX else "non-POSIX",
109+
"True" if cmd2.cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.cmd2.POSIX_SHLEX else "False"))
110110
assert out == expected
111111

112112

@@ -643,18 +643,18 @@ def test_pipe_to_shell_error(base_app, capsys):
643643
assert err.startswith("EXCEPTION of type '{}' occurred with message:".format(expected_error))
644644

645645

646-
@pytest.mark.skipif(not cmd2.can_clip,
646+
@pytest.mark.skipif(not cmd2.cmd2.can_clip,
647647
reason="Pyperclip could not find a copy/paste mechanism for your system")
648648
def test_send_to_paste_buffer(base_app):
649649
# Test writing to the PasteBuffer/Clipboard
650650
run_cmd(base_app, 'help >')
651651
expected = normalize(BASE_HELP)
652-
assert normalize(cmd2.get_paste_buffer()) == expected
652+
assert normalize(cmd2.cmd2.get_paste_buffer()) == expected
653653

654654
# Test appending to the PasteBuffer/Clipboard
655655
run_cmd(base_app, 'help history >>')
656656
expected = normalize(BASE_HELP + '\n' + HELP_HISTORY)
657-
assert normalize(cmd2.get_paste_buffer()) == expected
657+
assert normalize(cmd2.cmd2.get_paste_buffer()) == expected
658658

659659

660660
def test_base_timing(base_app, capsys):
@@ -1310,15 +1310,15 @@ def test_help_with_no_docstring(capsys):
13101310
reason="cmd2._which function only used on Mac and Linux")
13111311
def test_which_editor_good():
13121312
editor = 'vi'
1313-
path = cmd2._which(editor)
1313+
path = cmd2.cmd2._which(editor)
13141314
# Assert that the vi editor was found because it should exist on all Mac and Linux systems
13151315
assert path
13161316

13171317
@pytest.mark.skipif(sys.platform.startswith('win'),
13181318
reason="cmd2._which function only used on Mac and Linux")
13191319
def test_which_editor_bad():
13201320
editor = 'notepad.exe'
1321-
path = cmd2._which(editor)
1321+
path = cmd2.cmd2._which(editor)
13221322
# Assert that the editor wasn't found because no notepad.exe on non-Windows systems ;-)
13231323
assert path is None
13241324

@@ -1345,7 +1345,7 @@ def multiline_app():
13451345
return app
13461346

13471347
def test_multiline_complete_empty_statement_raises_exception(multiline_app):
1348-
with pytest.raises(cmd2.EmptyStatement):
1348+
with pytest.raises(cmd2.cmd2.EmptyStatement):
13491349
multiline_app._complete_statement('')
13501350

13511351
def test_multiline_complete_statement_without_terminator(multiline_app):
@@ -1363,7 +1363,7 @@ def test_multiline_complete_statement_without_terminator(multiline_app):
13631363

13641364
def test_clipboard_failure(capsys):
13651365
# Force cmd2 clipboard to be disabled
1366-
cmd2.disable_clip()
1366+
cmd2.cmd2.disable_clip()
13671367
app = cmd2.Cmd()
13681368

13691369
# Redirect command output to the clipboard when a clipboard isn't present

tests/test_parsing.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616

1717
@pytest.fixture
1818
def hist():
19-
from cmd2 import HistoryItem
20-
h = cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
19+
from cmd2.cmd2 import HistoryItem
20+
h = cmd2.cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
2121
return h
2222

2323
# Case-sensitive parser
2424
@pytest.fixture
2525
def parser():
2626
c = cmd2.Cmd()
2727
c.multilineCommands = ['multiline']
28-
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
29-
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
30-
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
31-
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
32-
preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
33-
shortcuts=c.shortcuts)
28+
c.parser_manager = cmd2.cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
29+
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
30+
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
31+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
32+
preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
33+
shortcuts=c.shortcuts)
3434
return c.parser_manager.main_parser
3535

3636
# Case-sensitive ParserManager
3737
@pytest.fixture
3838
def cs_pm():
3939
c = cmd2.Cmd()
4040
c.multilineCommands = ['multiline']
41-
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
42-
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
43-
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
44-
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
45-
preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
46-
shortcuts=c.shortcuts)
41+
c.parser_manager = cmd2.cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators,
42+
multilineCommands=c.multilineCommands, legalChars=c.legalChars,
43+
commentGrammars=c.commentGrammars, commentInProgress=c.commentInProgress,
44+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
45+
preparse=c.preparse, postparse=c.postparse, aliases=c.aliases,
46+
shortcuts=c.shortcuts)
4747
return c.parser_manager
4848

4949

@@ -77,7 +77,7 @@ def test_history_get(hist):
7777

7878

7979
def test_cast():
80-
cast = cmd2.cast
80+
cast = cmd2.cmd2.cast
8181

8282
# Boolean
8383
assert cast(True, True) == True
@@ -101,7 +101,7 @@ def test_cast():
101101

102102

103103
def test_cast_problems(capsys):
104-
cast = cmd2.cast
104+
cast = cmd2.cmd2.cast
105105

106106
expected = 'Problem setting parameter (now {}) to {}; incorrect type?\n'
107107

@@ -327,8 +327,8 @@ def test_parse_input_redirect_from_unicode_filename(input_parser):
327327

328328
def test_empty_statement_raises_exception():
329329
app = cmd2.Cmd()
330-
with pytest.raises(cmd2.EmptyStatement):
330+
with pytest.raises(cmd2.cmd2.EmptyStatement):
331331
app._complete_statement('')
332332

333-
with pytest.raises(cmd2.EmptyStatement):
333+
with pytest.raises(cmd2.cmd2.EmptyStatement):
334334
app._complete_statement(' ')

tests/test_transcript.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import pytest
1616

1717
import cmd2
18-
from cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes
18+
from cmd2 import set_posix_shlex, set_strip_quotes
1919
from .conftest import run_cmd, StdOut, normalize
2020

21-
class CmdLineApp(Cmd):
21+
class CmdLineApp(cmd2.Cmd):
2222

2323
MUMBLES = ['like', '...', 'um', 'er', 'hmmm', 'ahh']
2424
MUMBLE_FIRST = ['so', 'like', 'well']
@@ -82,7 +82,7 @@ def do_mumble(self, opts, arg):
8282
self.poutput(' '.join(output))
8383

8484

85-
class DemoApp(Cmd):
85+
class DemoApp(cmd2.Cmd):
8686
hello_parser = argparse.ArgumentParser()
8787
hello_parser.add_argument('-n', '--name', help="your name")
8888
@cmd2.with_argparser_and_unknown_args(hello_parser)
@@ -189,7 +189,7 @@ def test_base_with_transcript(_cmdline_app):
189189
assert out == expected
190190

191191

192-
class TestMyAppCase(Cmd2TestCase):
192+
class TestMyAppCase(cmd2.cmd2.Cmd2TestCase):
193193
CmdApp = CmdLineApp
194194
CmdApp.testfiles = ['tests/transcript.txt']
195195

@@ -293,7 +293,7 @@ def test_transcript(request, capsys, filename, feedback_to_output):
293293
def test_parse_transcript_expected(expected, transformed):
294294
app = CmdLineApp()
295295

296-
class TestMyAppCase(Cmd2TestCase):
296+
class TestMyAppCase(cmd2.cmd2.Cmd2TestCase):
297297
cmdapp = app
298298

299299
testcase = TestMyAppCase()

0 commit comments

Comments
 (0)