# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1378896689 -7200
# Wed Sep 11 12:51:29 2013 +0200
# Branch stable
# Node ID a3ddccf19ded09c1614124c94536c55d612143f8
# Parent ff79e47ff011e359f180476d6c13acee2154e2bf
properly undoable stmt.add_type_restriction. Closes #176469
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1378896689 -7200
# Wed Sep 11 12:51:29 2013 +0200
# Branch stable
# Node ID a3ddccf19ded09c1614124c94536c55d612143f8
# Parent ff79e47ff011e359f180476d6c13acee2154e2bf
properly undoable stmt.add_type_restriction. Closes #176469
@@ -1,6 +1,6 @@
1 -# copyright 2004-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 2 +# copyright 2004-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 4 # 5 # This file is part of rql. 6 # 7 # rql is free software: you can redistribute it and/or modify it under the
@@ -230,11 +230,11 @@
8 raise RQLException('%r not in %r' % (etype, etypes)) 9 if len(etypes) > 1: 10 # iterate a copy of children because it's modified inplace 11 for child in istarget.children[:]: 12 if child.value != etype: 13 - istarget.remove(child) 14 + typerel.stmt.remove_node(child) 15 else: 16 # let's botte en touche IN cases (who would do that anyway ?) 17 if isinstance(istarget, Function): 18 msg = 'adding type restriction over is_instance_of IN is not supported' 19 raise NotImplementedError(msg)
@@ -1,7 +1,7 @@
20 # -*- coding: iso-8859-1 -*- 21 -# copyright 2004-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 22 +# copyright 2004-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 23 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 24 # 25 # This file is part of rql. 26 # 27 # rql is free software: you can redistribute it and/or modify it under the
@@ -289,10 +289,22 @@
28 self.assertEqual(tree.as_string(), 'Any X,Y') 29 tree.recover() 30 tree.check_references() 31 self.assertEqual(tree.as_string(), 'Any X,Y GROUPBY X,Y') 32 33 + def test_recover_add_type_restriction_is_in(self): 34 + tree = self._parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'") 35 + annotator.annotate(tree) # needed to get typerel index 36 + tree.save_state() 37 + select = tree.children[0] 38 + x = select.get_selected_variables().next() 39 + select.add_type_restriction(x.variable, 'Company') 40 + self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Company), X name ILIKE 'A%'") 41 + tree.recover() 42 + tree.check_references() 43 + self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'") 44 + 45 def test_select_base_1(self): 46 tree = self._parse("Any X WHERE X is Person") 47 self.assertIsInstance(tree, stmts.Union) 48 select = tree.children[0] 49 self.assertEqual(select.limit, None)