Merge "Fix ItemMatcher to avoid false positives"
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import platform
|
import platform
|
||||||
import socket
|
import socket
|
||||||
@@ -322,22 +323,20 @@ class ItemsMatcher(CustomMockCallMatcher):
|
|||||||
|
|
||||||
But the following will fail::
|
But the following will fail::
|
||||||
my_mock(..., listy_kwarg=['foo', 'bar'], ...)
|
my_mock(..., listy_kwarg=['foo', 'bar'], ...)
|
||||||
|
|
||||||
.. todo:: Because we internally use set()s, the following will **pass**,
|
|
||||||
but it shouldn't::
|
|
||||||
|
|
||||||
# Duplicated item
|
|
||||||
my_mock(..., listy_kwarg=['foo', 'foo', 'bar', 'baz'], ...)
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, iterable):
|
def __init__(self, iterable):
|
||||||
self.items = set(iterable)
|
# NOTE(gibi): we need the extra iter() call as Counter handles dicts
|
||||||
|
# directly to initialize item count. However if a dict passed to
|
||||||
|
# ItemMatcher we want to use the keys of such dict as an iterable to
|
||||||
|
# initialize the Counter instead.
|
||||||
|
self.bag = collections.Counter(iter(iterable))
|
||||||
|
|
||||||
super(ItemsMatcher, self).__init__(
|
super(ItemsMatcher, self).__init__(
|
||||||
lambda other: self.items == set(other))
|
lambda other: self.bag == collections.Counter(iter(other)))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""This exists so a failed assertion prints something useful."""
|
"""This exists so a failed assertion prints something useful."""
|
||||||
return 'ItemsMatcher(%r)' % self.items
|
return 'ItemsMatcher(%r)' % list(self.bag.elements())
|
||||||
|
|
||||||
|
|
||||||
def assert_instance_delete_notification_by_uuid(
|
def assert_instance_delete_notification_by_uuid(
|
||||||
|
|||||||
Reference in New Issue
Block a user