[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_query.py:1.14

Casey Duncan casey at zope.com
Mon May 31 23:05:51 EDT 2004


Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv25759/tests

Modified Files:
	test_query.py 
Log Message:
Implement fixed values for partial result iterResult methods. This is in anticipation of the sort implementation which will depend on it. It is also used by Join in certain cases.


=== Packages/pypes/pypes/tests/test_query.py 1.13 => 1.14 ===
--- Packages/pypes/pypes/tests/test_query.py:1.13	Wed May 26 00:32:49 2004
+++ Packages/pypes/pypes/tests/test_query.py	Mon May 31 23:05:50 2004
@@ -187,7 +187,7 @@
             count += 1
         self.assertEqual(count, len(self.foos))
     
-    def test_iter_three_with_static(self):
+    def test_iter_three_with_fixed(self):
         from pypes.query import CartProduct
         inputs = {'one': [1,2,3,4,5,6], 
                   'two': list('ABCDEFGHIJKLMNOP'),
@@ -206,11 +206,12 @@
             count += 1
         self.assertEqual(count, len(inputs['three']))
     
-    def test_iter_with_static_fails(self):
+    def test_iter_with_fixed_fails(self):
+        from pypes.exceptions import PypesQueryError
         self.assertRaises(
-            AssertionError, self.cp.iterResult('foo', 'bar', bar=Bar()).next)
+            StopIteration, self.cp.iterResult('foo', 'bar', bar=Bar()).next)
         self.assertRaises(
-            KeyError, self.cp.iterResult('foo', 'bar', baz=None).next)
+            PypesQueryError, self.cp.iterResult('foo', 'bar', baz=None).next)
     
     def test_union_cp_with_cp(self):
         from pypes.query import CartProduct
@@ -528,7 +529,48 @@
                                 for c in self.inputs['c']
                                 if a[-1] == b])
         self.assertEqual(Set(j.iterResult('a', 'c')), expected)
+        
+    def test_select_join_fixed_right(self):
+        from pypes.query import Join
+        j = Join(self.inputs, DummyExpr(expr='a[-1] == b', names=['a', 'b']))
+        expected = Set([a for a in self.inputs['a'] 
+                          for b in self.inputs['b']
+                          if a[-1] == b and b == 'A'])
+        self.assertEqual(Set(j.iterResult('a', b='A')), expected)
+        
+    def test_select_join_fixed_left(self):
+        from pypes.query import Join
+        j = Join(self.inputs, DummyExpr(expr='a[-1] == b', names=['a', 'b']))
+        expected = Set([b for a in self.inputs['a'] 
+                          for b in self.inputs['b']
+                          if a[-1] == b and a == 'BAA'])
+        self.assertEqual(Set(j.iterResult('b', a='BAA')), expected)
+        
+    def test_select_join_fixed_both(self):
+        from pypes.query import Join
+        j = Join(self.inputs, DummyExpr(expr='a[-1] == b', names=['a', 'b']))
+        expected = Set([('AAD', 'D')])
+        self.assertEqual(Set(j.iterResult('a', 'b', a='AAD', b='D')), expected)
+    
+    def test_select_join_fixed_nomatch(self):
+        from pypes.query import Join
+        j = Join(self.inputs, DummyExpr(expr='a[:2] == c', names=['a', 'c']))
+        self.assertRaises(
+            StopIteration, j.iterResult('a', 'c', a='AAA', c='CC').next)
+        self.assertRaises(
+            StopIteration, j.iterResult('a', 'c', a='BCC', c='CC').next)
+        self.assertRaises(
+            StopIteration, j.iterResult('a', 'c', a='AAA', c='EE').next)
+        self.assertRaises(
+            StopIteration, j.iterResult('a', 'c', a='REE', c='EE').next)
     
+    def test_select_join_fixed_bad_input(self):
+        from pypes.query import Join
+        from pypes.exceptions import PypesQueryError
+        j = Join(self.inputs, DummyExpr(expr='a[:2] == c', names=['a', 'c']))
+        self.assertRaises(
+            PypesQueryError, j.iterResult, 'a', 'c', uncle='bob')
+           
     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']))
@@ -604,6 +646,31 @@
         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)
+    
+    def test_select_fixed_one_input(self):
+        self.assertEqual(list(self.result.iterResult('a', a=40)), [40])
+        self.assertEqual(
+            Set(self.result.iterResult('b', a=40)), 
+                self.result.inputMap()['b'])
+    
+    def test_select_fixed_two_inputs(self):
+        self.assertEqual(
+            list(self.result.iterResult('a', 'b', a=20, b='Q')), [(20, 'Q')])
+    
+    def test_select_fixed_nomatch(self):
+        self.assertRaises(
+             StopIteration, self.result.iterResult('a', 'b', a=30).next)
+        self.assertRaises(
+             StopIteration, self.result.iterResult('a', 'b', b='E').next)
+        self.assertRaises(
+             StopIteration, 
+             self.result.iterResult('a', 'b', a=1000, b='Jeez').next)
+    
+    def test_select_fixed_bad_input(self):
+        from pypes.exceptions import PypesQueryError
+        self.assertRaises(
+            PypesQueryError, self.result.iterResult('a', 'b', uncle='bob').next)
+
 
 if __name__ == '__main__':
     unittest.main()




More information about the Zope-CVS mailing list