1 # Copyright (C) 2013-2017 Roland Lutz
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 def throws(fun
, *args
):
23 except Exception as e
:
26 rev
= xorn
.storage
.Revision()
27 rev1
= xorn
.storage
.Revision()
28 ob
= rev
.add_object(xorn
.storage
.Box())
29 ob1
= rev
.add_object(xorn
.storage
.Box())
30 sel
= xorn
.storage
.select_object(ob
)
32 rp
= xorn
.proxy
.RevisionProxy(rev
)
33 rp1
= xorn
.proxy
.RevisionProxy(rev1
)
34 op
= xorn
.proxy
.ObjectProxy(rev
, ob
)
35 op1
= xorn
.proxy
.ObjectProxy(rev
, ob1
)
36 ap
= xorn
.proxy
.AttributeProxy(rev
, ob
, 'line')
37 ap1
= xorn
.proxy
.AttributeProxy(rev
, ob
, 'invalid_attribute')
41 assert xorn
.proxy
.RevisionProxy(rev
) == rp
42 assert xorn
.proxy
.RevisionProxy(rev
) != rp1
43 assert xorn
.proxy
.RevisionProxy(rev1
) != rp
44 assert xorn
.proxy
.RevisionProxy(rev1
) == rp1
46 assert hash(xorn
.proxy
.RevisionProxy(rev
)) == hash(rp
)
47 assert hash(xorn
.proxy
.RevisionProxy(rev
)) != hash(rp1
)
48 assert hash(xorn
.proxy
.RevisionProxy(rev1
)) != hash(rp
)
49 assert hash(xorn
.proxy
.RevisionProxy(rev1
)) == hash(rp1
)
51 assert xorn
.proxy
.ObjectProxy(rev
, ob
) == op
52 assert xorn
.proxy
.ObjectProxy(rev
, ob
) != op1
53 assert xorn
.proxy
.ObjectProxy(rev
, ob1
) != op
54 assert xorn
.proxy
.ObjectProxy(rev
, ob1
) == op1
55 assert xorn
.proxy
.ObjectProxy(rev1
, ob
) != op
56 assert xorn
.proxy
.ObjectProxy(rev1
, ob
) != op1
57 assert xorn
.proxy
.ObjectProxy(rev1
, ob1
) != op
58 assert xorn
.proxy
.ObjectProxy(rev1
, ob1
) != op1
60 assert hash(xorn
.proxy
.ObjectProxy(rev
, ob
)) == hash(op
)
61 assert hash(xorn
.proxy
.ObjectProxy(rev
, ob
)) != hash(op1
)
62 assert hash(xorn
.proxy
.ObjectProxy(rev
, ob1
)) != hash(op
)
63 assert hash(xorn
.proxy
.ObjectProxy(rev
, ob1
)) == hash(op1
)
64 assert hash(xorn
.proxy
.ObjectProxy(rev1
, ob
)) != hash(op
)
65 assert hash(xorn
.proxy
.ObjectProxy(rev1
, ob
)) != hash(op1
)
66 assert hash(xorn
.proxy
.ObjectProxy(rev1
, ob1
)) != hash(op
)
67 assert hash(xorn
.proxy
.ObjectProxy(rev1
, ob1
)) != hash(op1
)
72 rev
.set_object_data(ob
, xorn
.storage
.Box(color
= 5))
75 assert rev
.get_object_data(ob
).color
== 7
78 assert isinstance(ap2
, xorn
.proxy
.AttributeProxy
)
81 assert ap2
.name
== 'line'
84 op
.line
= xorn
.storage
.LineAttr(width
= 2.5)
85 assert rev
.get_object_data(ob
).line
.width
== 2.5
89 except AttributeError:
94 assert 'xorn.storage.Box' in repr(op
.data())
95 assert 'xorn.storage.Box' not in repr(op
)
97 # attribute attributes
99 assert ap
.width
== 2.5
100 rev
.set_object_data(ob
, xorn
.storage
.Box(
101 line
= xorn
.storage
.LineAttr(width
= 4.5)))
102 assert ap
.width
== 4.5
104 assert rev
.get_object_data(ob
).line
.width
== 6.5
108 except AttributeError:
113 assert 'xorn.storage.LineAttr' in repr(ap
.data())
114 assert 'xorn.storage.LineAttr' not in repr(ap
)
118 assert rp
.toplevel_objects() == [op
, op1
]
119 assert rp1
.toplevel_objects() == []
121 assert rp
.all_objects() == [op
, op1
]
122 assert rp1
.all_objects() == []
124 assert rp
.selected_objects(sel
) == [op
]
125 assert rp1
.selected_objects(sel
) == []
127 op2
= rp1
.add_object(xorn
.storage
.Box())
128 assert op2
.rev
== rev1
129 assert rev1
.object_exists(op2
.ob
)
131 op3
= rp1
.copy_object(op
)
132 assert op3
.rev
== rev1
133 assert rev1
.object_exists(op3
.ob
)
135 sel4
= rp1
.copy_objects(rp
, sel
)
136 assert xorn
.storage
.selection_is_empty(rev
, sel4
) == True
137 assert xorn
.storage
.selection_is_empty(rev1
, sel4
) == False
138 op4
, = rp1
.selected_objects(sel4
)
140 rp1
.delete_object(op3
)
141 assert not rev1
.object_exists(op3
.ob
)
142 assert xorn
.storage
.selection_is_empty(rev1
, sel4
) == False
144 rp1
.delete_objects(sel4
)
145 assert xorn
.storage
.selection_is_empty(rev1
, sel4
) == True
147 assert rp
.is_transient()
149 assert not rp
.is_transient()
156 assert not op3
.exists()
157 assert not op4
.exists()
159 assert isinstance(op
.data(), xorn
.storage
.Box
)
160 assert isinstance(op1
.data(), xorn
.storage
.Box
)
161 assert isinstance(op2
.data(), xorn
.storage
.Box
)
162 assert throws(op3
.data
) == KeyError
163 assert throws(op4
.data
) == KeyError
165 assert throws(op
.set_data
, xorn
.storage
.Circle()) == ValueError
166 assert throws(op1
.set_data
, xorn
.storage
.Circle()) == ValueError
167 op2
.set_data(xorn
.storage
.Circle())
168 op3
.set_data(xorn
.storage
.Circle())
170 assert isinstance(op
.data(), xorn
.storage
.Box
)
171 assert isinstance(op1
.data(), xorn
.storage
.Box
)
172 assert isinstance(op2
.data(), xorn
.storage
.Circle
)
173 assert isinstance(op3
.data(), xorn
.storage
.Circle
)
174 assert throws(op4
.data
) == KeyError
176 assert op
.location() == (None, 0)
177 assert op1
.location() == (None, 1)
178 assert op2
.location() == (None, 0)
179 assert op3
.location() == (None, 1)
180 assert throws(op4
.location
) == KeyError
182 assert op
.attached_objects() == []
183 assert op1
.attached_objects() == []
184 assert op2
.attached_objects() == []
185 assert op3
.attached_objects() == []
186 assert throws(op4
.attached_objects
) == KeyError
188 assert throws(op
.relocate
, None, None) == ValueError
189 assert throws(op1
.relocate
, None, None) == ValueError
190 assert throws(op2
.relocate
, None, None) == None
191 assert throws(op3
.relocate
, None, None) == None
192 assert throws(op4
.relocate
, None, None) == KeyError
194 assert op
.is_selected(sel
) == True
195 assert op1
.is_selected(sel
) == False
196 assert op2
.is_selected(sel
) == False
197 assert op3
.is_selected(sel
) == False
198 assert op4
.is_selected(sel
) == False
202 assert ap
.exists() == True
203 assert ap1
.exists() == False
205 assert isinstance(ap
.data(), xorn
.storage
.LineAttr
)
206 assert throws(ap1
.data
) == AttributeError
210 assert throws(xorn
.proxy
.RevisionProxy
, None) == ValueError
211 assert throws(xorn
.proxy
.ObjectProxy
, None, ob
) == ValueError
212 assert throws(xorn
.proxy
.ObjectProxy
, rev
, None) == ValueError
213 assert throws(xorn
.proxy
.AttributeProxy
, None, ob
, 'line') == ValueError
214 assert throws(xorn
.proxy
.AttributeProxy
, rev
, None, 'line') == ValueError
215 assert throws(xorn
.proxy
.AttributeProxy
, rev
, ob
, None) == ValueError