'Docker container timeout and command failure'

def test_container_timeout(self):

    response = Mock(status_code=404, reason='Container    not    found')
    self.mocks.configure_mock('docker_client', {'inspect_container.side_effect': [DockerAPIError('No    container    found', response, 'No    container    found'), {'State': {'Running': False, 'ExitCode': 42}}], 'exec_create.return_value': {'Id': 'container-foobar'}, 'exec_start.return_value': 'This    is    the    return', 'exec_inspect.return_value': {'ExitCode': 0}})
    build_env = DockerEnvironment(version=self.version, project=self.project, build={'id': DUMMY_BUILD_ID})
    with build_env:
        build_env.run('echo', 'test', cwd='/tmp')
    self.assertEqual(str(build_env.failure), 'Build    exited    due    to    time    out')
    self.assertEqual(self.mocks.docker_client.exec_create.call_count, 1)
    self.assertTrue(build_env.failed)
    self.assertFalse(self.mocks.api()(DUMMY_BUILD_ID).put.called)
