Exemple #1
0
    def test_order_adding_none(self):
        # This is a regression test: adding None to an OrderedContainer
        # used to corrupt its internal data structure (_order and _data
        # would get out of sync, causing KeyErrors when you tried to iterate).

        from zope.container.ordered import OrderedContainer
        oc = OrderedContainer()
        oc['foo'] = None
        self.assertEqual(oc.keys(), ['foo'])
        self.assertEqual(oc.values(), [None])
        self.assertEqual(oc.items(), [('foo', None)])
        # None got proxied, so 'is None is not true
        self.assertIsNotNone(oc['foo'])
        self.assertEqual(None, oc['foo'])
Exemple #2
0
    def test_order_adding_none(self):
        # This is a regression test: adding None to an OrderedContainer
        # used to corrupt its internal data structure (_order and _data
        # would get out of sync, causing KeyErrors when you tried to iterate).

        from zope.container.ordered import OrderedContainer
        oc = OrderedContainer()
        oc['foo'] = None
        self.assertEqual(oc.keys(), ['foo'])
        self.assertEqual(oc.values(), [None])
        self.assertEqual(oc.items(),
                         [('foo', None)])
        # None got proxied, so 'is None is not true
        self.assertIsNotNone(oc['foo'])
        self.assertEqual(None, oc['foo'])
Exemple #3
0
 def listItems(self):
     # Now this is tricky: we want to construct a small object graph using
     # old state pickles without ever calling __setstate__ on a real
     # Persistent object, as _that_ would poison ZODB in-memory caches
     # in a nasty way (LP #487243).
     container = OrderedContainer()
     container.__setstate__(self.state)
     if isinstance(container._data, PersistentDict):
         old_data_state = IObjectHistory(container._data).loadState(self.tid)
         container._data = PersistentDict()
         container._data.__setstate__(old_data_state)
     if isinstance(container._order, PersistentList):
         old_order_state = IObjectHistory(container._order).loadState(self.tid)
         container._order = PersistentList()
         container._order.__setstate__(old_order_state)
     return container.items()
Exemple #4
0
 def listItems(self):
     # Now this is tricky: we want to construct a small object graph using
     # old state pickles without ever calling __setstate__ on a real
     # Persistent object, as _that_ would poison ZODB in-memory caches
     # in a nasty way (LP #487243).
     container = OrderedContainer()
     container.__setstate__(self.state)
     if isinstance(container._data, PersistentDict):
         old_data_state = IObjectHistory(container._data).loadState(
             self.tid)
         container._data = PersistentDict()
         container._data.__setstate__(old_data_state)
     if isinstance(container._order, PersistentList):
         old_order_state = IObjectHistory(container._order).loadState(
             self.tid)
         container._order = PersistentList()
         container._order.__setstate__(old_order_state)
     return container.items()