コード例 #1
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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())
コード例 #2
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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
コード例 #3
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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())
コード例 #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
コード例 #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())
コード例 #6
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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')
コード例 #7
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
コード例 #8
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
コード例 #9
0
 def test_create_execute_object_with_pty_enabled(self):
     execute = Execute(['echo'], use_pty=True)
     self.assertTrue(execute.use_pty)
コード例 #10
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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()
コード例 #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()
コード例 #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)
コード例 #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')
コード例 #14
0
 def test_kill_unstarted_process(self):
     execute = Execute(['echo'])
     self.assertTrue(execute.kill() == None)
コード例 #15
0
 def test_execute_without_pty(self):
     execute = Execute(['echo', 'helpers'])
     execute.run()
     self.assertTrue('helpers' in str(execute.output()))
コード例 #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())
コード例 #17
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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)
コード例 #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)
コード例 #19
0
ファイル: test_runcommand.py プロジェクト: OkWilk/disk-image
 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())
コード例 #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)