コード例 #1
0
 def __setitem__(self, key, value):
     checkObject(self, key, value)
     value.__parent__ = self
     value.__name__ = key
     alsoProvides(value, IContained)
     OOBTree.__setitem__(self, key, value)
     notify(events.RelationAddedEvent(value))
コード例 #2
0
def test_moving_failure():
    """The constraints prevent us from moving a container beneath
    itself (either into itself or another folder beneath it).
    """
    container = Container()

    with pytest.raises(TypeError):
        checkObject(container, 'x', container)

    subcontainer = Container()
    interface.directlyProvides(subcontainer, ILocation)
    subcontainer.__parent__ = container

    with pytest.raises(TypeError):
        checkObject(subcontainer, 'x', container)
コード例 #3
0
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.
    """
    @interface.implementer(IContact)
    class Contact:
        pass
        
    @interface.implementer(IContacts)
    class Contacts:
        pass
        

    assert checkObject(Contacts(), 'x', Contact()) is None

    with pytest.raises(InvalidItemType):
        checkObject(Contacts(), 'x', object())
コード例 #4
0
def test_contraints():

    @interface.implementer(IBuddy)
    class Buddy:
        pass

    @interface.implementer(IBuddyFolder)
    class BuddyFolder:
        pass

    assert checkObject(BuddyFolder(), 'x', Buddy()) is None

    @interface.implementer(IContained)
    class Contained:
        pass

    with pytest.raises(InvalidContainerType):
        checkObject(Container(), 'x', Buddy())

    with pytest.raises(InvalidItemType):
        checkObject(BuddyFolder(), 'x', Contained())
コード例 #5
0
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())