summaryrefslogtreecommitdiffstats
path: root/nova/test.py
diff options
context:
space:
mode:
authorDan Prince <dan.prince@rackspace.com>2011-05-26 09:05:14 -0400
committerDan Prince <dan.prince@rackspace.com>2011-05-26 09:05:14 -0400
commita021b43b7d45f8cc803721002a0b2e7d9ea9a06d (patch)
tree6c3f6274d91a511a04a322a46d8678f4ad18d71a /nova/test.py
parent9d2513ea3a6d586e1fe3deae778a02bb089b9a5e (diff)
parentdb18a792414240cbdb1221d0e79e8a63313f103e (diff)
downloadnova-a021b43b7d45f8cc803721002a0b2e7d9ea9a06d.tar.gz
nova-a021b43b7d45f8cc803721002a0b2e7d9ea9a06d.tar.xz
nova-a021b43b7d45f8cc803721002a0b2e7d9ea9a06d.zip
Merge w/ trunk.
Diffstat (limited to 'nova/test.py')
-rw-r--r--nova/test.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/nova/test.py b/nova/test.py
index 3b608520a..4deb2a175 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -16,12 +16,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""
-Base classes for our unit tests.
-Allows overriding of flags for use of fakes,
-and some black magic for inline callbacks.
-"""
+"""Base classes for our unit tests.
+Allows overriding of flags for use of fakes, and some black magic for
+inline callbacks.
+
+"""
import datetime
import functools
@@ -52,9 +52,9 @@ flags.DEFINE_bool('fake_tests', True,
def skip_if_fake(func):
- """Decorator that skips a test if running in fake mode"""
+ """Decorator that skips a test if running in fake mode."""
def _skipper(*args, **kw):
- """Wrapped skipper function"""
+ """Wrapped skipper function."""
if FLAGS.fake_tests:
raise unittest.SkipTest('Test cannot be run in fake mode')
else:
@@ -63,9 +63,10 @@ def skip_if_fake(func):
class TestCase(unittest.TestCase):
- """Test case base class for all unit tests"""
+ """Test case base class for all unit tests."""
+
def setUp(self):
- """Run before each test method to initialize test environment"""
+ """Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
# NOTE(vish): We need a better method for creating fixtures for tests
# now that we have some required db setup for the system
@@ -86,8 +87,7 @@ class TestCase(unittest.TestCase):
self._original_flags = FLAGS.FlagValuesDict()
def tearDown(self):
- """Runs after each test method to finalize/tear down test
- environment."""
+ """Runs after each test method to tear down test environment."""
try:
self.mox.UnsetStubs()
self.stubs.UnsetAll()
@@ -121,7 +121,7 @@ class TestCase(unittest.TestCase):
pass
def flags(self, **kw):
- """Override flag variables for a test"""
+ """Override flag variables for a test."""
for k, v in kw.iteritems():
if k in self.flag_overrides:
self.reset_flags()
@@ -131,7 +131,11 @@ class TestCase(unittest.TestCase):
setattr(FLAGS, k, v)
def reset_flags(self):
- """Resets all flag variables for the test. Runs after each test"""
+ """Resets all flag variables for the test.
+
+ Runs after each test.
+
+ """
FLAGS.Reset()
for k, v in self._original_flags.iteritems():
setattr(FLAGS, k, v)
@@ -158,7 +162,6 @@ class TestCase(unittest.TestCase):
def _monkey_patch_wsgi(self):
"""Allow us to kill servers spawned by wsgi.Server."""
- # TODO(termie): change these patterns to use functools
self.original_start = wsgi.Server.start
@functools.wraps(self.original_start)
@@ -189,12 +192,13 @@ class TestCase(unittest.TestCase):
If you don't care (or don't know) a given value, you can specify
the string DONTCARE as the value. This will cause that dict-item
to be skipped.
+
"""
def raise_assertion(msg):
d1str = str(d1)
d2str = str(d2)
- base_msg = ("Dictionaries do not match. %(msg)s d1: %(d1str)s "
- "d2: %(d2str)s" % locals())
+ base_msg = ('Dictionaries do not match. %(msg)s d1: %(d1str)s '
+ 'd2: %(d2str)s' % locals())
raise AssertionError(base_msg)
d1keys = set(d1.keys())
@@ -202,8 +206,8 @@ class TestCase(unittest.TestCase):
if d1keys != d2keys:
d1only = d1keys - d2keys
d2only = d2keys - d1keys
- raise_assertion("Keys in d1 and not d2: %(d1only)s. "
- "Keys in d2 and not d1: %(d2only)s" % locals())
+ raise_assertion('Keys in d1 and not d2: %(d1only)s. '
+ 'Keys in d2 and not d1: %(d2only)s' % locals())
for key in d1keys:
d1value = d1[key]
@@ -217,19 +221,19 @@ class TestCase(unittest.TestCase):
"d2['%(key)s']=%(d2value)s" % locals())
def assertDictListMatch(self, L1, L2):
- """Assert a list of dicts are equivalent"""
+ """Assert a list of dicts are equivalent."""
def raise_assertion(msg):
L1str = str(L1)
L2str = str(L2)
- base_msg = ("List of dictionaries do not match: %(msg)s "
- "L1: %(L1str)s L2: %(L2str)s" % locals())
+ base_msg = ('List of dictionaries do not match: %(msg)s '
+ 'L1: %(L1str)s L2: %(L2str)s' % locals())
raise AssertionError(base_msg)
L1count = len(L1)
L2count = len(L2)
if L1count != L2count:
- raise_assertion("Length mismatch: len(L1)=%(L1count)d != "
- "len(L2)=%(L2count)d" % locals())
+ raise_assertion('Length mismatch: len(L1)=%(L1count)d != '
+ 'len(L2)=%(L2count)d' % locals())
for d1, d2 in zip(L1, L2):
self.assertDictMatch(d1, d2)