17
17
# this program. If not, see <http://www.gnu.org/licenses/>.
18
18
# -----------------------------------------------------------------------------
20
#If True, the TreeTester will automatically reorder node on the same level
21
#as a deleted node. If False, it means that Liblarch has the responsability
22
#to handle that itself.
20
# If True, the TreeTester will automatically reorder node on the same level
21
# as a deleted node. If False, it means that Liblarch has the responsability
22
# to handle that itself.
23
23
REORDER_ON_DELETE = False
30
30
def __init__(self, viewtree):
31
31
self.tree = viewtree
32
#both dict should always be synchronized
33
#They are the internal representation of the tree,
34
#based only on received signals
32
# both dict should always be synchronized
33
# They are the internal representation of the tree,
34
# based only on received signals
37
37
self.tree.register_cllbck('node-added-inview', self.add)
56
56
self.paths[path] = nid
58
58
def delete(self, nid, path):
59
self.trace += "removing %s from path %s\n" %(nid, str(path))
59
self.trace += "removing %s from path %s\n" % (nid, str(path))
60
60
if nid != self.paths.get(path, None):
61
error = '%s is not assigned to path %s\n'%(nid, str(path))
61
error = '%s is not assigned to path %s\n' % (nid, str(path))
62
62
error += self.print_tree()
63
63
raise Exception(error)
64
64
if path not in self.nodes.get(nid, []):
79
79
assert path_prefix + (index, ) == path, "%s vs %s" % (
80
path_prefix + (index, ), path)
80
path_prefix + (index, ), path)
82
82
def check_prefix(path):
83
83
""" Is this path affected by the change?
107
107
new_path = list(path)
108
108
print "new_path: %s" % str(new_path)
109
109
index = len(path_prefix)
110
new_path[index] = str(int(new_path[index])-1)
110
new_path[index] = str(int(new_path[index]) - 1)
111
111
new_path = tuple(new_path)
113
113
print "new_path: %s" % str(new_path)
141
141
# if path not in self.nodes[n] or n != nid:
142
142
# raise Exception('Mismatching node for path %s'%str(p))
144
#Because of the asynchronousness of update, this test
145
#doesn't work anymore
144
# Because of the asynchronousness of update, this test
145
# doesn't work anymore
148
148
def reordered(self, nid, path, neworder):
149
149
print "reordering"
150
150
self.trace += "reordering children of %s (%s) : %s\n" % (nid,
152
self.trace += "VR is %s\n" %self.tree.node_all_children()
153
self.trace += "VR is %s\n" % self.tree.node_all_children()
158
#we first update self.nodes with the new paths
159
# we first update self.nodes with the new paths
159
160
while i < len(neworder):
160
161
if i != neworder[i]:
161
162
old = neworder[i]
169
170
newpp = newp + pp[le:]
170
171
self.nodes[n].append(newpp)
171
172
self.trace += " change %s path from %s to %s\n" % (
173
174
newpaths[newpp] = n
174
175
toremove.append(pp)
176
#now we can update self.paths
177
# now we can update self.paths
177
178
for p in toremove:
178
179
self.paths.pop(p)
179
180
for p in newpaths:
180
self.trace += " adding %s to paths %s\n" %(newpaths[p], str(p))
181
self.trace += " adding %s to paths %s\n" % (newpaths[p], str(p))
181
182
self.paths[p] = newpaths[p]
183
184
def test_validity(self):
184
185
for n in self.nodes.keys():
185
186
paths = self.tree.get_paths_for_node(n)
186
187
if len(self.nodes[n]) == 0:
187
raise Exception('Node %s is stored without any path'%n)
188
raise Exception('Node %s is stored without any path' % n)
188
189
for p in self.nodes[n]:
189
190
if self.paths[p] != n:
190
raise Exception('Mismatching path for %s'%n)
191
raise Exception('Mismatching path for %s' % n)
191
192
if p not in paths:
192
error = 'we have a unknown stored path for %s\n' %n
193
error = 'we have a unknown stored path for %s\n' % n
193
194
nn = self.tree.get_node_for_path(p)
194
195
parent = self.tree.get_node_for_path(p[:-1])
195
error += ' path %s is the path of %s\n' %(str(p), str(nn))
196
error += ' path %s is the path of %s\n' % (
196
198
error += ' parent is %s' % parent
197
199
# error += self.trace
198
200
raise Exception(error)
200
202
if len(paths) > 0:
201
raise Exception('why is this path existing for %s' %n)
203
raise Exception('why is this path existing for %s' % n)
202
204
for p in self.paths.keys():
203
205
node = self.tree.get_node_for_path(p)
204
206
n = self.paths[p]
206
208
error = 'Node for path is %s but should be %s' % (node, n)
207
209
raise Exception(error)
208
210
if p not in self.nodes[n]:
209
error = 'Mismatching node for path %s\n'%str(p)
211
error = 'Mismatching node for path %s\n' % str(p)
210
212
error += self.print_tree()
211
213
raise Exception(error)
212
214
if len(p) == 1 and len(self.nodes[n]) > 1:
213
error = 'Node %s has multiple paths and is in the VR\n' %n
215
error = 'Node %s has multiple paths and is in the VR\n' % n
214
216
error += self.print_tree()
215
217
raise Exception(error)
218
220
def print_tree(self):
220
st += "nodes are %s\n" %self.nodes
221
st += "paths are %s\n" %self.paths
222
st += "nodes are %s\n" % self.nodes
223
st += "paths are %s\n" % self.paths