Skip to content

Commit 8a1f93f

Browse files
committed
Updated tests.
1 parent 5be1072 commit 8a1f93f

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

examples/hello_cmd2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
include_ipy=True, # Enable support for interactive Python shell via py command
1414
include_py=True, # Enable support for interactive IPython shell via ipy command
1515
persistent_history_file='cmd2_history.dat', # Persist history between runs
16-
multiline_commands=["help"],
1716
)
1817
app.self_in_py = True # Enable access to "self" within the py command
1918
app.debug = True # Show traceback if/when an exception occurs

tests/test_cmd2.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,45 @@ def test_nonexistent_macro(base_app) -> None:
27802780
assert exception is not None
27812781

27822782

2783+
@pytest.mark.parametrize(
2784+
# The line of text and whether to continue prompting to finish a multiline command.
2785+
('line', 'should_continue'),
2786+
[
2787+
("", False),
2788+
(" ", False),
2789+
("help", False),
2790+
("help alias", False),
2791+
("orate", True),
2792+
("orate;", False),
2793+
("orate\n", False),
2794+
("orate\narg", True),
2795+
("orate\narg;", False),
2796+
("orate\narg\n", False),
2797+
("single_mac", False), # macro resolution error returns False (no arg passed)
2798+
("single_mac arg", False),
2799+
("multi_mac", False), # macro resolution error returns False (no arg passed)
2800+
("multi_mac arg", True),
2801+
("multi_mac arg;", False),
2802+
("multi_mac arg\n", False),
2803+
("multi_mac\narg", True),
2804+
("multi_mac\narg;", False),
2805+
("multi_mac\narg\n", False),
2806+
],
2807+
)
2808+
def test_should_continue_multiline(multiline_app: MultilineApp, line: str, should_continue: bool) -> None:
2809+
mock_buffer = mock.MagicMock()
2810+
mock_buffer.text = line
2811+
2812+
mock_app = mock.MagicMock()
2813+
mock_app.current_buffer = mock_buffer
2814+
2815+
run_cmd(multiline_app, "macro create single_mac help {1}")
2816+
run_cmd(multiline_app, "macro create multi_mac orate {1}")
2817+
2818+
with mock.patch('cmd2.cmd2.get_app', return_value=mock_app):
2819+
assert multiline_app._should_continue_multiline() is should_continue
2820+
2821+
27832822
@with_ansi_style(ru.AllowStyle.ALWAYS)
27842823
def test_perror_style(base_app, capsys) -> None:
27852824
msg = 'testing...'

0 commit comments

Comments
 (0)