Ejemplo n.º 1
0
    def test_timeout(self, m):
        def side_effect(timeout=None):
            raise subprocess.TimeoutExpired('', timeout)

        process_mock = Mock()
        process_mock.configure_mock(**{'wait.side_effect': side_effect})
        m.return_value = process_mock
        self.assertEqual(execute_cmd(['ls']), None)
Ejemplo n.º 2
0
 def test_success(self, m):
     process_mock = Mock()
     process_mock.configure_mock(**{
         'returncode': 0,
         'stdout': io_out('foo')
     })
     m.return_value = process_mock
     out = execute_cmd(['ls'])
     self.assertEqual(out[0], 'foo')
Ejemplo n.º 3
0
    def test_check_execution_success(self, popen_mock):
        popen_mock.return_value = Mock()
        popen_mock_obj = popen_mock.return_value

        popen_mock_obj.communicate.return_value = ("OUT", "ERR")
        popen_mock_obj.returncode = 1
        with mock_patch.object(logger, 'error') as logger_error:
            check_execution_success('ls', '/tmp')
            logger_error.assert_called_once()
Ejemplo n.º 4
0
 def test_error(self, m):
     process_mock = Mock()
     process_mock.configure_mock(**{'returncode': 1})
     m.return_value = process_mock
     with self.assertRaises(ExecuteError):
         execute_cmd(['ls'])