HPS-MC
test_component.py
Go to the documentation of this file.
1 import unittest
2 import os
3 import configparser
4 
5 from hpsmc.component import Component
6 
7 
8 class TestComponent(unittest.TestCase):
9 
10  def test_init(self):
11  component = Component('component_name')
12  self.assertEqual(component.name, 'component_name')
13  self.assertEqual(component.seed, 1)
14  self.assertEqual(component.inputs, [])
15  self.assertEqual(component.outputs, None)
16  self.assertEqual(component.ignore_job_params, [])
17  self.assertEqual(component.hpsmc_dir, os.getenv("HPSMC_DIR", None))
18 
20  component = Component('component_name')
21  self.assertEqual(component.required_parameters(), [])
22 
24  component = Component('component_name')
25  self.assertEqual(component.optional_parameters(), ['nevents', 'seed'])
26 
28  component = Component('component_name')
29  self.assertEqual(component.required_config(), [])
30 
31  def test_input_files(self):
32  component = Component('component_name', inputs=['input1', 'input2'])
33  self.assertEqual(component.input_files(), ['input1', 'input2'])
34 
36  component = Component('component_name', inputs=['input1.stdhep', 'input2.stdhep'])
37  self.assertEqual(component._inputs_to_outputs(), ['input1.stdhep', 'input2.stdhep'])
38 
40  component = Component('component_name', inputs=['input1.stdhep', 'input2.stdhep'])
41  component.append_tok = 'tok'
42  component.output_ext = '.ext'
43  self.assertEqual(component._inputs_to_outputs(), ['input1_tok.ext', 'input2_tok.ext'])
44 
45  def test_output_files(self):
46  component = Component('component_name', outputs=['output1', 'output2'])
47  self.assertEqual(component.output_files(), ['output1', 'output2'])
48 
50  component = Component('component_name', inputs=['input1.stdhep', 'input2.stdhep'])
51  component.append_tok = 'tok'
52  component.output_ext = '.ext'
53  self.assertEqual(component.output_files(), ['input1_tok.ext', 'input2_tok.ext'])
54 
56  component = Component('component_name')
57  component.set_parameters({'nevents': 10, 'seed': 2})
58  self.assertEqual(component.nevents, 10)
59  self.assertEqual(component.seed, 2)
60 
62  component = Component('component_name', ignore_job_params=['nevents'])
63  component.set_parameters({'nevents': 10, 'seed': 2})
64  self.assertEqual(component.nevents, None)
65  self.assertEqual(component.seed, 2)
66 
67  def test_config(self):
68  component = Component('Component')
69  parser = configparser.ConfigParser()
70  config_file = ['test_helpers/.hpsmc_test_cfg']
71  parser.read(config_file)
72  component.config(parser)
73  self.assertEqual(component.hps_java_bin_jar, 'some/path/to/hps-java-bin.jar')
74  self.assertEqual(component.lcio_bin_jar, 'some/path/to/lcio-bin.jar')
75 
76  def test_cmd_args(self):
77  component = Component('component_name')
78  self.assertEqual(component.cmd_args(), [])
79 
80  def test_cmd_line_str(self):
81  component = Component('component_name', command='some_command')
82  self.assertEqual(component.cmd_line_str(), 'some_command')
83 
84 
85 if __name__ == '__main__':
86  unittest.main()
Base class for components in a job.
Definition: component.py:15