Remove mox from unit/compute/test_compute.py (8)

Introduce test.ContainKeyValue for replacing mox.ContainKeyValue

Stop using mox in test_compute.py in below test cases:
- test_lifecycle_events
- test_allow_confirm_resize_on_instance_in_deleting_task_state
- test_default_block_device_names_empty_instance_root_dev
- test_default_block_device_names_empty_root_device
- test_default_block_device_names_no_root_device
- test_vnc_console

Partially implements: blueprint remove-mox-newton
Change-Id: I22b97e05a130ac65bd4b7412aac1b5e95f41b614
This commit is contained in:
Hieu LE 2016-06-17 16:10:51 +07:00
parent aa8ffa3f6c
commit 9f4e21b724

View File

@ -454,3 +454,42 @@ class MatchType(object):
def __repr__(self):
return "<MatchType:" + str(self.wanttype) + ">"
class ContainKeyValue(object):
"""Checks whether a key/value pair is in a dict parameter.
The ContainKeyValue class is a helper for use with the
mock.assert_*() method that lets you assert that a particular
dict contain a key/value paire. It enables strict check than
the built in mock.ANY helper, and is the equivalent of the
mox.ContainsKeyValue() function from the legacy mox library
Example usage could be:
mock_some_method.assert_called_once_with(
"hello",
ContainKeyValue('foo', bar),
mock.ANY,
"world",
ContainKeyValue('hello', world))
"""
def __init__(self, wantkey, wantvalue):
self.wantkey = wantkey
self.wantvalue = wantvalue
def __eq__(self, other):
try:
return other[self.wantkey] == self.wantvalue
except (KeyError, TypeError):
return False
def __ne__(self, other):
try:
return other[self.wantkey] != self.wantvalue
except (KeyError, TypeError):
return True
def __repr__(self):
return "<ContainKeyValue: key " + str(self.wantkey) + \
" and value " + str(self.wantvalue) + ">"