HPS-MC
test_tools_lciotools.py
Go to the documentation of this file.
1 import unittest
2 import configparser
3 
4 from hpsmc.tools import LCIOTool, LCIOConcat, LCIOCount, LCIOMerge
5 
6 
7 class TestLCIOTool(unittest.TestCase):
8 
9  def test_init(self):
10  lcio_tool = LCIOTool()
11  self.assertEqual(lcio_tool.command, "java")
12 
14  lcio_tool = LCIOTool()
15  self.assertEqual(lcio_tool.required_parameters(), [])
16 
18  lcio_tool = LCIOTool()
19  self.assertEqual(lcio_tool.required_config(), ["lcio_bin_jar"])
20 
21  def test_config(self):
22  lcio_tool = LCIOTool()
23  parser = configparser.ConfigParser()
24  config_file = ['test_helpers/.hpsmc_test_cfg']
25  parser.read(config_file)
26  lcio_tool.config(parser)
27  self.assertEqual(lcio_tool.lcio_bin_jar, "some/path/to/lcio-bin.jar")
28 
29  def test_cmd_args(self):
30  lcio_tool = LCIOTool(name="lcio_tool")
31  parser = configparser.ConfigParser()
32  config_file = ['test_helpers/.hpsmc_test_cfg']
33  parser.read(config_file)
34  lcio_tool.config(parser)
35  self.assertEqual(lcio_tool.cmd_args(), ["-jar", "some/path/to/lcio-bin.jar", "lcio_tool"])
36 
37 
38 class TestLCIOConcat(unittest.TestCase):
39 
40  def test_init(self):
41  lcio_concat = LCIOConcat()
42  self.assertEqual(lcio_concat.name, "concat")
43  self.assertEqual(lcio_concat.command, "java")
44 
45  def test_cmd_args(self):
46  lcio_concat = LCIOConcat(inputs=["some/path/to/input1.slcio", "some/path/to/input2.slcio"], outputs=["some/path/to/output.slcio"])
47  parser = configparser.ConfigParser()
48  config_file = ['test_helpers/.hpsmc_test_cfg']
49  parser.read(config_file)
50  lcio_concat.config(parser)
51  self.assertEqual(lcio_concat.cmd_args(), ["-jar", "some/path/to/lcio-bin.jar", "concat", "-f", "some/path/to/input1.slcio", "-f", "some/path/to/input2.slcio", "-o", "some/path/to/output.slcio"])
52 
54  lcio_concat = LCIOConcat(outputs=["some/path/to/output.slcio"])
55  parser = configparser.ConfigParser()
56  config_file = ['test_helpers/.hpsmc_test_cfg']
57  parser.read(config_file)
58  lcio_concat.config(parser)
59  self.assertRaises(Exception, lambda: lcio_concat.cmd_args(), "Missing at least one input file.")
60 
62  lcio_concat = LCIOConcat(inputs=["some/path/to/input1.slcio", "some/path/to/input2.slcio"])
63  parser = configparser.ConfigParser()
64  config_file = ['test_helpers/.hpsmc_test_cfg']
65  parser.read(config_file)
66  lcio_concat.config(parser)
67  self.assertRaises(Exception, lambda: lcio_concat.cmd_args(), "Missing an output file.")
68 
69 
70 class TestLCIOCount(unittest.TestCase):
71 
72  def test_init(self):
73  lcio_count = LCIOCount()
74  self.assertEqual(lcio_count.name, "count")
75  self.assertEqual(lcio_count.command, "java")
76 
78  lcio_count = LCIOCount()
79  self.assertEqual(lcio_count.required_parameters(), [])
80 
82  lcio_count = LCIOCount()
83  self.assertEqual(lcio_count.optional_parameters(), [])
84 
85  def test_cmd_args(self):
86  lcio_count = LCIOCount(inputs=["some/path/to/input.slcio"])
87  parser = configparser.ConfigParser()
88  config_file = ['test_helpers/.hpsmc_test_cfg']
89  parser.read(config_file)
90  lcio_count.config(parser)
91  self.assertEqual(lcio_count.cmd_args(), ["-jar", "some/path/to/lcio-bin.jar", "count", "-f", "some/path/to/input.slcio"])
92 
94  lcio_count = LCIOCount()
95  parser = configparser.ConfigParser()
96  config_file = ['test_helpers/.hpsmc_test_cfg']
97  parser.read(config_file)
98  lcio_count.config(parser)
99  self.assertRaises(Exception, lambda: lcio_count.cmd_args(), "Missing an input file.")
100 
101 
102 class TestLCIOMerge(unittest.TestCase):
103 
104  def test_init(self):
105  lcio_merge = LCIOMerge()
106  self.assertEqual(lcio_merge.name, "merge")
107  self.assertEqual(lcio_merge.command, "java")
108 
109  def test_cmd_args(self):
110  lcio_merge = LCIOMerge(inputs=["some/path/to/input1.slcio", "some/path/to/input2.slcio"], outputs=["some/path/to/output.slcio"], nevents=100)
111  parser = configparser.ConfigParser()
112  config_file = ['test_helpers/.hpsmc_test_cfg']
113  parser.read(config_file)
114  lcio_merge.config(parser)
115  self.assertEqual(lcio_merge.cmd_args(), ["-jar", "some/path/to/lcio-bin.jar", "merge", "-f", "some/path/to/input1.slcio", "-f", "some/path/to/input2.slcio", "-o", "some/path/to/output.slcio", "-n", "100"])
116 
118  lcio_merge = LCIOMerge(outputs=["some/path/to/output.slcio"], nevents=100)
119  parser = configparser.ConfigParser()
120  config_file = ['test_helpers/.hpsmc_test_cfg']
121  parser.read(config_file)
122  lcio_merge.config(parser)
123  self.assertRaises(Exception, lambda: lcio_merge.cmd_args(), "Missing at least one input file.")
124 
126  lcio_merge = LCIOMerge(inputs=["some/path/to/input1.slcio", "some/path/to/input2.slcio"], nevents=100)
127  parser = configparser.ConfigParser()
128  config_file = ['test_helpers/.hpsmc_test_cfg']
129  parser.read(config_file)
130  lcio_merge.config(parser)
131  self.assertRaises(Exception, lambda: lcio_merge.cmd_args(), "Missing an output file.")
132 
133 
134 if __name__ == '__main__':
135  unittest.main()
Concatenate LCIO files together.
Definition: tools.py:1461
Count events in LCIO files.
Definition: tools.py:1487
Merge LCIO files.
Definition: tools.py:1530
Generic component for LCIO tools.
Definition: tools.py:1411
Tools that can be used in HPSMC jobs.
Definition: tools.py:1