Exemplo n.º 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())
Exemplo n.º 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
Exemplo n.º 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())
Exemplo n.º 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
Exemplo n.º 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())
Exemplo n.º 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')
Exemplo n.º 7
0
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
Exemplo n.º 8
0
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
Exemplo n.º 9
0
 def test_create_execute_object_with_pty_enabled(self):
     execute = Execute(['echo'], use_pty=True)
     self.assertTrue(execute.use_pty)
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 14
0
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
Exemplo n.º 15
0
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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)