~ubuntu-branches/ubuntu/saucy/python-cinderclient/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/v1/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-27 13:32:14 UTC
  • Revision ID: package-import@ubuntu.com-20120627133214-n2gx1yxu97efvhg8
Tags: upstream-2012.2~f1~20120621.8
ImportĀ upstreamĀ versionĀ 2012.2~f1~20120621.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from nose.tools import ok_
 
2
 
 
3
 
 
4
def fail(msg):
 
5
    raise AssertionError(msg)
 
6
 
 
7
 
 
8
def assert_in(thing, seq, msg=None):
 
9
    msg = msg or "'%s' not found in %s" % (thing, seq)
 
10
    ok_(thing in seq, msg)
 
11
 
 
12
 
 
13
def assert_not_in(thing, seq, msg=None):
 
14
    msg = msg or "unexpected '%s' found in %s" % (thing, seq)
 
15
    ok_(thing not in seq, msg)
 
16
 
 
17
 
 
18
def assert_has_keys(dict, required=[], optional=[]):
 
19
    keys = dict.keys()
 
20
    for k in required:
 
21
        assert_in(k, keys, "required key %s missing from %s" % (k, dict))
 
22
    allowed_keys = set(required) | set(optional)
 
23
    extra_keys = set(keys).difference(set(required + optional))
 
24
    if extra_keys:
 
25
        fail("found unexpected keys: %s" % list(extra_keys))
 
26
 
 
27
 
 
28
def assert_isinstance(thing, kls):
 
29
    ok_(isinstance(thing, kls), "%s is not an instance of %s" % (thing, kls))