def test_execute_with_pty(self): execute = Execute('python3 ./helpers/listprint.py 5 test test2', shell=True, use_pty=True) t = Thread(target=execute.run) t.start() sleep(0.3) self.assertTrue(execute.output())
def test_poll_process(self): execute = Execute(['echo']) self.assertEqual(-1, execute.poll()) # process never started execute.process = Mock() execute.process.poll.return_value = None self.assertEqual(None, execute.poll()) # process still running execute.process.poll.return_value = 0 self.assertEqual(0, execute.poll()) # process finished
def test_kill_running_process(self): execute = Execute(['tail', '-f', '/dev/null']) t = Thread(target=execute.run) t.start() while execute.process is None: sleep(0.1) self.assertTrue(execute.poll() == None) execute.kill() self.assertTrue(execute.poll())
def test_parser_is_called_to_generate_output(self): parser = Mock() execute = Execute(['echo', 'test'], parser) execute.run() parser.parse.assert_called_with('test\n')
def test_kill_unstarted_process(self): execute = Execute(['echo']) self.assertTrue(execute.kill() == None)
def test_execute_without_pty(self): execute = Execute(['echo', 'helpers']) execute.run() self.assertTrue('helpers' in str(execute.output()))
def test_create_execute_object_with_pty_enabled(self): execute = Execute(['echo'], use_pty=True) self.assertTrue(execute.use_pty)
def test_non_EIO_raises_exception(self, mock_os): execute = Execute(['echo'], use_pty=True) mock_os.read.side_effect = IOError("test") with self.assertRaises(IOError): execute.run()
def test_EIO_do_not_raise_exception(self, mock_os): execute = Execute(['echo'], use_pty=True) mock_os.read.side_effect = IOError(EIO, None) execute.run() self.assertTrue(mock_os.read.called)
def test_exit_process_when_no_more_output_is_generated(self, mock_os): mock_os.read.return_value = "" execute = Execute(['echo'], use_pty=True) execute.run() self.assertTrue(mock_os.close.called) self.assertNotEqual(None, execute.poll())
def test_create_default_execute_object(self): execute = Execute(['echo']) self.assertEqual(['echo'], execute.command) self.assertTrue(execute.output_parser) self.assertFalse(execute.shell) self.assertFalse(execute.use_pty)
def test_create_execute_object_with_shell_enabled(self): execute = Execute('echo', shell=True) self.assertEqual('echo', execute.command) self.assertTrue(execute.shell)