Skip to content

Commit

Permalink
add little test for history feature
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Nov 25, 2023
1 parent 96fad04 commit ebab42a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/config/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from unittest import TestCase

from prompt_toolkit.history import InMemoryHistory
from tmtccmd.config.prompt import prompt_cmd_path
from tmtccmd.config.tmtc import CmdTreeNode
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -36,7 +38,7 @@ def test_prompt_cmd_path_full_print(self, mocked_print: MagicMock):
self.assertEqual(len(call_list), 2)
help_txt = mocked_print.call_args_list[0].args[0]
self.assertTrue("Additional commands for prompt:" in help_txt)
self.assertTrue(":p[b][<depth>] Tree Print" in help_txt)
self.assertTrue(":p[b][f][<depth>] Tree Print" in help_txt)
self.assertTrue(":r Retry" in help_txt)
self.assertTrue(":h Help Text" in help_txt)
printout = mocked_print.call_args_list[1].args[0]
Expand Down Expand Up @@ -83,8 +85,19 @@ def test_prompt_help_reprint(self, mocked_print: MagicMock):
self.assertEqual(len(call_list), 2)
help_txt = mocked_print.call_args_list[0].args[0]
self.assertTrue("Additional commands for prompt:" in help_txt)
self.assertTrue(":p[b][<depth>] Tree Print" in help_txt)
self.assertTrue(":p[b][f][<depth>] Tree Print" in help_txt)
self.assertTrue(":r Retry" in help_txt)
self.assertTrue(":h Help Text" in help_txt)
help_txt_2 = mocked_print.call_args_list[1].args[0]
self.assertEqual(help_txt, help_txt_2)

def test_cmd_history(self):
self.base_tree()
history = InMemoryHistory()
history.append_string("test")
with patch(
"tmtccmd.config.prompt.prompt_toolkit.prompt", side_effect=["ping"]
) as prompt:
cmd_path = prompt_cmd_path(self.cmd_tree, history=history)
self.assertEqual(len(prompt.call_args_list), 1)
self.assertEqual(cmd_path, "/ping")

0 comments on commit ebab42a

Please sign in to comment.