[tests] Add tests to exercise various code paths in Select.replace()
authorRémi Cardona <remi.cardona@logilab.fr>
Mon, 21 Sep 2015 12:20:26 +0200
changeset 784 610b45f75ea8
parent 783 c54814eb0a28
child 785 76b5258df874
[tests] Add tests to exercise various code paths in Select.replace() The original patch for bug #1190458 broke tests in CubicWeb. The patch has now been amended to fix the broken paths (namely, replacing the 'in' tests with appropriate 'is_equivalent' loops). These tests are adapted from CubicWeb's own test suite, especially those that test FTIRANK() on sqlite (the function exists but is replaced by a no-op).
test/unittest_nodes.py
--- a/test/unittest_nodes.py	Mon Sep 21 12:20:16 2015 +0200
+++ b/test/unittest_nodes.py	Mon Sep 21 12:20:26 2015 +0200
@@ -654,6 +654,30 @@
         self.assertEqual(select.selection[0].get_type(), 'String')
         self.assertEqual(tree.get_description(0), [['String']])
 
+    def test_replace_node_select(self):
+        tree = sparse(u'Any X, MAX(X) WHERE X name "toto tata"')
+        select = tree.children[0]
+        funcnode = sparse(u'Any MAX(X)').children[0].selection[0]
+        select.replace(funcnode, nodes.Constant(1.0, 'Float'))
+
+    def test_replace_node_orderby(self):
+        tree = sparse(u'Any X ORDERBY MAX(X) WHERE X name "toto tata"')
+        select = tree.children[0]
+        funcnode = sparse(u'Any X ORDERBY MAX(X)').children[0].orderby[0]
+        select.replace(funcnode, nodes.Constant(1.0, 'Float'))
+
+    def test_replace_node_groupby(self):
+        tree = sparse(u'Any X GROUPBY X, MAX(X) WHERE X name "toto tata"')
+        select = tree.children[0]
+        funcnode = sparse(u'Any MAX(X)').children[0].selection[0]
+        select.replace(funcnode, nodes.Constant(1.0, 'Float'))
+
+    def test_replace_node_having(self):
+        tree = sparse(u'Any X WHERE X name "toto tata" HAVING MAX(X) > 1')
+        select = tree.children[0]
+        funcnode = sparse(u'Any X HAVING MAX(X) > 1').children[0].having[0]
+        select.replace(funcnode, nodes.Constant(1.0, 'Float'))
+
 
 class GetNodesFunctionTest(TestCase):
     def test_known_values_1(self):