[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_query.py:1.12
Casey Duncan
casey at zope.com
Fri May 14 00:38:34 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv23901/tests
Modified Files:
test_query.py
Log Message:
Implement basic union & intersection for Join partial results
Implement actualized results
reload(sys)
=== Packages/pypes/pypes/tests/test_query.py 1.11 => 1.12 ===
--- Packages/pypes/pypes/tests/test_query.py:1.11 Thu May 13 00:33:39 2004
+++ Packages/pypes/pypes/tests/test_query.py Fri May 14 00:38:32 2004
@@ -34,6 +34,8 @@
self._names = Set(names)
if expr is not None:
self._ast = parse(expr, mode='eval')
+ if func is None:
+ self._func = lambda ns: eval(expr, {}, ns)
def names(self):
return self._names
@@ -61,16 +63,16 @@
and self._names == other.__names)
def __or__(self, other):
- assert Set(self._names) == Set(other._names)
+ names = list(Set(self._names) & Set(other._names))
def func(*args, **kw):
return self._func(*args, **kw) or other._func(*args, **kw)
- return DummyExpr(func, self._names)
+ return DummyExpr(func, names)
def __and__(self, other):
- assert Set(self._names) == Set(other._names)
+ names = list(Set(self._names) & Set(other._names))
def func(*args, **kw):
return self._func(*args, **kw) and other._func(*args, **kw)
- return DummyExpr(func, self._names)
+ return DummyExpr(func, names)
class Foo(TestClass):
pass
@@ -505,7 +507,7 @@
def test_union_joins_one_common_input(self):
from pypes.query import Join
j1 = Join(self.inputs, DummyExpr(expr='a[-1] == b', names=['a', 'b']))
- j2 = Join(self.inputs, DummyExpr(expr='a[:2] == c', names=['a', 'b']))
+ j2 = Join(self.inputs, DummyExpr(expr='a[:2] == c', names=['a', 'c']))
union = j1.union(j2)
self.failIf(union is j1)
self.failIf(union is j2)
@@ -513,7 +515,54 @@
for b in self.inputs['b']
for c in self.inputs['c']
if a[-1] == b or a[:2] == c])
- self.assertEqual(sort(union), expected)
+ self.assertEqual(sort(union.iterResult('a', 'b', 'c')), expected)
+
+
+class TestActualizedResult(unittest.TestCase):
+
+ def setUp(self):
+ from pypes.query import ActualizedResult
+ self.inputs = {'a': Set((10,20,30,40,50,60)),
+ 'b': Set('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}
+ self.criteria = DummyExpr(expr="a%20 == 0 and b > 'M'", names=['a','b'])
+ self.result = ActualizedResult(self.inputs, self.criteria)
+
+ def test_interface(self):
+ from pypes.interfaces import IPartialResult
+ self.failUnless(verifyObject(IPartialResult, self.result))
+
+ def test_input_map(self):
+ expected = {
+ 'a': Set((20, 40, 60)),
+ 'b': Set('NOPQRSTUVWXYZ')}
+ self.assertEqual(self.result.inputMap(), expected)
+ self.failIf(self.result.inputMap() is self.inputs)
+
+ def test_criteria(self):
+ self.failUnless(self.result.criteriaExpr() is self.criteria)
+
+ def test_names_used(self):
+ self.assertEqual(self.result.namesUsed(), Set(['a', 'b']))
+
+ def test_no_criteria(self):
+ from pypes.query import ActualizedResult
+ inputset = Set((1,2,3,4))
+ ar = ActualizedResult({'x':inputset})
+ self.assertEqual(Set(ar.iterResult('x')), inputset)
+
+ def test_select_one_input(self):
+ expected = Set([a for a in self.inputs['a'] if a%20 == 0])
+ self.assertEqual(Set(self.result.iterResult('a')), expected)
+ expected = Set([b for b in self.inputs['b'] if b > 'M'])
+ self.assertEqual(Set(self.result.iterResult('b')), expected)
+
+ def test_select_multiple_inputs(self):
+ expected = sort([(a, b) for a in self.inputs['a']
+ for b in self.inputs['b']
+ if a%20 == 0 and b > 'M'])
+ self.assertEqual(sort(self.result.iterResult('a', 'b')), expected)
+ expected = sort([(b, a) for a, b in expected])
+ self.assertEqual(sort(self.result.iterResult('b', 'a')), expected)
if __name__ == '__main__':
unittest.main()
More information about the Zope-CVS
mailing list