Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / tests / cpython / storage / query_attached.py
blobbbc8a8f74d72235b3d09403fbc585a056af78899
1 # Copyright (C) 2013-2020 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.
17 import xorn.storage
19 def assert_attached_objects(rev, attached_to, result):
20 try:
21 objects = xorn.storage.get_objects_attached_to(rev, attached_to)
22 except Exception as e:
23 assert type(e) == result
24 else:
25 assert objects == result
27 try:
28 sel = xorn.storage.select_attached_to(rev, attached_to)
29 except Exception as e:
30 assert type(e) == result
31 else:
32 objects = xorn.storage.get_selected_objects(rev, sel)
33 objects.sort()
34 result = result[:]
35 result.sort()
36 assert objects == result
38 rev = xorn.storage.Revision()
39 assert rev is not None
41 N = rev.add_object(xorn.storage.Net())
42 a = rev.add_object(xorn.storage.Text())
43 b = rev.add_object(xorn.storage.Text())
45 assert N is not None
46 assert a is not None
47 assert b is not None
49 assert_attached_objects(rev, None, [N, a, b])
50 assert_attached_objects(rev, N, [])
51 assert_attached_objects(rev, a, [])
52 assert_attached_objects(rev, b, [])
54 rev.relocate_object(N, None, None)
56 assert_attached_objects(rev, None, [a, b, N])
57 assert_attached_objects(rev, N, [])
58 assert_attached_objects(rev, a, [])
59 assert_attached_objects(rev, b, [])
61 rev.relocate_object(N, None, b)
63 assert_attached_objects(rev, None, [a, N, b])
64 assert_attached_objects(rev, N, [])
65 assert_attached_objects(rev, a, [])
66 assert_attached_objects(rev, b, [])
68 rev.relocate_object(a, N, None)
70 assert_attached_objects(rev, None, [N, b])
71 assert_attached_objects(rev, N, [a])
72 assert_attached_objects(rev, a, [])
73 assert_attached_objects(rev, b, [])
75 rev.relocate_object(b, N, None)
77 assert_attached_objects(rev, None, [N])
78 assert_attached_objects(rev, N, [a, b])
79 assert_attached_objects(rev, a, [])
80 assert_attached_objects(rev, b, [])
82 rev.relocate_object(a, N, None)
84 assert_attached_objects(rev, None, [N])
85 assert_attached_objects(rev, N, [b, a])
86 assert_attached_objects(rev, a, [])
87 assert_attached_objects(rev, b, [])
89 rev.relocate_object(a, N, b)
91 assert_attached_objects(rev, None, [N])
92 assert_attached_objects(rev, N, [a, b])
93 assert_attached_objects(rev, a, [])
94 assert_attached_objects(rev, b, [])
96 rev.delete_object(b)
98 assert_attached_objects(rev, None, [N])
99 assert_attached_objects(rev, N, [a])
100 assert_attached_objects(rev, a, [])
101 assert_attached_objects(rev, b, KeyError)
103 rev.delete_object(N)
105 assert_attached_objects(rev, None, [])
106 assert_attached_objects(rev, N, KeyError)
107 assert_attached_objects(rev, a, KeyError)
108 assert_attached_objects(rev, b, KeyError)