ctools  2.0.0
 All Classes Namespaces Files Functions Variables Macros Pages
cscript_test.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # ==========================================================================
3 # This scripts performs unit tests for the xxx script.
4 #
5 # Copyright (C) [YEAR] [AUTHOR]
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # ==========================================================================
21 import os
22 import gammalib
23 import cscripts
24 from testing import test
25 
26 
27 # ========================= #
28 # Test class for xxx script #
29 # ========================= #
30 class Test(test):
31  """
32  Test class for xxx script
33 
34  This test class makes unit tests for the xxx script by using it from
35  the command line and from Python.
36  """
37 
38  # Constructor
39  def __init__(self):
40  """
41  Constructor
42  """
43  # Call base class constructor
44  test.__init__(self)
45 
46  # Return
47  return
48 
49  # Set test functions
50  def set(self):
51  """
52  Set all test functions
53  """
54  # Set test name
55  self.name('xxx')
56 
57  # Append tests
58  self.append(self._test_cmd, 'Test xxx on command line')
59  self.append(self._test_python, 'Test xxx from Python')
60  self.append(self._test_pickeling, 'Test xxx pickeling')
61 
62  # Return
63  return
64 
65  # Test xxx on command line
66  def _test_cmd(self):
67  """
68  Test xxx on the command line
69  """
70  # Set script name
71  xxx = self._script('xxx')
72 
73  # Setup xxx command
74  cmd = xxx+' logfile="xxx_cmd1.log" chatter=1'
75 
76  # Check if execution was successful
77  self.test_value(self._execute(cmd), 0,
78  'Check successful execution from command line')
79 
80  # Check xxx --help
81  self._check_help(xxx)
82 
83  # Return
84  return
85 
86  # Test xxx from Python
87  def _test_python(self):
88  """
89  Test xxx from Python
90  """
91  # Allocate xxx
92  script = cscripts.xxx()
93 
94  # Check that saving does not nothing
95  script['logfile'] = 'xxx_py0.log'
96  script.logFileOpen()
97  script.save()
98  self.test_assert(not os.path.isfile('xxx_py0.fits'),
99  'Check that no FITS file has been created')
100 
101  # Check that clearing does not lead to an exception or segfault
102  script.clear()
103 
104  # Now set xxx parameters
105  script['logfile'] = 'xxx_py1.log'
106  script['chatter'] = 2
107 
108  # Run xxx script
109  script.logFileOpen()
110  script.run()
111 
112  # Check result
113  self._check_result(script)
114 
115  # Return
116  return
117 
118  # Test xxx pickeling
119  def _test_pickeling(self):
120  """
121  Test xxx pickeling
122  """
123  # Perform pickeling test of empty class
124  self._pickeling(cscripts.xxx())
125 
126  # Setup script for pickling text
127  script = cscripts.xxx()
128  script['logfile'] = 'xxx_py1_pickle.log'
129  script['chatter'] = 2
130 
131  # Perform pickeling tests of filled class
132  obj = self._pickeling(script)
133 
134  # Run xxx script and save result
135  obj.logFileOpen() # Make sure we get a log file
136  obj.run()
137  obj.save()
138 
139  # TODO: Check result file
140 
141  # Return
142  return
143 
144  # Check xxx result
145  def _check_result(self, script):
146  """
147  Check content of script
148 
149  Parameters
150  ----------
151  script : `~cscripts.xxx`
152  xxx instance
153  """
154  # TODO: Implement test on script result
155 
156  # Return
157  return
def test
Definition: __init__.py:116