Skip to content

Commit b6bf292

Browse files
committed
Fixed a unit test
Also: - Added a couple unit tests related to case-sensitive vs case-insensitive parsing - Updated CHANGES.md
1 parent f594dc2 commit b6bf292

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ News
77
*Release date: TBD*
88

99
* Bug Fixes
10-
* Fixed some timing bugs when running unit tests in parallel by using monkeypatch
10+
* Case-sensitive command parsing was completely broken and has been fixed
11+
* <Ctrl>+D now properly quits when case-sensitive command parsing is enabled
1112
* Fixed some pyperclip clipboard interaction bugs on Linux
12-
13+
* Fixed some timing bugs when running unit tests in parallel by using monkeypatch
14+
1315
0.7.5
1416
-----
1517

tests/test_cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,4 +1335,4 @@ def test_empty_stdin_input():
13351335
app.stdin.readline = m
13361336

13371337
line = app.pseudo_raw_input('(cmd2)')
1338-
assert line == 'EOF'
1338+
assert line == 'eof'

tests/test_parsing.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def hist():
2020
h = cmd2.History([HistoryItem('first'), HistoryItem('second'), HistoryItem('third'), HistoryItem('fourth')])
2121
return h
2222

23+
# Case-insensitive parser
2324
@pytest.fixture
2425
def parser():
2526
c = cmd2.Cmd()
@@ -32,6 +33,33 @@ def parser():
3233
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
3334
return c.parser_manager.main_parser
3435

36+
# Case-insensitive ParserManager
37+
@pytest.fixture
38+
def ci_pm():
39+
c = cmd2.Cmd()
40+
c.multilineCommands = ['multiline']
41+
c.case_insensitive = True
42+
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
43+
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
44+
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
45+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
46+
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
47+
return c.parser_manager
48+
49+
# Case-sensitive ParserManager
50+
@pytest.fixture
51+
def cs_pm():
52+
c = cmd2.Cmd()
53+
c.multilineCommands = ['multiline']
54+
c.case_insensitive = False
55+
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
56+
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
57+
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
58+
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
59+
preparse=c.preparse, postparse=c.postparse, shortcuts=c.shortcuts)
60+
return c.parser_manager
61+
62+
3563
@pytest.fixture
3664
def input_parser():
3765
c = cmd2.Cmd()
@@ -190,6 +218,18 @@ def test_parse_output_redirect_with_dash_in_path(parser):
190218
assert results.output == '>'
191219
assert results.outputTo == 'python-cmd2/afile.txt'
192220

221+
222+
def test_case_insensitive_parsed_single_word(ci_pm):
223+
line = 'HeLp'
224+
statement = ci_pm.parsed(line)
225+
assert statement.parsed.command == line.lower()
226+
227+
def test_case_sensitive_parsed_single_word(cs_pm):
228+
line = 'HeLp'
229+
statement = cs_pm.parsed(line)
230+
assert statement.parsed.command == line
231+
232+
193233
def test_parse_input_redirect(input_parser):
194234
line = '< afile.txt'
195235
results = input_parser.parseString(line)

0 commit comments

Comments
 (0)