Commit 995869124e0ec86b57dcf4a758fc83531242358e

Authored by Jürgen Knödlseder
1 parent c495b3a4

Include Python example scripts in unit tests (#1803)

.gitignore
... ... @@ -5,9 +5,6 @@ depcomp
5 5 pyext/build/
6 6 .libs
7 7 .deps
8   -test/*.fits
9   -test/.samp
10   -examples/python/*.fits
11 8 inst/cta/test/*.xml
12 9 inst/cta/test/*.fits
13 10 inst/cta/test/*.fits.gz
... ... @@ -81,29 +78,7 @@ src/template/test_GClass
81 78 doc/Doxyfile.bak
82 79 testconf.sh
83 80  
84   -test/test_url.dat
85   -test/*.xml
86   -test/reports/*.xml
87   -test/*.trs
88   -test/region.reg
89   -test/test_python.sh
90   -test/test_examples.sh
91   -test/test_csv*.dat
92   -test/dev/*.fits
93   -test/dev/*.xml
94   -
95   -examples/python/*.xml
96   -examples/python/*.html
97   -examples/cpp/createfits
98   -examples/cpp/createskymap
99   -examples/cpp/createxml
100   -examples/cpp/readmodel
101   -examples/cpp/numerics
102   -examples/cpp/optimize
103   -examples/cpp/interpolate
104   -examples/cpp/readmodel
105   -
106   -# Binaries
  81 +# Test folder
107 82 test/test_GApplication
108 83 test/test_GFits
109 84 test/test_GMatrix
... ... @@ -123,4 +98,26 @@ test/test_LAT
123 98 test/test_MWL
124 99 test/test_CTA
125 100 test/test_COM
  101 +test/region.reg
  102 +test/.samp
126 103 test/test_python.sh
  104 +test/test_examples.sh
  105 +test/*.fits
  106 +test/*.xml
  107 +test/*.trs
  108 +test/*.html
  109 +test/test_csv*.dat
  110 +test/test_url.dat
  111 +test/reports/*.xml
  112 +test/dev/*.fits
  113 +test/dev/*.xml
  114 +
  115 +# Examples folder
  116 +examples/cpp/createfits
  117 +examples/cpp/createskymap
  118 +examples/cpp/createxml
  119 +examples/cpp/readmodel
  120 +examples/cpp/numerics
  121 +examples/cpp/optimize
  122 +examples/cpp/interpolate
  123 +examples/cpp/readmodel
... ...
ChangeLog
1   -2016-06-23 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
  1 +2016-06-24 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2  
3 3 * Version 1.1.0 released
4 4 =========================
5 5  
6 6 Correct Makefile for example executables (#1806)
  7 + Include examples in unit tests (#1803)
7 8 Handle additional columns in GArf class
8 9 GCTAAeff2D no longer extrapolates beyond response table (#1784)
9 10 Add GWcsSIN projection class (#1798)
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -23 June 2016
  5 +24 June 2016
6 6  
7 7  
8 8 1. Introduction
... ...
README.md
1 1 GammaLib information
2 2 ====================
3   -* Version: 1.1.0.dev1 (23 June 2016)
  3 +* Version: 1.1.0.dev1 (24 June 2016)
4 4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu)
5 5  
6 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/)
... ... @@ -178,7 +178,7 @@ extensive unit test by typing:
178 178 If everything works successfully you should see
179 179  
180 180 ===================
181   - All 20 tests passed
  181 + All 21 tests passed
182 182 ===================
183 183  
184 184 or
... ... @@ -186,8 +186,8 @@ or
186 186 ============================================================================
187 187 Testsuite summary for gammalib 1.1.0.dev1
188 188 ============================================================================
189   - # TOTAL: 20
190   - # PASS: 20
  189 + # TOTAL: 21
  190 + # PASS: 21
191 191 # SKIP: 0
192 192 # XFAIL: 0
193 193 # FAIL: 0
... ...
examples/python/xml_html_create.py
1 1 #! /usr/bin/env python
2 2 # ==========================================================================
3   -# Scope
  3 +# Creates a simple HTML Web page using GammaLib's xml module
4 4 #
5   -# This script creates a simple HTML Web page using GammaLib's xml module
6   -#
7   -# Usage
8   -# ./xml_html_create.py
9   -#
10   -# -------------------------------------------------------------------------
11   -#
12   -# Copyright (C) 2013 Juergen Knoedlseder
  5 +# Copyright (C) 2013-2016 Juergen Knoedlseder
13 6 #
14 7 # This program is free software: you can redistribute it and/or modify
15 8 # it under the terms of the GNU General Public License as published by
... ... @@ -100,9 +93,7 @@ def show_xml(xml):
100 93 # Main routine entry point #
101 94 # ======================== #
102 95 if __name__ == '__main__':
103   - """
104   - This script creates a simple HTML Web page using GammaLib's xml module.
105   - """
  96 +
106 97 # Create HTML XML document
107 98 xml = create_html()
108 99  
... ... @@ -110,4 +101,4 @@ if __name__ == &#39;__main__&#39;:
110 101 show_xml(xml)
111 102  
112 103 # Save HTML document
113   - xml.save("gammalib.html")
  104 + xml.save('example_html_create.html')
... ...
test/test_examples.py
... ... @@ -39,7 +39,8 @@ class Test(gammalib.GPythonTestSuite):
39 39 gammalib.GPythonTestSuite.__init__(self)
40 40  
41 41 # Examples directory
42   - self._dir = '../examples/cpp/'
  42 + self._cpp_dir = '../examples/cpp/'
  43 + self._python_dir = '../examples/python/'
43 44  
44 45 # Return
45 46 return
... ... @@ -55,11 +56,11 @@ class Test(gammalib.GPythonTestSuite):
55 56 Binary executable name.
56 57 """
57 58 # Setup command
58   - cmd = self._dir + name
  59 + cmd = self._cpp_dir + name
59 60  
60 61 # Execute binary, make sure we catch any exception
61 62 try:
62   - rc = os.system(cmd+' >/dev/null 2>&1')
  63 + rc = os.system(cmd+' > example_'+name+'.log 2>&1')
63 64 except:
64 65 pass
65 66  
... ... @@ -69,6 +70,31 @@ class Test(gammalib.GPythonTestSuite):
69 70 # Return
70 71 return
71 72  
  73 + # Execute Python script
  74 + def _execute_python(self, name):
  75 + """
  76 + Execute Python script
  77 +
  78 + Parameters
  79 + ----------
  80 + name : str
  81 + Python script name with .py extension.
  82 + """
  83 + # Setup command
  84 + cmd = self._python_dir + name + '.py'
  85 +
  86 + # Execute Python script, make sure we catch any exception
  87 + try:
  88 + rc = os.system(cmd+' > example_'+name+'.log 2>&1')
  89 + except:
  90 + pass
  91 +
  92 + # Check if execution was successful
  93 + self.test_assert(rc == 0, 'Check "'+name+'" script from command line')
  94 +
  95 + # Return
  96 + return
  97 +
72 98 # Set test functions
73 99 def set(self):
74 100 """
... ... @@ -85,6 +111,10 @@ class Test(gammalib.GPythonTestSuite):
85 111 self.append(self.test_numerics, "Test numerics")
86 112 self.append(self.test_optimize, "Test optimize")
87 113 self.append(self.test_readmodel, "Test readmodel")
  114 + self.append(self.test_matrix_howto, "Test matrix howto")
  115 + self.append(self.test_models_howto, "Test models howto")
  116 + self.append(self.test_xml_howto, "Test XML howto")
  117 + self.append(self.test_xml_html_create, "Test HTML creation")
88 118  
89 119 # Return
90 120 return
... ... @@ -180,6 +210,58 @@ class Test(gammalib.GPythonTestSuite):
180 210 # Return
181 211 return
182 212  
  213 + # Test matrix howto
  214 + def test_matrix_howto(self):
  215 + """
  216 + Test matrix howto
  217 + """
  218 + # Execute python script
  219 + self._execute_python('matrix_howto')
  220 +
  221 + #TODO: Do any testing
  222 +
  223 + # Return
  224 + return
  225 +
  226 + # Test models howto
  227 + def test_models_howto(self):
  228 + """
  229 + Test models howto
  230 + """
  231 + # Execute python script
  232 + self._execute_python('models_howto')
  233 +
  234 + #TODO: Do any testing
  235 +
  236 + # Return
  237 + return
  238 +
  239 + # Test XML howto
  240 + def test_xml_howto(self):
  241 + """
  242 + Test XML howto
  243 + """
  244 + # Execute python script
  245 + self._execute_python('xml_howto')
  246 +
  247 + #TODO: Do any testing
  248 +
  249 + # Return
  250 + return
  251 +
  252 + # Test HTML creation
  253 + def test_xml_html_create(self):
  254 + """
  255 + Test HTML creation
  256 + """
  257 + # Execute python script
  258 + self._execute_python('xml_html_create')
  259 +
  260 + #TODO: Do any testing
  261 +
  262 + # Return
  263 + return
  264 +
183 265  
184 266 # ======================== #
185 267 # Main routine entry point #
... ...
testall.sh
... ... @@ -28,19 +28,6 @@ cd test/dev
28 28 ./example_radial_models.py
29 29 cd $base
30 30  
31   -
32   -# examples/python
33   -# ===============
34   -echo
35   -echo "=====> examples/python"
36   -cd examples/python
37   -./matrix_howto.py
38   -./models_howto.py
39   -./xml_howto.py
40   -./xml_html_create.py
41   -cd $base
42   -
43   -
44 31 # inst/cta/test/dev
45 32 # =================
46 33 echo
... ... @@ -55,7 +42,6 @@ cd inst/cta/test/dev
55 42 ./test_sim_edisp.py
56 43 cd $base
57 44  
58   -
59 45 # inst/lat/test/dev
60 46 # =================
61 47 echo
... ... @@ -64,7 +50,6 @@ cd inst/lat/test/dev
64 50 #./test_python.py
65 51 cd $base
66 52  
67   -
68 53 # inst/mwl/test/dev
69 54 # =================
70 55 echo
... ... @@ -73,7 +58,6 @@ cd inst/mwl/test/dev
73 58 ./test_python.py
74 59 cd $base
75 60  
76   -
77 61 # Signal completion
78 62 # =================
79 63 echo
... ...