test_python.py
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /usr/bin/env python
# ==========================================================================
# This scripts performs unit tests for the GammaLib Python bindings.
#
# Copyright (C) 2012 Juergen Knoedlseder
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ==========================================================================
from gammalib import *
from math import *
import sys
import test_GApplication
import test_GLinalg
import test_GModel
import test_GNumerics
import test_GObservation
import test_GOptimizer
import test_GFits
import test_GSky
import test_GSupport
import test_GTest
import test_GXml
# Try importing CTA tests
try:
import test_CTA
has_cta = True
except:
has_cta = False
# Try importing LAT tests
try:
import test_LAT
has_lat = True
except:
has_lat = False
# Try importing MWL tests
try:
import test_MWL
has_mwl = True
except:
has_mwl = False
# ======================== #
# Main routine entry point #
# ======================== #
if __name__ == '__main__':
"""
Perform unit testing for Python interface.
"""
# Allocate test suites
suites = GTestSuites("Python interface testing")
# Allocate test suites and append them to the container
suite1 = test_GApplication.Test()
suite2 = test_GFits.Test()
suite3 = test_GLinalg.Test()
suite4 = test_GModel.Test()
suite5 = test_GNumerics.Test()
suite6 = test_GObservation.Test()
suite7 = test_GOptimizer.Test()
suite8 = test_GSky.Test()
suite9 = test_GSupport.Test()
suite10 = test_GTest.Test()
suite11 = test_GXml.Test()
# Setup unit tests
suite1.set()
suite2.set()
suite3.set()
suite4.set()
suite5.set()
suite6.set()
suite7.set()
suite8.set()
suite9.set()
suite10.set()
suite11.set()
# Append tests to container
suites.append(suite1)
suites.append(suite2)
suites.append(suite3)
suites.append(suite4)
suites.append(suite5)
suites.append(suite6)
suites.append(suite7)
suites.append(suite8)
suites.append(suite9)
suites.append(suite10)
suites.append(suite11)
# Optionally handle CTA suite
if has_cta:
suite_cta = test_CTA.Test()
suite_cta.set()
suites.append(suite_cta)
# Optionally handle LAT suite
if has_lat:
suite_lat = test_LAT.Test()
suite_lat.set()
suites.append(suite_lat)
# Optionally handle MWL suite
if has_mwl:
suite_mwl = test_MWL.Test()
suite_mwl.set()
suites.append(suite_mwl)
# Run test suite
success = suites.run()
# Save test results
suites.save("reports/GPython.xml")
# Set return code
if success:
rc = 0
else:
rc = 1
# Print a linefeed
#sys.stdout.write("\n")
# Exit with return code
sys.exit(rc)