Beispiel #1
0
    def test_does_not_raise_exception_if_poll_eventually_succeed(self):
        self.process.poll.side_effect = [None, 0]

        wait_step = 0.1
        sh(COMMAND, timeout=10.0, wait_step=wait_step)()

        self.mock_time.sleep.assert_called_with(wait_step)
Beispiel #2
0
    def test_does_not_raise_exception_if_poll_eventually_succeed(self):
        self.process.poll.side_effect = [None, 0]

        wait_step = 0.1
        sh(COMMAND, timeout=10.0, wait_step=wait_step)()

        self.mock_time.sleep.assert_called_with(wait_step)
Beispiel #3
0
    def test_command_errors_are_logged(self, mock_logging):
        mock_logger = Mock()
        mock_logging.getLogger.return_value = mock_logger
        self.process.communicate.return_value = (STDOUT, STDERR)

        sh(COMMAND)()
        mock_logger.warn.assert_called_once_with(ANY)
Beispiel #4
0
    def test_command_errors_are_logged(self, mock_logging):
        mock_logger = Mock()
        mock_logging.getLogger.return_value = mock_logger
        self.process.communicate.return_value = ('', STDERR)

        sh(COMMAND)()
        mock_logger.warn.assert_called_once_with(ANY)
Beispiel #5
0
 def test_function_runs_command_when_called(self):
     sh(COMMAND)()
     command = self.mock_popen.call_args[0][0]
     assert_equal(command, COMMAND)
     self.process.communicate.assert_called_once_with()
Beispiel #6
0
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
Beispiel #7
0
    def test_raises_exception_if_command_does_not_produce_output(self):
        self.process.communicate.return_value = ('', '')

        f = sh(COMMAND)
        assert_raises(OperatingSystemError, f)
Beispiel #8
0
 def test_communicate_with_completed_process(self):
     sh(COMMAND)()
     self.process.communicate.assert_called_once_with()
Beispiel #9
0
    def test_raises_exception_if_poll_never_succeed(self):
        self.process.poll.return_value = None

        command = sh(COMMAND, timeout=10.0)
        assert_raises(OperatingSystemError, command)
Beispiel #10
0
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
Beispiel #11
0
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
Beispiel #12
0
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
Beispiel #13
0
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
Beispiel #14
0
 def test_function_runs_command_when_called(self):
     sh(COMMAND)()
     command = self.mock_popen.call_args[0][0]
     assert_equal(command, COMMAND)
     self.process.communicate.assert_called_once_with()
Beispiel #15
0
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
Beispiel #16
0
 def test_communicate_with_timed_out_process(self):
     self.process.poll.return_value = None
     command = sh(COMMAND, timeout=10.0)
     assert_raises(OperatingSystemError, command)
     self.process.communicate.assert_called_once_with()
Beispiel #17
0
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
Beispiel #18
0
 def test_function_inserts_arguments_into_command(self):
     sh(COMMAND_WITH_ARGUMENTS)(ARGUMENT)
     command = self.mock_popen.call_args[0][0]
     assert_in(ARGUMENT, command)
Beispiel #19
0
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
Beispiel #20
0
 def test_function_inserts_arguments_into_command(self):
     sh(COMMAND_WITH_ARGUMENTS)(ARGUMENT)
     command = self.mock_popen.call_args[0][0]
     assert_in(ARGUMENT, command)
Beispiel #21
0
    def test_raises_exception_if_command_does_not_produce_output(self):
        self.process.communicate.return_value = ('', '')

        f = sh(COMMAND)
        assert_raises(OperatingSystemError, f)
Beispiel #22
0
    def test_calling_command_without_timeout_does_not_poll(self):
        sh(COMMAND, timeout=None)()

        assert_false(self.process.poll.called)
Beispiel #23
0
 def test_communicate_with_completed_process(self):
     sh(COMMAND)()
     self.process.communicate.assert_called_once_with()
Beispiel #24
0
    def test_calling_command_without_timeout_does_not_poll(self):
        sh(COMMAND, timeout=None)()

        assert_false(self.process.poll.called)
Beispiel #25
0
    def test_raises_exception_if_command_produces_errors(self):
        self.process.communicate.return_value = (STDOUT, STDERR)

        f = sh(COMMAND, raise_on_nonempty_err=True)
        assert_raises(OperatingSystemError, f)
Beispiel #26
0
    def test_raises_exception_if_command_produces_errors(self):
        self.process.communicate.return_value = (STDOUT, STDERR)

        f = sh(COMMAND, raise_on_nonempty_err=True)
        assert_raises(OperatingSystemError, f)
Beispiel #27
0
    def test_raises_exception_if_poll_never_succeed(self):
        self.process.poll.return_value = None

        command = sh(COMMAND, timeout=10.0)
        assert_raises(OperatingSystemError, command)
Beispiel #28
0
 def test_communicate_with_timed_out_process(self):
     self.process.poll.return_value = None
     command = sh(COMMAND, timeout=10.0)
     assert_raises(OperatingSystemError, command)
     self.process.communicate.assert_called_once_with()
Beispiel #29
0
 def test_result_is_equal_to_coreutils_md5sum(self):
     coreutils_md5sum = sh('md5sum {0}')(self.FILE_PATH).split()[0]
     zabby_md5sum = file.md5sum(self.FILE_PATH)
     assert_equal(coreutils_md5sum, zabby_md5sum)