示例#1
0
文件: test_utils.py 项目: blin/zabby
    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)
示例#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)
示例#3
0
文件: test_utils.py 项目: blin/zabby
    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)
示例#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)
示例#5
0
文件: test_utils.py 项目: blin/zabby
 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()
示例#6
0
文件: test_utils.py 项目: blin/zabby
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
示例#7
0
文件: test_utils.py 项目: blin/zabby
    def test_raises_exception_if_command_does_not_produce_output(self):
        self.process.communicate.return_value = ('', '')

        f = sh(COMMAND)
        assert_raises(OperatingSystemError, f)
示例#8
0
文件: test_utils.py 项目: blin/zabby
 def test_communicate_with_completed_process(self):
     sh(COMMAND)()
     self.process.communicate.assert_called_once_with()
示例#9
0
文件: test_utils.py 项目: blin/zabby
    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)
示例#10
0
文件: test_utils.py 项目: blin/zabby
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
示例#11
0
文件: test_utils.py 项目: blin/zabby
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
示例#12
0
 def test_function_accepts_arguments(self):
     sh(COMMAND)(ARGUMENT)
示例#13
0
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
示例#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()
示例#15
0
 def test_returns_a_function(self):
     f = sh(COMMAND)
     assert_is_instance(f, FunctionType)
示例#16
0
文件: test_utils.py 项目: blin/zabby
 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()
示例#17
0
文件: test_utils.py 项目: blin/zabby
 def test_command_output_is_returned(self):
     result = sh(COMMAND)()
     assert_true(not result.endswith('\n'))
     assert_in(result, STDOUT)
示例#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)
示例#19
0
 def test_calling_command_that_accepts_arguments_without_them(self):
     f = sh(COMMAND_WITH_ARGUMENTS)
     assert_raises(WrongArgumentError, f)
示例#20
0
文件: test_utils.py 项目: blin/zabby
 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)
示例#21
0
文件: test_utils.py 项目: blin/zabby
    def test_raises_exception_if_command_does_not_produce_output(self):
        self.process.communicate.return_value = ('', '')

        f = sh(COMMAND)
        assert_raises(OperatingSystemError, f)
示例#22
0
文件: test_utils.py 项目: blin/zabby
    def test_calling_command_without_timeout_does_not_poll(self):
        sh(COMMAND, timeout=None)()

        assert_false(self.process.poll.called)
示例#23
0
文件: test_utils.py 项目: blin/zabby
 def test_communicate_with_completed_process(self):
     sh(COMMAND)()
     self.process.communicate.assert_called_once_with()
示例#24
0
    def test_calling_command_without_timeout_does_not_poll(self):
        sh(COMMAND, timeout=None)()

        assert_false(self.process.poll.called)
示例#25
0
文件: test_utils.py 项目: blin/zabby
    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)
示例#26
0
文件: test_utils.py 项目: blin/zabby
    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)
示例#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)
示例#28
0
文件: test_utils.py 项目: blin/zabby
 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()
示例#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)