Debian Codegraph @

tests/structscaffold.py

raw
1 """
2 Some structures for unit tests.
3
4 (in particular in attrdeftest and structuretest).
5 """
6
7 #c Copyright 2008-2025, the GAVO project <[email protected]>
8 #c
9 #c This program is free software, covered by the GNU GPL. See the
10 #c COPYING file in the source distribution.
11
12 from gavo import base
13 from gavo.base.structure import Structure
14
15
16 class Child(Structure):
17 name_ = "child"
18 _fab = base.UnicodeAttribute("fab", default="empty", copyable=True)
19
20
21 class Child2(Structure):
22 name_ = "child2"
23 _fab = base.UnicodeAttribute("romp")
24
25
26 class Color(Structure):
27 name_ = "color"
28 _r = base.IntAttribute("r", 255, copyable=True)
29 _g = base.IntAttribute("g", 255, copyable=True)
30 _b = base.FloatAttribute("b", 255, copyable=True)
31
32 class CopyableColor(Color):
33 _orig = base.OriginalAttribute(forceType=Color)
34
35
36 class Foo(Structure):
37 name_ = "foo"
38 _color = base.StructAttribute(
39 "color",
40 childFactory=Color,
41 copyable=True,
42 default=None)
43 _name = base.UnicodeAttribute("name", default=base.Undefined, copyable=True)
44 _content = base.DataContent(copyable=True)
45
46
47 class Foos(Structure):
48 name_ = "foos"
49 _content = base.StructListAttribute("plups", Foo)
50
51
52 class Bla(Structure):
53 name_ = "bla"
54 _att1 = base.ListOfAtomsAttribute("items",
55 itemAttD=base.IntAttribute("item"), copyable=True)
56
57
58 class Palette(Structure):
59 name_ = "pal"
60 _map = base.StringListAttribute("map", copyable=True)
61 _flavor = base.UnicodeAttribute("flavor")
62 _colors = base.StructListAttribute("colors", childFactory=CopyableColor,
63 copyable=True)
64 _foo = base.StructListAttribute("foos", childFactory=Foo, copyable=True)
65
66
67 class PalCollection(Structure):
68 name_ = "pals"
69 _pals = base.StructListAttribute("pals", childFactory=Palette)
70
71
72 class Image(Structure):
73 name_ = "image"
74 _pal = base.ReferenceAttribute("pal",
75 default=True,
76 forceType=Palette,
77 copyable=True)
78 _calib = base.ListOfAtomsAttribute("calibs",
79 itemAttD=base.UnicodeAttribute("calib"), copyable=True)
80 _orig = base.OriginalAttribute()
81 _maps = base.DictAttribute("maps", keyName="from", copyable=True,
82 itemAttD=base.UnicodeAttribute("map"))
83 _revs = base.DictAttribute("rev", keyName="to", inverted=True)
84
85
86 class Root(Structure):
87 name_ = "root"
88 _ims = base.StructListAttribute("ims", childFactory=Image, copyable=True)
89 _pals = base.StructListAttribute("pals", childFactory=Palette,
90 copyable=True)