def assertIdentity(self, query): input_query = parseString(query) result_query = CqlIdentityVisitor(input_query).visit() self.assertEqual(input_query, result_query) input_ids = set(id(n) for n in allnodes(input_query)) result_ids = set(id(n) for n in allnodes(result_query)) self.assertEqual(0, len(input_ids.intersection(result_ids)), 'Expected new ast to be a deepcopy.')
def visitTERM(self, node): if node.children[0] == self._oldTerm: return node.__class__(self._newTerm) return CqlIdentityVisitor.visitTERM(self, node)
def doVisit(): for i in range(10): CqlIdentityVisitor(p).visit()
def __init__(self, ast, oldTerm, newTerm): CqlIdentityVisitor.__init__(self, ast) self._oldTerm = oldTerm self._newTerm = newTerm
def visitINDEX(self, node): indexTerm = node.children[0].children[0] if indexTerm in self._mapping: return INDEX(TERM(self._mapping[indexTerm])) return CqlIdentityVisitor.visitINDEX(self, node)
def __init__(self, ast, mapping): CqlIdentityVisitor.__init__(self, ast) self._mapping = mapping