ctools  2.0.0
 All Classes Namespaces Files Functions Variables Macros Pages
ctool_test.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # ==========================================================================
3 # This scripts performs unit tests for the xxx tool.
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 ctools
24 from testing import test
25 
26 
27 # ======================= #
28 # Test class for xxx tool #
29 # ======================= #
30 class Test(test):
31  """
32  Test class for xxx tool
33 
34  This test class makes unit tests for the xxx tool 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 
61  # Return
62  return
63 
64  # Test xxx on command line
65  def _test_cmd(self):
66  """
67  Test xxx on the command line
68  """
69  # Set tool name
70  xxx = self._tool('xxx')
71 
72  # Setup xxx command
73  cmd = xxx+' logfile="xxx_cmd1.log" chatter=1'
74 
75  # Check if execution was successful
76  self.test_value(self._execute(cmd), 0,
77  'Check successful execution from command line')
78 
79  # Check xxx --help
80  self._check_help(xxx)
81 
82  # Return
83  return
84 
85  # Test xxx from Python
86  def _test_python(self):
87  """
88  Test xxx from Python
89  """
90  # Allocate xxx
91  tool = ctools.xxx()
92 
93  # Check that saving does not nothing
94  tool['logfile'] = 'xxx_py0.log'
95  tool.logFileOpen()
96  tool.save()
97  self.test_assert(not os.path.isfile('xxx_py0.fits'),
98  'Check that no FITS file has been created')
99 
100  # Check that clearing does not lead to an exception or segfault
101  tool.clear()
102 
103  # Now set xxx parameters
104  tool['logfile'] = 'xxx_py1.log'
105  tool['chatter'] = 2
106 
107  # Run xxx tool
108  tool.logFileOpen()
109  tool.run()
110 
111  # Check result
112  self._check_result(tool)
113 
114  # Copy xxx tool
115  cpy_tool = tool.copy()
116 
117  # Check result
118  self._check_result(cpy_tool)
119 
120  # Run copy of xxx tool again
121  cpy_tool['logfile'] = 'xxx_py2.log'
122  cpy_tool['chatter'] = 3
123  cpy_tool.logFileOpen()
124  cpy_tool.run()
125 
126  # Check result
127  self._check_result(cpy_tool)
128 
129  # Return
130  return
131 
132  # Check xxx result
133  def _check_result(self, tool):
134  """
135  Check content of tool
136 
137  Parameters
138  ----------
139  tool : `~ctools.xxx`
140  xxx instance
141  """
142  # TODO: Implement test on tool result
143 
144  # Return
145  return
def test
Definition: __init__.py:116