7 from os.path
import expanduser
8 from hpsmc.job import JobConfig, Job, JobStore, JobScriptDatabase
16 self.assertEqual(job_config.config_files, [os.path.join(expanduser(
"~"),
".hpsmc"), os.path.abspath(
".hpsmc")])
19 job_config =
JobConfig(config_files=[
'test_helpers/.hpsmc_test_cfg'], include_default_locations=
False)
20 self.assertEqual(job_config.config_files, [
'test_helpers/.hpsmc_test_cfg'])
24 job_config =
JobConfig(config_files=[
'test_helpers/.hpsmc_test_cfg'], include_default_locations=
False)
26 job_config.config(component, required_names=[
'detector_dir'])
27 self.assertEqual(component.detector_dir,
'some/detector/dir')
30 job_config =
JobConfig(config_files=[
'test_helpers/.hpsmc_test_cfg_invalid'], include_default_locations=
False)
32 self.assertRaises(Exception,
lambda: job_config.config(component, required_names=[
'hpstr_install_dir']),
"Missing required config section HPSTR")
33 job_config.config(component, required_names=[
'hpstr_install_dir'], require_section=
False)
34 self.assertEqual(component.hpstr_install_dir,
None)
37 job_config =
JobConfig(config_files=[
'test_helpers/.hpsmc_test_cfg'], include_default_locations=
False)
39 self.assertRaises(Exception,
lambda: job_config.config(component, required_names=[
'not_in_config']),
"Missing required config not_in_config")
42 job_config =
JobConfig(config_files=[
'test_helpers/.hpsmc_test_cfg'], include_default_locations=
False)
44 self.assertRaises(Exception,
lambda: job_config.config(component, allowed_names=[
'not_in_config']),
"Config name detector_dir is not allowed for SLIC")
51 job_store.load(
"test_helpers/job_files/job_params.json")
52 self.assertEqual(job_store.data, {1: {
"input_files": {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"},
"output_files": {
"output.slcio":
"output_file.slcio"},
"output_dir":
"some/output_dir",
"job_id": 1}, 2: {
"input_files": {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"},
"output_files": {
"output.slcio":
"output_file.slcio"},
"output_dir":
"some/output_dir",
"job_id": 2}})
56 self.assertRaises(Exception,
lambda: job_store.load(
"path/does/not/exist.json"),
"JSON job store does not exist: path/does/not/exist.json")
59 job_store =
JobStore(
"test_helpers/job_files/job_params.json")
60 self.assertEqual(job_store.path,
"test_helpers/job_files/job_params.json")
61 self.assertEqual(job_store.data, {1: {
"input_files": {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"},
"output_files": {
"output.slcio":
"output_file.slcio"},
"output_dir":
"some/output_dir",
"job_id": 1}, 2: {
"input_files": {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"},
"output_files": {
"output.slcio":
"output_file.slcio"},
"output_dir":
"some/output_dir",
"job_id": 2}})
64 job_store =
JobStore(
"test_helpers/job_files/job_params.json")
65 job = job_store.get_job(1)
66 self.assertEqual(job[
'job_id'], 1)
67 self.assertEqual(job[
'output_dir'],
"some/output_dir")
68 self.assertEqual(job[
'input_files'], {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"})
69 self.assertEqual(job[
'output_files'], {
"output.slcio":
"output_file.slcio"})
72 job_store =
JobStore(
"test_helpers/job_files/job_params.json")
73 self.assertEqual(job_store.get_job_ids(), [1, 2])
76 job_store =
JobStore(
"test_helpers/job_files/job_params.json")
77 self.assertTrue(job_store.has_job_id(1))
78 self.assertFalse(job_store.has_job_id(3))
83 @unittest.skip("Test is broken")
86 self.assertEqual(len(job_script_database.scripts), 33)
90 basepath = os.path.join(os.environ[
'HPSMC_DIR'],
'lib',
'python',
'jobs')
91 self.assertEqual(job_script_database.get_script_path(
"slic"), os.path.join(basepath,
'slic_job.py'))
92 self.assertEqual(job_script_database.get_script_path(
"tritrig_gen"), os.path.join(basepath,
'tritrig_gen_job.py'))
94 @unittest.skip("Test is broken")
97 job_name_list = sorted(job_script_database.get_script_names())
98 self.assertEqual(job_name_list, [
"ap_gen",
"ap_gen_to_slic",
"ap_slic",
"beam_coords",
"beam_gen",
"beam_gen_sample",
"beam_prep_and_slic",
"data_cnv",
"dummy",
"fee_gen_to_recon",
"hpstr",
"lcio_count",
"moller_gen",
"rad_gen",
"readout_recon",
"signal_beam_merge_to_recon",
"signal_beam_merge_to_recon_2016",
"signal_pulser_overlay_to_recon",
"sim_to_ana",
"simp",
"slic",
"slic_to_ana",
"slic_to_anaMC",
"slic_to_recon",
"tritrig_beam",
"tritrig_beam_slic_to_reco",
"tritrig_gen",
"tritrig_gen_to_beam_coords",
"tritrig_prep_and_slic",
"tritrig_sim_full_chain",
"tritrig_slic_full_chain",
"wab_gen_sample",
"wab_gen_to_slic"])
102 self.assertTrue(job_script_database.exists(
"slic"))
103 self.assertFalse(job_script_database.exists(
"does_not_exist"))
109 job =
Job(args=[
'-d',
'some/run/dir',
'-o',
'output/dir',
'-i',
'1'])
110 self.assertEqual(job.args, [
'-d',
'some/run/dir',
'-o',
'output/dir',
'-i',
'1'])
111 self.assertEqual(job.description,
'HPS MC Job')
112 self.assertEqual(job.job_id,
None)
113 self.assertEqual(job.param_file,
None)
114 self.assertEqual(job.components, [])
115 self.assertEqual(job.rundir, os.getcwd())
116 self.assertEqual(job.params, {})
117 self.assertEqual(job.output_dir, os.getcwd())
118 self.assertEqual(job.input_files, {})
119 self.assertEqual(job.output_files, {})
120 self.assertEqual(job.ptags, {})
121 self.assertEqual(job.log, sys.stdout)
122 self.assertEqual(job.out, sys.stdout)
123 self.assertEqual(job.err, sys.stderr)
124 self.assertEqual(job.enable_copy_output_files,
True)
125 self.assertEqual(job.enable_copy_input_files,
True)
126 self.assertEqual(job.delete_existing,
False)
127 self.assertEqual(job.delete_rundir,
False)
128 self.assertEqual(job.dry_run,
False)
129 self.assertEqual(job.ignore_return_codes,
True)
130 self.assertEqual(job.check_output_files,
True)
131 self.assertEqual(job.check_commands,
False)
132 self.assertEqual(job.enable_file_chaining,
True)
133 self.assertEqual(job.enable_env_config,
False)
134 self.assertEqual(job.log_level, logging.INFO)
139 self.assertEqual(job.components, [
'test1'])
140 job.add([
'test2',
'test3'])
141 self.assertEqual(job.components, [
'test1',
'test2',
'test3'])
145 job.set_parameters({
'test1': 1,
'test2': 2})
146 self.assertEqual(job.params, {
'test1': 1,
'test2': 2})
147 job.set_parameters({
'test3': 3})
148 self.assertEqual(job.params, {
'test1': 1,
'test2': 2,
'test3': 3})
151 job =
Job(args=[
'-c',
'test_helpers/.hpsmc_test_cfg',
'-d',
'some/run/dir',
'-o',
'test_helpers/job_files/out_file',
'-e',
'test_helpers/job_files/err_file',
'-l',
'test_helpers/job_files/log_file',
'-s',
'1',
'-i',
'1',
'test_helpers/job_files/some_job_script.py',
'test_helpers/job_files/job_params.json'])
152 self.assertEqual(job.args, [
'-c',
'test_helpers/.hpsmc_test_cfg',
'-d',
'some/run/dir',
'-o',
'test_helpers/job_files/out_file',
'-e',
'test_helpers/job_files/err_file',
'-l',
'test_helpers/job_files/log_file',
'-s',
'1',
'-i',
'1',
'test_helpers/job_files/some_job_script.py',
'test_helpers/job_files/job_params.json'])
154 self.assertEqual(job.log_level, 10)
155 self.assertEqual(job.rundir,
'some/run/dir')
156 self.assertEqual(job.job_steps, 1)
157 self.assertEqual(job.script,
'test_helpers/job_files/some_job_script.py')
158 self.assertEqual(job.param_file, os.path.abspath(
'test_helpers/job_files/job_params.json'))
159 self.assertEqual(job.job_id, 1)
160 self.assertEqual(job.params, {
"input_files": {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"},
"output_files": {
"output.slcio":
"output_file.slcio"},
"output_dir":
"some/output_dir",
"job_id": 1})
161 self.assertEqual(job.output_dir, os.path.abspath(
'some/output_dir'))
162 self.assertEqual(job.input_files, {
"input1.stdhep":
"path/to/input1.stdhep",
"input2.stdhep":
"path/to/input2.stdhep"})
163 self.assertEqual(job.output_files, {
"output.slcio":
"output_file.slcio"})
167 self.assertRaises(Exception,
lambda: job.parse_args(),
'Missing required script name or location.')
Wrapper for accessing config information from parser.
Simple JSON based store of job data.
Primary class to run HPS jobs from a Python script.
def test_config_missing_section(self)
def test_init_config(self)
def test_config_not_allowed_config(self)
def test_config_missing_config(self)
def test_get_script_names(self)
def test_get_script_path(self)
def test_has_job_id(self)
def test_load_file_not_exist(self)
def test_get_job_ids(self)
def test_parse_args(self)
def test_set_params(self)
def test_parse_args_no_script(self)