Beispiel #1
0
 def test_on_command_just_print_error_message_when_invalid_command(
         self, mock_print):
     simulator = Simulator()
     simulator.command_list = [
         {
             "guide": "h, help          print command info",
             "cmd": ["help", "h"],
             "need_value": False,
         },
     ]
     simulator.execute_command = MagicMock()
     simulator.on_command("hell")
     simulator.execute_command.assert_not_called()
     mock_print.assert_called_once_with("invalid command")
Beispiel #2
0
 def test_on_command_call_action_correclty(self):
     simulator = Simulator()
     simulator.command_list = [
         {
             "guide": "h, help          print command info",
             "cmd": ["help", "h"],
             "action": MagicMock(),
         },
         {
             "guide": "c, count         set simulation count",
             "cmd": ["count", "c"],
             "action": MagicMock(),
         },
         {
             "guide": "i, interval         set simulation interval",
             "cmd": ["interval", "i"],
             "action": MagicMock(),
         },
     ]
     simulator.on_command("h")
     simulator.on_command("coun")
     simulator.command_list[0]["action"].assert_called_once()
     simulator.command_list[1]["action"].assert_not_called()
     simulator.on_command("iNTERval")
     simulator.command_list[2]["action"].assert_called_once()