I have a class that mostly displays outwardly as a set of ids, but not entirely. Think this:
class PoundIds(object):
....
@property
def cats(self):
return self.cats
@property
def dogs(self):
return self.dogs
@property
def animal_ids(self):
return set(dog.id for dog in self.dogs) | set(cat.id for cat in self.cats) |
def __contains__(self, id):
return id in self.animal_ids
def __iter__(self, id):
return self.animal_ids.__iter__()
I am now testing this object, in a way that will only be using the list of ids it provides. Is there a way to mock out the object as a specific set of integers, passing magic methods through to the encapsulated set?
Aucun commentaire:
Enregistrer un commentaire