Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 6
0
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
Esempio n. 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)
Esempio n. 8
0
 def test_communicate_with_completed_process(self):
     sh(COMMAND)()
     self.process.communicate.assert_called_once_with()
Esempio n. 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)
Esempio n. 10
0
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
Esempio n. 11
0
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
Esempio n. 12
0
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
Esempio n. 13
0
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
Esempio n. 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()
Esempio n. 15
0
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
Esempio n. 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()
Esempio n. 17
0
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
Esempio n. 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)
Esempio n. 19
0
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
Esempio n. 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)
Esempio n. 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)
Esempio n. 22
0
    def test_calling_command_without_timeout_does_not_poll(self):
        sh(COMMAND, timeout=None)()

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

        assert_false(self.process.poll.called)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 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)