Debian Codegraph @

tests/stcxvaltest.py

raw
1 """
2 STC tests requiring XSD validation (slow...)
3 """
4
5 #c Copyright 2008-2025, the GAVO project <[email protected]>
6 #c
7 #c This program is free software, covered by the GNU GPL. See the
8 #c COPYING file in the source distribution.
9
10
11 from gavo.helpers import testhelpers
12
13 from gavo import stc
14 from gavo.stc import stcxgen
15
16
17 class StanValidationTests(testhelpers.VerboseTest, testhelpers.XSDTestMixin):
18 """tests for generation of XSD-valid documents from the xml stan.
19 """
20 def testExample1(self):
21 S = stc.STC
22 tree = S.STCResourceProfile[
23 S.AstroCoordSystem(id="TT-ICRS-CXO")[
24 S.TimeFrame[
25 S.Name["Time"],
26 S.TimeScale["TT"],
27 S.TOPOCENTER],
28 S.SpaceFrame[
29 S.Name["Space"],
30 S.ICRS,
31 S.TOPOCENTER,
32 S.SPHERICAL],
33 S.SpectralFrame[
34 S.Name["Energy"],
35 S.TOPOCENTER]],
36 S.AstroCoords(coord_system_id="TT-ICRS-CXO")[
37 S.Time[
38 S.Name["Time"],
39 S.Error[0.000005],
40 S.Error[0.0001],
41 S.Resolution[0.000016],
42 S.Resolution["3.0"],
43 S.Size["1000"],
44 S.Size[170000]],
45 S.Position2D(unit="arcsec")[
46 S.Name["Position"],
47 S.Error2Radius[1.0],
48 S.Resolution2Radius[0.5],
49 S.Size2[
50 S.C1[1000],
51 S.C2[1000]],
52 S.Size2[
53 S.C1[1000],
54 S.C2[1000]]],
55 S.Spectral(unit="keV")[
56 S.Name["Energy"],
57 S.Error[0.1],
58 S.Resolution[0.02],
59 S.Resolution[2.0],
60 S.Size[2],
61 S.Size[10]]],
62 S.AstroCoordArea(id="AllSky-CXO", coord_system_id="TT-ICRS-CXO")[
63 S.TimeInterval[
64 S.StartTime[
65 S.Timescale["TT"],
66 S.ISOTime["1999-07-23T16:00:00"]]],
67 S.AllSky(fill_factor="0.02"),
68 S.SpectralInterval(unit="keV")[
69 S.LoLimit[0.12],
70 S.HiLimit[10.0]]]]
71 self.assertValidates(tree.render(), leaveOffending=__name__=="__main__")
72
73
74 class STCSValidationTests(testhelpers.VerboseTest, testhelpers.XSDTestMixin):
75 """tests for generation of XSD-valid documents from STC-S
76 """
77 def assertFromSTCSValidates(self, stcsLiteral):
78 ast = stc.parseSTCS(stcsLiteral)
79 tree = stcxgen.astToStan(ast, stc.STC.STCResourceProfile)
80 self.assertValidates(tree.render(),leaveOffending=__name__=="__main__")
81
82 def testSimpleCoos(self):
83 self.assertFromSTCSValidates("Time TT 2009-03-10T09:56:10.015625"
84 " Spectral NEPTUNE 12 unit Angstrom Error 4 3"
85 " Redshift TOPOCENTER VELOCITY RELATIVISTIC 0.1")
86
87 def testComplexCoos(self):
88 self.assertFromSTCSValidates("Time TT 2009-03-10T09:56:10.015625 unit s"
89 " Error 0.0001 0.0002 Resolution 0.0001 PixSize 2")
90
91 def testComplexSpaceCoos(self):
92 self.assertFromSTCSValidates("Position ICRS 12000.3 14000 unit arcsec"
93 " Error 0.1 0.14 Resolution 0.5 0.5 Size 1 1.1 4.8 2.3 PixSize 0.2 0.25")
94
95 def test1DIntervals(self):
96 self.assertFromSTCSValidates("TimeInterval TT 2009-03-10T09:56:10.015625"
97 " PositionInterval UNKNOWNFrame CART1 1 2 unit mm"
98 " SpectralInterval 1e10 1e11 unit Hz"
99 " RedshiftInterval 1000 7500 unit km/s")
100
101 def test2DInterval(self):
102 self.assertFromSTCSValidates("PositionInterval ICRS 12 13 14 15 Error 1 2")
103
104 def test3DInterval(self):
105 self.assertFromSTCSValidates(
106 "Time TT 2000-01-01T12:00:00"
107 " PositionInterval ECLIPTIC CART3 12 13 10 14 15 9")
108
109 def testAllSky(self):
110 self.assertFromSTCSValidates("AllSky ICRS")
111
112 def testCircles(self):
113 self.assertFromSTCSValidates("Circle ICRS 12 13 1")
114 self.assertFromSTCSValidates("Circle UNKNOWNFrame CART3 12 13 1 4")
115
116 def testEllipse(self):
117 self.assertFromSTCSValidates("Ellipse ICRS 12 13 1 0.75 0")
118
119 def testBox(self):
120 self.assertFromSTCSValidates("Box fillfactor 0.1 ICRS 70 190 23 18")
121
122 def testPolygon(self):
123 self.assertFromSTCSValidates("Polygon ICRS 70 190 23 18 12 45"
124 " 30 -10")
125
126 def testConvex(self):
127 self.assertFromSTCSValidates("Convex ICRS 70 190 23 0.125 12 45"
128 " 30 -0.25")
129
130 def testSimpleUnion(self):
131 self.assertFromSTCSValidates("Union ICRS (Circle 10 10 2 Box 11 11 2 3"
132 " Ellipse 12 13 1 0.75 0)")
133
134 def testInsaneRegion(self):
135 self.assertFromSTCSValidates(
136 "Difference ICRS (AllSky Union (Circle 10 10 2"
137 " Intersection (Polygon 10 2 2 10 10 10 Intersection( Ellipse 11 11 2 3 30"
138 " Not (Difference (Circle 12 12 3 Box 11 11 2 3))))))")
139
140 if __name__=="__main__":
141 testhelpers.main(STCSValidationTests)