~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/test.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-06-22 12:39:57 UTC
  • mfrom: (1.1.57)
  • Revision ID: package-import@ubuntu.com-20120622123957-hbzwg84nt9rqwg8r
Tags: 2012.2~f2~20120621.14517-0ubuntu1
[ Chuck Short ]
* New upstream version.

[ Adam Gandelman ]
* debian/rules: Temporarily disable test suite while blocking
  tests are investigated. 
* debian/patches/kombu_tests_timeout.patch: Dropped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
 
26
26
import functools
27
 
import os
28
 
import shutil
29
27
import unittest
30
28
import uuid
31
29
 
37
35
import nova.image.fake
38
36
from nova import log as logging
39
37
from nova.openstack.common import cfg
 
38
from nova.openstack.common import timeutils
40
39
from nova import service
41
40
from nova import tests
42
41
from nova.tests import fake_flags
43
 
from nova import utils
44
42
from nova.virt import fake
45
43
 
46
44
 
133
131
        # NOTE(vish): We need a better method for creating fixtures for tests
134
132
        #             now that we have some required db setup for the system
135
133
        #             to work properly.
136
 
        self.start = utils.utcnow()
 
134
        self.start = timeutils.utcnow()
137
135
        tests.reset_db()
138
136
 
139
137
        # emulate some of the mox stuff, we can't use the metaclass
152
150
            self.mox.VerifyAll()
153
151
            super(TestCase, self).tearDown()
154
152
        finally:
155
 
            if FLAGS.connection_type == 'fake':
156
 
                if hasattr(fake.FakeConnection, '_instance'):
157
 
                    del fake.FakeConnection._instance
158
 
 
159
153
            if FLAGS.image_service == 'nova.image.fake.FakeImageService':
160
154
                nova.image.fake.FakeImageService_reset()
161
155
 
295
289
            self.assertFalse(a in b, *args, **kwargs)
296
290
        else:
297
291
            f(a, b, *args, **kwargs)
 
292
 
 
293
    def assertNotRaises(self, exc_class, func, *args, **kwargs):
 
294
        """Assert that a particular exception is not raised.
 
295
 
 
296
        If exc_class is None, then we assert that *no* error is raised.
 
297
 
 
298
        Otherwise, we assert that only a particular error wasn't raised;
 
299
        if any different exceptions were raised, we just silently capture
 
300
        them and return.
 
301
        """
 
302
        exc_msg = kwargs.pop('exc_msg', '')
 
303
 
 
304
        if exc_class is None:
 
305
            # Ensure no errors were raised
 
306
            try:
 
307
                return func(*args, **kwargs)
 
308
            except Exception:
 
309
                raise
 
310
                raise AssertionError(exc_msg)
 
311
        else:
 
312
            # Ensure a specific error wasn't raised
 
313
            try:
 
314
                return func(*args, **kwargs)
 
315
            except exc_class:
 
316
                raise AssertionError(exc_msg)
 
317
            except Exception:
 
318
                pass  # Any other errors are fine
 
319
 
 
320
    def assertIsInstance(self, a, b, *args, **kwargs):
 
321
        """Python < v2.7 compatibility.  Assert 'a' is Instance of 'b'"""
 
322
        try:
 
323
            f = super(TestCase, self).assertIsInstance
 
324
        except AttributeError:
 
325
            self.assertTrue(isinstance(a, b), *args, **kwargs)
 
326
        else:
 
327
            f(a, b, *args, **kwargs)