def test_constraints_order(): """In the previous tests, we defined the container first and then the items. We can define these in the opposite order. """ class Contact: interface.implements(IContact) class Contacts: interface.implements(IContacts) assert checkObject(Contacts(), 'x', Contact()) is None assert checkFactory(Contacts(), 'x', Factory(Contact)) with pytest.raises(InvalidItemType): checkObject(Contacts(), 'x', object()) assert not checkFactory(Contacts(), 'x', Factory(object))
def test_contraints(): class Buddy: interface.implements(IBuddy) class BuddyFolder: interface.implements(IBuddyFolder) assert checkObject(BuddyFolder(), 'x', Buddy()) is None assert checkFactory(BuddyFolder(), 'x', Factory(Buddy)) class Contained: interface.implements(IContained) with pytest.raises(InvalidContainerType): checkObject(Container(), 'x', Buddy()) assert not checkFactory(Container(), 'x', Factory(Buddy)) with pytest.raises(InvalidItemType): checkObject(BuddyFolder(), 'x', Contained())
def get_valid_factories(container): for name, factory in getUtilitiesFor(dolmen.content.IFactory): if checkFactory(container, name, factory): yield name, factory