FLEXPART Testing Environment CTBTO WO8
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
distrotest.TestSuite.TestSuite Class Reference
Inheritance diagram for distrotest.TestSuite.TestSuite:
Inheritance graph
[legend]
Collaboration diagram for distrotest.TestSuite.TestSuite:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def get_distribution_list
 

Private Member Functions

def _create_distribution
 
def _create_met_case
 
def _create_run_case
 
def _create_basic_test
 

Private Attributes

 _xml_files
 
 _distribution_list
 

Detailed Description

Container for an entire test suite, initialised from an XML config file.
A TestSuite object contains Distribution classes, which in turn will each 
contain MetCase, RunCase and BasicTest objects.  A TestSuite object should 
have all of the information necessary for testing routines to do their
thang.

Definition at line 29 of file TestSuite.py.

Constructor & Destructor Documentation

def distrotest.TestSuite.TestSuite.__init__ (   self,
  xml_files = None 
)
Creates a list of Distribution objects from a list of xml_files.
If only a single file is entered as an argument (which may often
be the case), it is inserted into a list of one element.  An XML file
is read, and a Distribution object is manufactured from this

Definition at line 39 of file TestSuite.py.

39 
40  def __init__(self, xml_files=None):
41 
42  """
43  Creates a list of Distribution objects from a list of xml_files.
44  If only a single file is entered as an argument (which may often
45  be the case), it is inserted into a list of one element. An XML file
46  is read, and a Distribution object is manufactured from this
47  """
48 
49  if xml_files:
50  if type(xml_files) is str:
51  self._xml_files = [xml_files]
52  elif type(xml_files) is list:
53  self._xml_files = xml_files
54  else:
55  raise Exception('xml_files should be a list')
56  else:
57  raise Exception('A list of valid xml_files is needed')
58 
59  # If we are here, we have our XML file list, and we should load the
60  # contents of each one into a Distribution object
61  self._distribution_list = []
62  for the_xml_file in self._xml_files:
63 
64  # print the_xml_file
65  try:
66  #print 'hello'
67  distro_tree = XMLTree.parse(the_xml_file)
68  #print distro_tree
69 
70  except:
71  print 'Error parsing XML file: ' + str(the_xml_file)
72  raise Exception
73 
74  distro_object = self._create_distribution(distro_tree=distro_tree)
75  self._distribution_list.append( distro_object )
76 
77 
78 

Member Function Documentation

def distrotest.TestSuite.TestSuite._create_basic_test (   self,
  basic_test_tree = None 
)
private
Creates and returns a BasicTest object based on the parsed
XML tree parameters

Definition at line 205 of file TestSuite.py.

206  def _create_basic_test(self, basic_test_tree=None):
207 
208  """ Creates and returns a BasicTest object based on the parsed
209  XML tree parameters"""
210 
211  the_basic_test = None
212  if basic_test_tree is not None:
213  basic_test_root = basic_test_tree.getchildren()
214 
215  for child in basic_test_root:
216  if child.tag == 'short_descr':
217  descr = child.text.strip()
218  elif child.tag == 'type':
219  testtype = child.text.strip()
220  elif child.tag == 'max_threshold':
221  max_threshold = child.text.strip()
222 
223  if descr and testtype and max_threshold:
224  the_basic_test = BasicTest.BasicTest(descr=descr,
225  test_type=testtype,
226  threshold=max_threshold)
227  else:
228  raise ValueError(
229  "Unable to create BasicTest object - missing args"
230  )
231 
232  return the_basic_test
233 
234 

Here is the caller graph for this function:

def distrotest.TestSuite.TestSuite._create_distribution (   self,
  distro_tree = None 
)
private
Creates and returns a distribution object (e.g. FLEXPART-ECMWF 
(nested/not nested input), FLEXPART-GFS or FLEXPART-WRF) based 
on the parsed XML distribution tree

Definition at line 82 of file TestSuite.py.

