Exemplo n.º 1
0
 def test_exit_command_drops_connection(self):
     sp = base.get_shell_protocol()
     sp.lineReceived("exit")
     self.assertTrue(
         sp.terminal.disconnecting,
         "Shell did not call terminal.loseConnection()"
     )
Exemplo n.º 2
0
 def test_lineReceived_without_args(self):
     sp = base.get_shell_protocol()
     # disable running commands in the stack, so we can inspect it
     sp.resume = lambda x: None
     sp.lineReceived("command")
     command = sp.cmd_stack[0][0]
     name = command['name']
     self.assertEqual(name, 'command')
Exemplo n.º 3
0
 def test_get_command_returns_command_not_found(self):
     sp = base.get_shell_protocol()
     sp.lineReceived("not_a_command arg0")
     #sp.get_executable(sp.cmd_stack.pop())
     self.assertEqual(
         sp.terminal.value(),
         "StubShell: not_a_command: command not found\n"
         + PROMPT
     )
     self.assertEqual(sp.RET, 127)
Exemplo n.º 4
0
 def test_lineReceived_with_args(self):
     sp = base.get_shell_protocol()
     sp.resume = lambda x: None 
     sp.lineReceived("command arg0 arg1")
     command = sp.cmd_stack[0][0]
     name = command['name']
     args = command['args']
     self.assertEqual(name, 'command')
     self.assertEqual(args[0], 'arg0')
     self.assertEqual(args[1], 'arg1')
Exemplo n.º 5
0
 def test_multiple_command_line(self):
     sp = base.get_shell_protocol()
     sp.resume = lambda x: None
     sp.lineReceived("command0 arg0; command1 arg1.0 arg1.1")
     cmd_list = sp.cmd_stack[0]
     cmd2 = cmd_list[1]
     name = cmd2['name']
     args = cmd2['args']
     self.assertEqual(name, 'command1')
     self.assertEqual(args[0], 'arg1.0')
     self.assertEqual(args[1], 'arg1.1')
Exemplo n.º 6
0
 def test_execute_multiple_commands(self):
     sp = base.get_shell_protocol()
     sp.lineReceived(
         "test_command; "
         "test_args a1 a2; "
         "rexeisawesome;"
     )
     self.assertEqual(
         sp.terminal.value(),
         "pass!\n"
         "my args are: a1, a2\n"
         "rexeisawesome executed rexe\n"
         + PROMPT
     )
Exemplo n.º 7
0
 def test_received_new_input_while_running(self):
     sp = base.get_shell_protocol()
     sp.lineReceived(
         "test_command; "
         "test_args a1 a2; "
     )
     sp.lineReceived(
         "test_command; "
         "test_args b1 b2; "
     )
     self.assertEqual(
         sp.terminal.value(),
         "pass!\n"
         "my args are: a1, a2\n"
         + PROMPT +
         "pass!\n"
         "my args are: b1, b2\n"
         + PROMPT
     )
Exemplo n.º 8
0
    def test_timed_executable(self):

        class exe_timed(BaseExecutables.TimedExe):
            name = "wait"
            first_print = "Begin Waiting:"
            final_print = "Waiting Complete"


        sp = base.get_shell_protocol()
        clock = task.Clock()
        exe = exe_timed(
            {'name': 'wait', 'args':[]},
            {}, # standin for match
            sp,
            reactor=clock
        )

        exe.run()
        # first we print the first_print line
        self.assertEqual(
            sp.terminal.value(),
            "Begin Waiting:\n"
        )
        sp.terminal.clear()
        clock.advance(1)
        # then we see the output from print_timed_output
        # count times
        for _ in range(3):
            self.assertEqual(
                sp.terminal.value(),
                "waiting...\n"
            )
            sp.terminal.clear()
            clock.advance(1)
        # finally we see the final_print line, and prompt
        self.assertEqual(
            sp.terminal.value(),
            "Waiting Complete\n" + PROMPT
        )
Exemplo n.º 9
0
 def test_get_executable_regex_captures(self):
     sp = base.get_shell_protocol()
     cmd = {'name': 'rexe123', 'args':[]}
     exe = sp.get_executable(cmd)
     self.assertEqual(exe.match.group(1), '123') 
Exemplo n.º 10
0
 def test_get_executable_regex(self):
     sp = base.get_shell_protocol()
     cmd = {'name':'rexe_something', 'args':['arg0']}
     exe = sp.get_executable(cmd)
     self.assertIsInstance(exe, base.exe_rexe)
Exemplo n.º 11
0
 def test_get_executable(self):
     sp = base.get_shell_protocol()
     cmd = {'name':'test_command', 'args':['arg0']}
     exe = sp.get_executable(cmd)
     self.assertIsInstance(exe, base.exe_test_command)
     self.assertEqual(exe.args[0], "arg0")
Exemplo n.º 12
0
 def test_exe_exit_in_shell_executables_by_default(self):
     sp = base.get_shell_protocol()
     self.assertIn(StubShell.exe_exit, sp.executables)
Exemplo n.º 13
0
 def setUp(self):
     self.sp = base.get_shell_protocol()
Exemplo n.º 14
0
 def test_Executable_can_call_containing_shell(self):
     sp = base.get_shell_protocol()
     cmd = {'name':'test', 'args':[]}
     exe = Executable(cmd, {}, sp)
     exe.shell.writeln("pass")
     self.assertEqual(sp.terminal.value(), "pass\n")