properly undoable stmt.add_type_restriction. Closes #176469
--- a/nodes.py Thu Aug 08 13:42:58 2013 +0200
+++ b/nodes.py Wed Sep 11 12:51:29 2013 +0200
@@ -1,4 +1,4 @@
-# copyright 2004-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of rql.
@@ -232,7 +232,7 @@
# iterate a copy of children because it's modified inplace
for child in istarget.children[:]:
if child.value != etype:
- istarget.remove(child)
+ typerel.stmt.remove_node(child)
else:
# let's botte en touche IN cases (who would do that anyway ?)
if isinstance(istarget, Function):
--- a/test/unittest_nodes.py Thu Aug 08 13:42:58 2013 +0200
+++ b/test/unittest_nodes.py Wed Sep 11 12:51:29 2013 +0200
@@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
-# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2004-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of rql.
@@ -291,6 +291,18 @@
tree.check_references()
self.assertEqual(tree.as_string(), 'Any X,Y GROUPBY X,Y')
+ def test_recover_add_type_restriction_is_in(self):
+ tree = self._parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
+ annotator.annotate(tree) # needed to get typerel index
+ tree.save_state()
+ select = tree.children[0]
+ x = select.get_selected_variables().next()
+ select.add_type_restriction(x.variable, 'Company')
+ self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Company), X name ILIKE 'A%'")
+ tree.recover()
+ tree.check_references()
+ self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
+
def test_select_base_1(self):
tree = self._parse("Any X WHERE X is Person")
self.assertIsInstance(tree, stmts.Union)