HPS-MC
test_tools_slic.py
Go to the documentation of this file.
1 import unittest
2 import configparser
3 import os
4 
5 from hpsmc.tools import SLIC
6 
7 
8 class TestSLIC(unittest.TestCase):
9 
10  def test_init(self):
11  slic = SLIC()
12  self.assertEqual(slic.name, 'slic')
13 
14  def test_config(self):
15  slic = SLIC()
16  parser = configparser.ConfigParser()
17  config_file = ['test_helpers/.hpsmc_test_cfg']
18  parser.read(config_file)
19  slic.config(parser)
20  self.assertEqual(slic.detector_dir, 'some/detector/dir')
21  self.assertEqual(slic.hps_fieldmaps_dir, 'some/fieldmaps/dir')
22 
24  slic = SLIC()
25  self.assertEqual(slic.optional_parameters(), ['nevents', 'macros', 'run_number'])
26 
28  slic = SLIC()
29  self.assertEqual(slic.required_parameters(), ['detector'])
30 
32  slic = SLIC()
33  self.assertEqual(slic.required_config(), ['slic_dir', 'hps_fieldmaps_dir', 'detector_dir'])
34 
36  slic = SLIC()
37  self.assertRaises(Exception, lambda: slic.cmd_args())
38 
40  slic = SLIC(inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"])
41  parser = configparser.ConfigParser()
42  config_file = ['test_helpers/.hpsmc_test_cfg_invalid']
43  parser.read(config_file)
44  slic.config(parser)
45  params = {'detector': 'some_detector'}
46  slic.set_parameters(params)
47  self.assertRaises(Exception, lambda: slic.cmd_args())
48 
49  def test_cmd_args(self):
50  slic = SLIC(inputs=["some/path/to/input.slcio"], outputs=["some/path/to/output.slcio"])
51  parser = configparser.ConfigParser()
52  config_file = ['test_helpers/.hpsmc_test_cfg']
53  parser.read(config_file)
54  slic.config(parser)
55  params = {'detector': 'some_detector', 'nevents': 1}
56  slic.set_parameters(params)
57  self.assertEqual(slic.cmd_args(), ["-g", "some/detector/dir/some_detector/some_detector.lcdd", "-i", "some/path/to/input.slcio", "-o", "some/path/to/output.slcio", "-d1", "-r", str(1), "-P", "test_helpers/slicdir/share/particle.tbl"])
58 
60  slic = SLIC()
61  parser = configparser.ConfigParser()
62  config_file = ['test_helpers/.hpsmc_test_cfg_invalid']
63  parser.read(config_file)
64  slic.config(parser)
65  self.assertRaises(Exception, lambda: slic.setup())
66 
67  def test_setup(self):
68  slic = SLIC(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  slic.config(parser)
73  slic.setup()
74  self.assertEqual(slic.env_script, "test_helpers/slicdir/bin/slic-env.sh")
75  os.remove(os.getcwd() + '/fieldmap')
76 
77 
78 if __name__ == '__main__':
79  unittest.main()
Run the SLIC Geant4 simulation.
Definition: tools.py:15
def test_cmd_args_exception_particle_tbl(self)
Tools that can be used in HPSMC jobs.
Definition: tools.py:1