diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-05-21 16:32:35 -0400 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2012-05-21 16:32:35 -0400 |
commit | 471704df644eced17026c280b0aab9e549718e14 (patch) | |
tree | c2d8d0ec74fa45e0b61ca4b2153fb5b0e7bf490d /tests/v1/utils.py | |
download | python-cinderclient-0.0.tar.gz |
Initial split from python-novaclient.0.0
Diffstat (limited to 'tests/v1/utils.py')
-rw-r--r-- | tests/v1/utils.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/v1/utils.py b/tests/v1/utils.py new file mode 100644 index 0000000..f878a5e --- /dev/null +++ b/tests/v1/utils.py @@ -0,0 +1,29 @@ +from nose.tools import ok_ + + +def fail(msg): + raise AssertionError(msg) + + +def assert_in(thing, seq, msg=None): + msg = msg or "'%s' not found in %s" % (thing, seq) + ok_(thing in seq, msg) + + +def assert_not_in(thing, seq, msg=None): + msg = msg or "unexpected '%s' found in %s" % (thing, seq) + ok_(thing not in seq, msg) + + +def assert_has_keys(dict, required=[], optional=[]): + keys = dict.keys() + for k in required: + assert_in(k, keys, "required key %s missing from %s" % (k, dict)) + allowed_keys = set(required) | set(optional) + extra_keys = set(keys).difference(set(required + optional)) + if extra_keys: + fail("found unexpected keys: %s" % list(extra_keys)) + + +def assert_isinstance(thing, kls): + ok_(isinstance(thing, kls), "%s is not an instance of %s" % (thing, kls)) |