Пример #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)
Пример #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')
Пример #3
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'])
Пример #4
0
 def test_execute_cmd_start(self):
     with mock_patch.object(Thread, 'start') as start_mock:
         execute_cmd('ls', '/tmp')
         start_mock.assert_called_once()