/usr/share/pyshared/zope/container/tests/test_ordered.py is in python-zope.container 3.12.0-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | ##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the OrderedContainer.
"""
import unittest
from doctest import DocTestSuite
from zope.component.eventtesting import getEvents, clearEvents
from zope.container import testing
def test_order_events():
"""
Prepare the setup::
>>> from zope.container.sample import SampleContainer
>>> root = SampleContainer()
Prepare some objects::
>>> from zope.container.ordered import OrderedContainer
>>> oc = OrderedContainer()
>>> oc['foo'] = 'bar'
>>> oc['baz'] = 'quux'
>>> oc['zork'] = 'grue'
>>> oc.keys()
['foo', 'baz', 'zork']
Now change the order::
>>> clearEvents()
>>> oc.updateOrder(['baz', 'foo', 'zork'])
>>> oc.keys()
['baz', 'foo', 'zork']
Check what events have been sent::
>>> events = getEvents()
>>> [event.__class__.__name__ for event in events]
['ContainerModifiedEvent']
This is in fact a specialized modification event::
>>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
>>> IObjectModifiedEvent.providedBy(events[0])
True
"""
def test_all_items_available_at_object_added_event():
"""
Prepare the setup::
>>> from zope.container.sample import SampleContainer
>>> root = SampleContainer()
Now register an event subscriber to object added events.
>>> import zope.component
>>> from zope.container import interfaces
>>> from zope.lifecycleevent.interfaces import IObjectAddedEvent
>>> @zope.component.adapter(IObjectAddedEvent)
... def printContainerKeys(event):
... print event.newParent.keys()
>>> zope.component.provideHandler(printContainerKeys)
Now we are adding an object to the container.
>>> from zope.container.ordered import OrderedContainer
>>> oc = OrderedContainer()
>>> oc['foo'] = 'FOO'
['foo']
"""
def test_exception_causes_order_fix():
"""
Prepare the setup::
>>> from zope.container.sample import SampleContainer
>>> root = SampleContainer()
Now register an event subscriber to object added events that
throws an error.
>>> import zope.component
>>> from zope.container import interfaces
>>> from zope.lifecycleevent.interfaces import IObjectAddedEvent
>>> @zope.component.adapter(IObjectAddedEvent)
... def raiseException(event):
... raise Exception()
>>> zope.component.provideHandler(raiseException)
Now we are adding an object to the container.
>>> from zope.container.ordered import OrderedContainer
>>> oc = OrderedContainer()
>>> oc['foo'] = 'FOO'
Traceback (most recent call last):
...
Exception
The key 'foo' should not be around:
>>> 'foo' in oc.keys()
False
"""
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite("zope.container.ordered",
setUp=testing.setUp,
tearDown=testing.tearDown))
suite.addTest(DocTestSuite(
setUp=testing.ContainerPlacefulSetup().setUp,
tearDown=testing.ContainerPlacefulSetup().tearDown))
return suite
if __name__ == '__main__':
unittest.main()
|