82 
83  def _create_distribution(self, distro_tree=None):
84 
85  """
86  Creates and returns a distribution object (e.g. FLEXPART-ECMWF
87  (nested/not nested input), FLEXPART-GFS or FLEXPART-WRF) based
88  on the parsed XML distribution tree
89 
90  """
91 
92  # Find the Distribution parameter and MetCase nodes and iterate
93  # through those to create the
94  # MetCase Objects (which will recursively create RunCase and
95  # BasicTest objects). This is set up, however, to permit empty
96  # metcase lists. Creates and returns a Distribution object
97 
98  the_distribution = None
99  if distro_tree:
100 
101  distro_path = parmod_path = exec_name = None
102  met_case_list = []
103  distro_root = distro_tree.getroot()
104  for child in distro_root:
105  if child.tag == 'metcase':
106  the_met_case = self._create_met_case(met_case_tree=child)
107  met_case_list.append(the_met_case)
108  elif child.tag == 'short_descr':
109  descr = child.text.strip()
110  elif child.tag == 'distropath':
111  distro_path = child.text.strip()
112  elif child.tag == 'parmodpath':
113  parmod_path = child.text.strip()
114  elif child.tag == 'execname':
115  exec_name = child.text.strip()
116 
117 
118  if descr and distro_path and exec_name:
119  the_distribution = Distribution.Distribution(
120  descr=descr,
121  distro_path=distro_path,
122  parmod_path=parmod_path,
123  exec_name=exec_name,
124  met_case_list=met_case_list
125  )
126  else:
127  raise ValueError(
128  "Unable to create Distribution object - missing args"
129  )
130 
131  return the_distribution
132 

Here is the call graph for this function:

def distrotest.TestSuite.TestSuite._create_met_case (   self,
  met_case_tree = None 
)
private
Creates and returns a MetCase object based on the parsed XML
tree.  This will read in the parameters for a MetCase object, as
well as RunCase objects, if available.  Otherwise, inserts an empty
RunCase list

Definition at line 133 of file TestSuite.py.

134  def _create_met_case(self, met_case_tree=None):
135 
136  """ Creates and returns a MetCase object based on the parsed XML
137  tree. This will read in the parameters for a MetCase object, as
138  well as RunCase objects, if available. Otherwise, inserts an empty
139  RunCase list"""
140 
141  the_met_case = None
142  metnestfile_dir = None
143  if met_case_tree is not None:
144  run_case_list = []
145  met_case_root = met_case_tree.getchildren()
146  for child in met_case_root:
147  if child.tag == 'runcase':
148  the_run_case = self._create_run_case(run_case_tree=child)
149  run_case_list.append(the_run_case)
150  elif child.tag == "short_descr":
151  descr = child.text.strip()
152  elif child.tag == "metfiledir":
153  metfile_dir = child.text.strip()
154  elif child.tag == "metnestfiledir":
155  metnestfile_dir = child.text.strip()
156 
157  if descr and metfile_dir:
158  the_met_case = MetCase.MetCase(descr=descr,
159  metfile_dir=metfile_dir,
160  metnestfile_dir=metnestfile_dir,
161  run_case_list=run_case_list)
162  else:
163  raise ValueError(
164  "Unable to create MetCase object - missing args"
165  )
166 
167  return the_met_case

Here is the call graph for this function:

Here is the caller graph for this function:

def distrotest.TestSuite.TestSuite._create_run_case (   self,
  run_case_tree = None 
)
private
Creates and returns a RunCase object based on the parsed XML tree.
This will read in the parameters for runcase objects, as
well as BasicTest objects, if available.  Otherwise, inserts and
empty BasicTest list

Definition at line 168 of file TestSuite.py.

169  def _create_run_case(self, run_case_tree=None):
170  """Creates and returns a RunCase object based on the parsed XML tree.
171  This will read in the parameters for runcase objects, as
172  well as BasicTest objects, if available. Otherwise, inserts and
173  empty BasicTest list"""
174 
175  the_run_case = None
176  if run_case_tree is not None:
177  descr = testtype = max_threshold = None
178 
179  basic_test_list = []
180  run_case_root = run_case_tree.getchildren()
181  for child in run_case_root:
182  if child.tag == 'basictest':
183  the_basic_test = self._create_basic_test(basic_test_tree=child)
184  basic_test_list.append(the_basic_test)
185  elif child.tag == 'short_descr':
186  descr = child.text.strip()
187  elif child.tag == 'casedir':
188  case_dir = child.text.strip()
189  elif child.tag == 'controldatadir':
190  control_data_dir = child.text.strip()
191 
192 
193  if descr and case_dir and control_data_dir:
194  the_run_case = RunCase.RunCase(descr=descr,
195  case_dir=case_dir,
196  control_data_dir=control_data_dir,
197  test_list=basic_test_list)
198  else:
199  raise ValueError(
200  "Unable to create RunCase object - missing args"
201  )
202 
203  return the_run_case
204 

Here is the call graph for this function:

Here is the caller graph for this function:

def distrotest.TestSuite.TestSuite.get_distribution_list (   self)

Definition at line 79 of file TestSuite.py.

79 
80  def get_distribution_list(self):
81  return self._distribution_list

Member Data Documentation

distrotest.TestSuite.TestSuite._distribution_list
private

Definition at line 60 of file TestSuite.py.

distrotest.TestSuite.TestSuite._xml_files
private

Definition at line 50 of file TestSuite.py.


The documentation for this class was generated from the following file: