Skip to content

Commit

Permalink
fix tests and re method
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Apr 16, 2022
1 parent bb4fcc2 commit b0a5d73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 20 additions & 5 deletions tests/test_lsf_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class TestSubmitter(unittest.TestCase):
@patch.object(
CookieCutter, CookieCutter.get_default_mem_mb.__name__, return_value=1000
)
@patch.object(
CookieCutter, CookieCutter.get_default_project.__name__, return_value="proj"
)
@patch.object(OSLayer, OSLayer.get_uuid4_string.__name__, return_value="random")
def test___several_trivial_getter_methods(self, *mocks):
argv = [
Expand Down Expand Up @@ -72,7 +75,7 @@ def test___several_trivial_getter_methods(self, *mocks):
self.assertEqual(
lsf_submit.submit_cmd,
"bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' "
"{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"{jobinfo} -q q1 -P proj cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd),
)

Expand Down Expand Up @@ -140,6 +143,9 @@ def test____submit_cmd_and_get_external_job_id___output_stream_has_no_jobid(
@patch.object(
CookieCutter, CookieCutter.get_default_mem_mb.__name__, return_value=1000
)
@patch.object(
CookieCutter, CookieCutter.get_default_project.__name__, return_value="proj"
)
@patch.object(OSLayer, OSLayer.get_uuid4_string.__name__, return_value="random")
@patch.object(OSLayer, OSLayer.mkdir.__name__)
@patch.object(OSLayer, OSLayer.remove_file.__name__)
Expand Down Expand Up @@ -191,7 +197,7 @@ def test___submit___successfull_submit(
expected_mem = "2662"
run_process_mock.assert_called_once_with(
"bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' "
"{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"{jobinfo} -q q1 -P proj cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd)
)
print_mock.assert_called_once_with(
Expand All @@ -204,6 +210,9 @@ def test___submit___successfull_submit(
@patch.object(
CookieCutter, CookieCutter.get_default_mem_mb.__name__, return_value=1000
)
@patch.object(
CookieCutter, CookieCutter.get_default_project.__name__, return_value="proj"
)
@patch.object(OSLayer, OSLayer.get_uuid4_string.__name__, return_value="random")
@patch.object(OSLayer, OSLayer.mkdir.__name__)
@patch.object(OSLayer, OSLayer.remove_file.__name__)
Expand Down Expand Up @@ -247,7 +256,7 @@ def test___submit___failed_submit_bsub_invocation_error(
expected_mem = "2662"
run_process_mock.assert_called_once_with(
"bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' "
"{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"{jobinfo} -q q1 -P proj cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd)
)
print_mock.assert_not_called()
Expand Down Expand Up @@ -335,6 +344,9 @@ def test_rule_specific_params_are_submitted(self, *mocks):
@patch.object(
CookieCutter, CookieCutter.get_default_mem_mb.__name__, return_value=1000
)
@patch.object(
CookieCutter, CookieCutter.get_default_project.__name__, return_value="proj"
)
@patch.object(OSLayer, OSLayer.get_uuid4_string.__name__, return_value="random")
def test_lsf_mem_unit_is_kb_and_mem_mb_is_converted_accordingly(self, *mocks):
argv = [
Expand Down Expand Up @@ -373,7 +385,7 @@ def test_lsf_mem_unit_is_kb_and_mem_mb_is_converted_accordingly(self, *mocks):
).format(outlog=expected_outlog, errlog=expected_errlog)
expected = (
"bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' "
"{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"{jobinfo} cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"-q queue -gpu - -P project "
"real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd)
)
Expand All @@ -383,6 +395,9 @@ def test_lsf_mem_unit_is_kb_and_mem_mb_is_converted_accordingly(self, *mocks):
@patch.object(
CookieCutter, CookieCutter.get_log_dir.__name__, return_value="logdir"
)
@patch.object(
CookieCutter, CookieCutter.get_default_project.__name__, return_value="proj"
)
@patch.object(
CookieCutter, CookieCutter.get_default_mem_mb.__name__, return_value=1000
)
Expand Down Expand Up @@ -426,7 +441,7 @@ def test_lsf_mem_unit_is_tb_and_mem_mb_is_converted_and_rounded_up_to_int(
).format(outlog=expected_outlog, errlog=expected_errlog)
expected = (
"bsub -M {mem} -n 1 -R 'select[mem>{mem}] rusage[mem={mem}] span[hosts=1]' "
"{jobinfo} -q q1 cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"{jobinfo} cluster_opt_1 cluster_opt_2 cluster_opt_3 "
"-q queue -gpu - -P project "
"real_jobscript.sh".format(mem=expected_mem, jobinfo=expected_jobinfo_cmd)
)
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.profile_name}}/lsf_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def jobinfo_cmd(self) -> str:

@property
def queue(self) -> str:
if re.match(r"-q ", self.rule_specific_params):
if re.search(r"-q ", self.rule_specific_params):
return ""
return self.cluster.get("queue", CookieCutter.get_default_queue())

Expand All @@ -179,7 +179,7 @@ def rule_specific_params(self) -> str:

@property
def proj(self) -> str:
if re.match(r"-P ", self.rule_specific_params):
if re.search(r"-P ", self.rule_specific_params):
return ""
return self.cluster.get("project", CookieCutter.get_default_project())

Expand Down

0 comments on commit b0a5d73

Please sign in to comment.