def _convert(self, collection): # TODO We could check if the objects' type is correct. type_ = util.duck_type_collection(collection) if type_ is dict: for key, value in util.dictlike_iteritems(collection): if key != self.keyfunc(value): raise TypeError("Found incompatible key '%r' for value '%r'" % (key, value)) yield value elif type_ in (list, set): for value in collection: yield value else: raise TypeError("Object '%r' is not dict-like nor iterable" % collection)
def _convert(self, coll): # TODO We could check if the objects' type is correct. type_ = util.duck_type_collection(coll) if type_ is dict: for key, value in util.dictlike_iteritems(coll): if key != self.keyfunc(value): raise TypeError( "Found incompatible key '%r' for value '%r'" % (key, value)) yield value elif type_ in (list, set): for value in coll: yield value else: raise TypeError("Object '%r' is not dict-like nor iterable" % coll)
def _convert(self, dictlike): """Validate and convert a dict-like object into values for set()ing. This is called behind the scenes when a MappedCollection is replaced entirely by another collection, as in:: myobj.mappedcollection = {'a':obj1, 'b': obj2} # ... Raises a TypeError if the key in any (key, value) pair in the dictlike object does not match the key that this collection's keyfunc would have assigned for that value. """ for incoming_key, value in sautil.dictlike_iteritems(dictlike): new_key = self.keyfunc(value) if incoming_key != new_key: raise TypeError( "Found incompatible key %r for value %r; this collection's " "keying function requires a key of %r for this value." % (incoming_key, value, new_key)) yield value
def _convert(self, dictlike): """Validate and convert a dict-like object into values for set()ing. This is called behind the scenes when a MappedCollection is replaced entirely by another collection, as in:: myobj.mappedcollection = {'a':obj1, 'b': obj2} # ... Raises a TypeError if the key in any (key, value) pair in the dictlike object does not match the key that this collection's keyfunc would have assigned for that value. """ for incoming_key, value in util.dictlike_iteritems(dictlike): new_key = self.keyfunc(value) if incoming_key != new_key: raise TypeError( "Found incompatible key %r for value %r; this collection's " "keying function requires a key of %r for this value." % ( incoming_key, value, new_key)) yield value
def _ok(self, instance): iterator = util.dictlike_iteritems(instance) eq_(set(iterator), self.baseline)
def _ok(self, instance): iterator = util.dictlike_iteritems(instance) self.assertEquals(set(iterator), self.baseline)