[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_extent.py:1.10
Casey Duncan
casey at zope.com
Sun Feb 22 01:09:32 EST 2004
Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv11264/tests
Modified Files:
test_extent.py
Log Message:
Finish implementing extent to identity set operations and add integration tests
=== Packages/pypes/pypes/tests/test_extent.py 1.9 => 1.10 ===
--- Packages/pypes/pypes/tests/test_extent.py:1.9 Mon Feb 16 01:00:01 2004
+++ Packages/pypes/pypes/tests/test_extent.py Sun Feb 22 01:09:32 2004
@@ -21,14 +21,15 @@
from zope.interface import Interface, implements
from zope.interface.exceptions import DoesNotImplement
from zope.interface.verify import verifyObject
+from persistent import Persistent
from pypes.interfaces import IExtentMap, IExtentService
from pypes.tests.common import TestConnection, sort, PypesTestCase
from BTrees.OOBTree import OOBTree, OOTreeSet
-class FooClass:
+class FooClass(Persistent):
pass
-class BarClass(object):
+class BarClass(Persistent):
pass
class BazClass(BarClass):
@@ -283,7 +284,7 @@
self.assertEqual(len(self.cemap[BarClass]), 15)
self.assertEqual(len(self.cemap[BazClass]), 10)
self.assertEqual(len(self.cemap[SplatClass]), 5)
- self.assertEqual(len(self.cemap[object]), 15)
+ self.assertEqual(len(self.cemap[object]), 20)
def testRemoveObject(self):
from pypes import services
@@ -396,7 +397,7 @@
union = foo_extent | splat_extent
self.failIf(union is foo_extent)
self.failIf(union is splat_extent)
- self.assertEqual(sort(list(union)), sort(foos + splats))
+ self.assertEqual(sort(list(union)), sort(foos + splats))
def testDiffDisjointExtents(self):
foo_extent, foos = self.makeExtent(FooClass)
@@ -514,7 +515,7 @@
self.identity.register(obj)
return obj
- def testIdentifyCreatesExtents(self):
+ def testIdentifyCreatesClassExtents(self):
self.assertRaises(KeyError, lambda cls: self.extent[cls], FooClass)
self.assertRaises(KeyError, lambda cls: self.extent[cls], BarClass)
self.assertRaises(KeyError, lambda cls: self.extent[cls], BazClass)
@@ -525,7 +526,7 @@
self.failUnless(obj in self.extent[BarClass])
self.assertRaises(KeyError, lambda cls: self.extent[cls], FooClass)
- def testRemoveRemovesExtents(self):
+ def testRemoveRemovesClassExtents(self):
foo, bar, baz, splat = [self._makeObj(cls)
for cls in [FooClass, BarClass, BazClass, SplatClass]]
self.assertEqual(len(self.extent[FooClass]), 1)
@@ -552,7 +553,137 @@
self.assertRaises(KeyError, lambda cls: self.extent[cls], BarClass)
self.assertRaises(KeyError, lambda cls: self.extent[cls], BazClass)
self.assertRaises(KeyError, lambda cls: self.extent[cls], SplatClass)
-
+
+ def testExtentEqIdentitySet(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(50)]
+ foos = [self._makeObj(FooClass) for i in range(50)]
+ bar_set = IdentitySet(bars)
+ foo_set = IdentitySet(foos)
+ self.failUnless(self.extent[BarClass] == bar_set)
+ self.failUnless(bar_set == self.extent[BarClass])
+ self.failIf(self.extent[BarClass] == foo_set)
+ self.failIf(foo_set == self.extent[BarClass])
+ self.failUnless(self.extent[FooClass] == foo_set)
+ self.failUnless(foo_set == self.extent[FooClass])
+ self.failIf(self.extent[FooClass] == bar_set)
+ self.failIf(bar_set == self.extent[FooClass])
+
+ def testExtentNeIdentitySet(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(50)]
+ foos = [self._makeObj(FooClass) for i in range(50)]
+ bar_set = IdentitySet(bars)
+ foo_set = IdentitySet(foos)
+ self.failIf(self.extent[BarClass] != bar_set)
+ self.failIf(bar_set != self.extent[BarClass])
+ self.failUnless(self.extent[BarClass] != foo_set)
+ self.failUnless(foo_set != self.extent[BarClass])
+ self.failIf(self.extent[FooClass] != foo_set)
+ self.failIf(foo_set != self.extent[FooClass])
+ self.failUnless(self.extent[FooClass] != bar_set)
+ self.failUnless(bar_set != self.extent[FooClass])
+
+ def testExtentIdentitySetUnion(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ bar_set = IdentitySet(bars)
+ foo_set = IdentitySet(foos)
+ union = self.extent[FooClass].union(bar_set)
+ self.failUnless(isinstance(union, IdentitySet))
+ self.assertEqual(union, foo_set.union(bar_set))
+ self.assertEqual(sort(list(union)), sort(foos + bars))
+
+ def testUnionDifferentExtentKinds(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ extent1 = self.extent[BarClass]
+ extent2 = self.extent[FooClass]
+ # Pretend to use a different extent map for extent2
+ extent2._instances = OOBTree(extent2._instances.items())
+ union = extent1.union(extent2)
+ self.failUnless(isinstance(union, IdentitySet))
+ self.assertEqual(sort(list(union)), sort(foos + bars))
+
+ def testExtentIdentitySetIntersect(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ overlap = bars[5:] + foos[5:]
+ bar_set = IdentitySet(bars + overlap)
+ foo_set = IdentitySet(foos)
+ sect = self.extent[FooClass].intersection(bar_set)
+ self.failUnless(isinstance(sect, IdentitySet))
+ self.assertEqual(sect, foo_set.intersection(bar_set))
+ self.assertEqual(sort(list(sect)), sort(foos[5:]))
+
+ def testIntersectDifferentExtentKinds(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ extent1 = self.extent[BarClass]
+ extent2 = self.extent[BarClass]
+ # Pretend to use a different extent map for extent2
+ extent2._instances = OOBTree(extent2._instances.items())
+ sect = extent1.intersection(extent2)
+ self.failUnless(isinstance(sect, IdentitySet))
+ self.assertEqual(sort(list(sect)), sort(bars))
+
+ def testExtentIdentitySetDiff(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ halfnhalf = bars[5:] + foos[5:]
+ foo_set = IdentitySet(foos)
+ some_set = IdentitySet(halfnhalf)
+ diff = self.extent[FooClass].difference(some_set)
+ self.failUnless(isinstance(diff, IdentitySet))
+ self.assertEqual(diff, foo_set.difference(some_set))
+ self.assertEqual(sort(list(diff)), sort(foos[:5]))
+
+ def testDiffDifferentExtentKinds(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ extent1 = self.extent[BarClass]
+ extent2 = self.extent[BarClass]
+ # Pretend to use a different extent map for extent2
+ extent2._instances = OOBTree(extent2._instances.items())
+ diff = extent1.difference(extent2)
+ self.failUnless(isinstance(diff, IdentitySet))
+ self.assertEqual(diff, IdentitySet())
+
+ def testExtentSuperSetofIdentitySet(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ subset = IdentitySet(bars[5:])
+ self.failUnless(self.extent[BarClass].issuperset(subset))
+ self.failIf(self.extent[BarClass].issubset(subset))
+ self.failIf(self.extent[FooClass].issuperset(subset))
+ self.failIf(self.extent[FooClass].issubset(subset))
+ self.failUnless(subset.issubset(self.extent[BarClass]))
+ self.failIf(subset.issuperset(self.extent[BarClass]))
+ self.failIf(subset.issubset(self.extent[FooClass]))
+ self.failIf(subset.issuperset(self.extent[FooClass]))
+
+ def testExtentSuperSetofDifferentExtentKinds(self):
+ from pypes.identity import IdentitySet
+ bars = [self._makeObj(BarClass) for i in range(10)]
+ foos = [self._makeObj(FooClass) for i in range(10)]
+ baz = [self._makeObj(BazClass) for i in range(10)]
+ extent1 = self.extent[BarClass]
+ extent2 = self.extent[BazClass]
+ # Pretend to use a different extent map for extent2
+ extent2._instances = OOBTree(extent2._instances.items())
+ self.failUnless(extent1.issuperset(extent2))
+ self.failIf(extent1.issubset(extent2))
+ self.failIf(self.extent[FooClass].issuperset(extent2))
+ self.failIf(self.extent[FooClass].issubset(extent2))
+ self.failUnless(extent2.issubset(extent1))
+ self.failIf(extent2.issuperset(extent1))
+ self.failIf(extent2.issubset(self.extent[FooClass]))
+ self.failIf(extent2.issuperset(self.extent[FooClass]))
if __name__ == '__main__':
unittest.main()
More information about the Zope-CVS
mailing list