[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_query.py:1.6
Casey Duncan
casey at zope.com
Wed Apr 21 01:32:10 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv12167/tests
Modified Files:
test_query.py
Log Message:
Define IPartialResult interface for intermediate query result objects. Begin changing CartProduct class to implement it. Add supporting functions and tests.
Test pass, but CartProduct implementation needs finishing
=== Packages/pypes/pypes/tests/test_query.py 1.5 => 1.6 ===
--- Packages/pypes/pypes/tests/test_query.py:1.5 Mon Apr 19 01:12:46 2004
+++ Packages/pypes/pypes/tests/test_query.py Wed Apr 21 01:32:09 2004
@@ -52,35 +52,72 @@
class Bar(TestClass):
pass
+
+class TestUtilities(unittest.TestCase):
+
+ def test_union_input_maps(self):
+ from pypes.query import union_input_maps
+ map1 = {'jerry': Set((1,2,3)), 'george': Set(('blue', 'red'))}
+ map2 = {'jerry': Set((3,4,5)), 'george': map1['george']}
+ union = union_input_maps(map1, map2)
+ self.assertEqual(Set(union), Set(map1))
+ self.assertEqual(union['jerry'], map1['jerry'].union(map2['jerry']))
+ self.assertEqual(union['george'], map1['george'].union(map2['george']))
+ self.failIf(union is map1 or union is map2)
class TestCartProduct(unittest.TestCase):
def setUp(self):
+ from pypes.query import CartProduct
self.foos = [Foo(foo=i) for i in range(10)]
self.bars = [Bar(bar=chr(i+65)) for i in range(26)]
self.inputs = {'foo':self.foos, 'bar':self.bars}
+ self.cp = CartProduct(self.inputs)
+
+ def test_interface(self):
+ from pypes.interfaces import IPartialResult
+ self.failUnless(verifyObject(IPartialResult, self.cp))
- def test_maxLen(self):
+ def test_input_map(self):
+ self.assertEqual(self.cp.inputMap(), self.inputs)
+ self.failIf(self.cp.inputMap() is self.inputs)
+
+ def test_criteria(self):
from pypes.query import CartProduct
- cp = CartProduct(self.inputs)
+ self.assertEqual(self.cp.criteriaExpr(), None)
+ criteria = DummyExpr(None)
+ cp = CartProduct(self.inputs, criteria)
+ self.assertEqual(cp.criteriaExpr(), criteria)
+
+ def test_names_used(self):
+ from pypes.query import CartProduct
+ self.failIf(self.cp.namesUsed())
+ cp = CartProduct(
+ self.inputs, DummyExpr(None, ['kirk', 'spock', 'mccoy']))
+ self.assertEqual(cp.namesUsed(), Set(['kirk', 'spock', 'mccoy']))
+
+ def test_magnitude_all_inputs(self):
expected = reduce(mul, [len(ipt) for ipt in self.inputs.values()])
- self.assertEqual(cp.maxLen(), expected)
+ self.assertEqual(self.cp.magnitude(), expected)
+ self.assertEqual(self.cp.magnitude('foo', 'bar'), expected)
+
+ def test_magnitude_one_input(self):
+ self.assertEqual(self.cp.magnitude('bar'), len(self.inputs['bar']))
+ self.assertEqual(self.cp.magnitude('foo'), len(self.inputs['foo']))
def test_iter_one_no_criteria(self):
- from pypes.query import CartProduct
- cp = CartProduct(self.inputs)
- result = list(cp.iterProduct('foo'))
+ result = list(self.cp.iterResult('foo'))
self.assertEqual(len(result), len(self.foos) * len(self.bars))
expected = Set(self.foos)
result = Set(result)
self.assertEqual(result, expected)
- def test_iter_with_criteria(self):
+ def test_iter_two_with_criteria(self):
from pypes.query import CartProduct
cp = CartProduct(self.inputs,
lambda ipt: ipt['foo'].foo < 5 and ipt['bar'].bar in ('A', 'B'))
count = 0
- for foo, bar in cp.iterProduct('foo', 'bar'):
+ for foo, bar in cp.iterResult('foo', 'bar'):
self.failUnless(foo.foo < 5 and bar.bar in ('A', 'B'))
count += 1
self.assertEqual(count, len(self.foos))
More information about the Zope-CVS
mailing list