Beispiel #1
0
 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())
Beispiel #2
0
 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
Beispiel #3
0
 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())
Beispiel #4
0
 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
Beispiel #5
0
 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())
Beispiel #6
0
 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')
Beispiel #7
0
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
Beispiel #8
0
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
Beispiel #9
0
 def test_create_execute_object_with_pty_enabled(self):
     execute = Execute(['echo'], use_pty=True)
     self.assertTrue(execute.use_pty)
Beispiel #10
0
 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()
Beispiel #11
0
 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()
Beispiel #12
0
 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)
Beispiel #13
0
 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')
Beispiel #14
0
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
Beispiel #15
0
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
Beispiel #16
0
 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())
Beispiel #17
0
 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)
Beispiel #18
0
 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)
Beispiel #19
0
 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())
Beispiel #20
0
 def test_create_execute_object_with_shell_enabled(self):
     execute = Execute('echo', shell=True)
     self.assertEqual('echo', execute.command)
     self.assertTrue(execute.shell)