HPS-MC
test_tools_jobmanager.py
Go to the documentation of this file.
1 import unittest
2 import configparser
3 import os
4 
5 from hpsmc.tools import JobManager
6 
7 
8 class TestJobManager(unittest.TestCase):
9 
10  def test_init(self):
11  job_manager = JobManager()
12  self.assertEqual(job_manager.name, 'job_manager')
13  self.assertEqual(job_manager.command, 'java')
14 
16  job_manager = JobManager(steering="steering", inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"], overlay_file="some/path/to/overlay.slcio")
17  self.assertEqual(job_manager.name, 'job_manager')
18  self.assertEqual(job_manager.command, 'java')
19  self.assertEqual(job_manager.inputs, ["some/path/to/input.slcio"])
20  self.assertEqual(job_manager.outputs, ["some/path/to/output.slcio"])
21  self.assertEqual(job_manager.steering, "steering")
22  self.assertEqual(job_manager.append_tok, "steering")
23  self.assertEqual(job_manager.overlay_file, "some/path/to/overlay.slcio")
24 
26  job_manager = JobManager()
27  self.assertEqual(job_manager.required_parameters(), ['steering_files'])
28 
30  job_manager = JobManager()
31  self.assertEqual(job_manager.required_config(), ['hps_java_bin_jar', 'hps_fieldmaps_dir'])
32 
34  job_manager = JobManager()
35  self.assertEqual(job_manager.optional_parameters(), ['detector', 'run_number', 'defs'])
36 
37  def test_config(self):
38  job_manager = JobManager()
39  parser = configparser.ConfigParser()
40  config_file = ['test_helpers/.hpsmc_test_cfg']
41  parser.read(config_file)
42  job_manager.config(parser)
43  self.assertEqual(job_manager.hps_fieldmaps_dir, 'some/fieldmaps/dir')
44  self.assertEqual(job_manager.hps_java_bin_jar, 'some/path/to/hps-java-bin.jar')
45  self.assertEqual(job_manager.conditions_url, 'http://some/path/to/conditions')
46 
48  job_manager = JobManager()
49  parser = configparser.ConfigParser()
50  config_file = ['test_helpers/.hpsmc_test_cfg_invalid']
51  parser.read(config_file)
52  self.assertRaises(Exception, lambda: job_manager.config(parser))
53 
54  def test_setup(self):
55  job_manager = JobManager(steering="steering", inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"])
56  parser = configparser.ConfigParser()
57  config_file = ['test_helpers/.hpsmc_test_cfg']
58  parser.read(config_file)
59  job_manager.config(parser)
60  params = {'steering_files': {'steering': 'some/path/to/steering.lcsim'}}
61  job_manager.set_parameters(params)
62  job_manager.setup()
63  self.assertEqual(job_manager.steering_file, "some/path/to/steering.lcsim")
64  self.assertEqual(job_manager.hps_fieldmaps_dir, "some/fieldmaps/dir")
65  os.remove(os.getcwd() + '/fieldmap')
66 
68  job_manager = JobManager(steering="invalid_steering", inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"])
69  parser = configparser.ConfigParser()
70  config_file = ['test_helpers/.hpsmc_test_cfg']
71  parser.read(config_file)
72  job_manager.config(parser)
73  params = {'steering_files': {'steering': 'some/path/to/steering.lcsim'}}
74  job_manager.set_parameters(params)
75  self.assertRaises(Exception, lambda: job_manager.setup())
76 
77  def test_cmd_args(self):
78  job_manager = JobManager(steering="steering", inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"])
79  parser = configparser.ConfigParser()
80  config_file = ['test_helpers/.hpsmc_test_cfg']
81  parser.read(config_file)
82  job_manager.config(parser)
83  params = {'steering_files': {'steering': 'some/path/to/steering.lcsim'}, 'detector': 'some_detector', 'run_number': 1, 'event_print_interval': 10, 'nevents': 1}
84  job_manager.set_parameters(params)
85  job_manager.setup()
86  print(job_manager.cmd_args())
87  self.assertEqual(job_manager.cmd_args(), ["-Dorg.hps.conditions.url=http://some/path/to/conditions", "-jar", "some/path/to/hps-java-bin.jar", "-R", "1", "-d", "some_detector", "-D", "outputFile=some/path/to/output", "-r", "some/path/to/steering.lcsim", "-i", "some/path/to/input.slcio"])
88 
89 
90 if __name__ == '__main__':
91  unittest.main()
Run the hps-java JobManager class.
Definition: tools.py:160
Tools that can be used in HPSMC jobs.
Definition: tools.py:1