Merge lp:~spud/spud/make-diamond-pick-up-attributes-of-real-vectors-and-tensors into lp:spud

Proposed by Patrick Farrell
Status: Merged
Merged at revision: 510
Proposed branch: lp:~spud/spud/make-diamond-pick-up-attributes-of-real-vectors-and-tensors
Merge into: lp:spud
Diff against target: 111 lines (+39/-6)
5 files modified
diamond/diamond/attributewidget.py (+1/-1)
diamond/diamond/mixedtree.py (+20/-3)
diamond/diamond/tree.py (+7/-0)
diamond/tests/schema/first.rnc (+4/-1)
diamond/tests/schema/first.rng (+7/-1)
To merge this branch: bzr merge lp:~spud/spud/make-diamond-pick-up-attributes-of-real-vectors-and-tensors
Reviewer Review Type Date Requested Status
David Ham Approve
Review via email: mp+83962@code.launchpad.net

Description of the change

Found a major bug in Diamond's interface, pointed out by Dan Barker.

In the MixedTree class (used to hide real_value and stuff like that from the user), the attributes came solely from the parent. But the child (real_value) element also could have attributes the user must set -- but these were never displayed, and could never be set.

To test this, take a look at the first.rng included with this commit, with Diamond before and after this change. In particular, real_vector and real_tensor have /never/ worked, despite being in the spud_base schema.

To post a comment you must log in.
Revision history for this message
David Ham (david-ham) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'diamond/diamond/attributewidget.py'
2--- diamond/diamond/attributewidget.py 2011-07-28 12:30:12 +0000
3+++ diamond/diamond/attributewidget.py 2011-11-30 15:31:25 +0000
4@@ -86,7 +86,7 @@
5
6 self.node = node
7
8- if node is None or not node.attrs.keys():
9+ if node is None or node.all_attrs_fixed():
10 self.set_property("visible", False)
11 else:
12 self.set_property("visible", True)
13
14=== modified file 'diamond/diamond/mixedtree.py'
15--- diamond/diamond/mixedtree.py 2011-07-30 04:36:33 +0000
16+++ diamond/diamond/mixedtree.py 2011-11-30 15:31:25 +0000
17@@ -30,7 +30,7 @@
18
19 self.name = parent.name
20 self.schemaname = parent.schemaname
21- self.attrs = self.parent.attrs
22+ self.attrs = dict(self.parent.attrs.items() + self.child.attrs.items())
23 self.children = parent.children
24 self.datatype = child.datatype
25 self.data = child.data
26@@ -40,12 +40,22 @@
27 return
28
29 def set_attr(self, attr, val):
30- self.parent.set_attr(attr, val)
31+ if attr in self.parent.attrs:
32+ self.parent.set_attr(attr, val)
33+ elif attr in self.child.attrs:
34+ self.child.set_attr(attr, val)
35+ else:
36+ raise Exception, "Attribute not present in either parent or child!"
37
38 return
39
40 def get_attr(self, attr):
41- return self.parent.get_attr(attr)
42+ if attr in self.parent.attrs:
43+ self.parent.get_attr(attr)
44+ elif attr in self.child.attrs:
45+ self.child.get_attr(attr)
46+ else:
47+ raise Exception, "Attribute not present in either parent or child!"
48
49 def set_data(self, data):
50 self.child.set_data(data)
51@@ -197,3 +207,10 @@
52
53 def is_sliceable(self):
54 return True
55+
56+ def all_attrs_fixed(self):
57+ for attr in self.attrs:
58+ if self.attrs[attr][0] != "fixed":
59+ return False
60+
61+ return True
62
63=== modified file 'diamond/diamond/tree.py'
64--- diamond/diamond/tree.py 2011-09-01 14:59:55 +0000
65+++ diamond/diamond/tree.py 2011-11-30 15:31:25 +0000
66@@ -540,6 +540,13 @@
67
68 def __repr__(self):
69 return self.get_name_path()
70+
71+ def all_attrs_fixed(self):
72+ for attr in self.attrs:
73+ if self.attrs[attr][0] != "fixed":
74+ return False
75+
76+ return True
77
78 gobject.type_register(Tree)
79
80
81=== modified file 'diamond/tests/schema/first.rnc'
82--- diamond/tests/schema/first.rnc 2008-06-23 14:35:46 +0000
83+++ diamond/tests/schema/first.rnc 2011-11-30 15:31:25 +0000
84@@ -1,3 +1,6 @@
85+include "spud_base.rnc"
86+
87 start = element test {
88- empty
89+ element example_real_tensor { real_tensor },
90+ element example_real_vector { real_vector }
91 }
92
93=== modified file 'diamond/tests/schema/first.rng'
94--- diamond/tests/schema/first.rng 2008-06-23 14:35:46 +0000
95+++ diamond/tests/schema/first.rng 2011-11-30 15:31:25 +0000
96@@ -1,8 +1,14 @@
97 <?xml version="1.0" encoding="UTF-8"?>
98 <grammar xmlns="http://relaxng.org/ns/structure/1.0">
99+ <include href="spud_base.rng"/>
100 <start>
101 <element name="test">
102- <empty/>
103+ <element name="example_real_tensor">
104+ <ref name="real_tensor"/>
105+ </element>
106+ <element name="example_real_vector">
107+ <ref name="real_vector"/>
108+ </element>
109 </element>
110 </start>
111 </grammar>

Subscribers

People subscribed via source and target branches