Skip to content

Commit

Permalink
feat: Add unit test for interactive job
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmunday committed Feb 2, 2024
1 parent 18dd6d5 commit 4f82afa
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,65 @@ def test_job_ended(
assert mock_smtp_sendmail.call_args[0][1] == ["root"]
check_template_used(mock_get_file_contents, "ended.tpl")

def test_interactive_job_ended(
self,
mock_get_file_contents,
mock_slurmmail_cli_delete_spool_file,
mock_slurmmail_cli_process_spool_file_options,
mock_slurmmail_cli_run_command,
mock_smtp_sendmail,
):
with patch(
"pathlib.Path.open",
new_callable=mock_open,
read_data="""{
"job_id": 2,
"email": "root",
"state": "Ended",
"array_summary": false
}
""",
):
sacct_output = "2|root|root|all|1674340451|1674340571|COMPLETED|500M||1|1|00:00.010|1|/root|00:02:00|0:0|||test|node01|01:00:00|60|2|test.jcf\n" # noqa
sacct_output += "2.batch||||1674340451|1674340571|COMPLETED||4880K|1|1|00:00.010|1||00:02:00|0:0|||test|node01|||2.batch|batch" # noqa
scontrol_output = (
"JobId=2 JobName=test.jcf UserId=root(0) GroupId=root(0) MCS_label=N/A"
" Priority=4294901758 Nice=0 Account=root QOS=normal JobState=COMPLETED"
" Reason=None Dependency=(null) Requeue=1 Restarts=0 BatchFlag=1"
" Reboot=0 ExitCode=0:0 RunTime=00:02:00 TimeLimit=01:00:00 TimeMin=N/A"
" SubmitTime=2023-01-21T22:34:11 EligibleTime=2023-01-21T22:34:11"
" AccrueTime=2023-01-21T22:34:11 StartTime=2023-01-21T22:34:11"
" EndTime=2023-01-21T22:36:11 Deadline=N/A SuspendTime=None"
" SecsPreSuspend=0 LastSchedEval=2023-01-21T22:34:11 Scheduler=Main"
" Partition=all AllocNode:Sid=ac2c384f02af:204 ReqNodeList=(null)"
" ExcNodeList=(null) NodeList=node01 BatchHost=node01 NumNodes=1"
" NumCPUs=1 NumTasks=1 CPUs/Task=1 ReqB:S:C:T=0:0:*:*"
" TRES=cpu=1,node=1,billing=1 Socks/Node=* NtasksPerN:B:S:C=0:0:*:*"
" CoreSpec=* MinCPUsNode=1 MinMemoryNode=0 MinTmpDiskNode=0"
" Features=(null) DelayBoot=00:00:00 OverSubscribe=OK Contiguous=0"
" Licenses=(null) Network=(null) Command=/root/test.jcf WorkDir=/root"
" StdIn=/dev/null Power= MailUser=root"
" MailType=INVALID_DEPEND,BEGIN,END,FAIL,REQUEUE,STAGE_OUT"
)
mock_slurmmail_cli_run_command.side_effect = [
(0, sacct_output, ""),
(0, scontrol_output, ""),
]
slurmmail.cli.__dict__["__process_spool_file"](
pathlib.Path("/tmp/foo"),
smtplib.SMTP(),
mock_slurmmail_cli_process_spool_file_options,
)
assert mock_slurmmail_cli_run_command.call_count == 2
mock_slurmmail_cli_delete_spool_file.assert_called_once()
mock_smtp_sendmail.assert_called_once()
assert (
mock_smtp_sendmail.call_args[0][0]
== mock_slurmmail_cli_process_spool_file_options.email_from_address
)
assert mock_smtp_sendmail.call_args[0][1] == ["root"]
check_template_used(mock_get_file_contents, "ended.tpl")

def test_job_ended_mem_per_node_slurm_less_than_v21(
self,
mock_get_file_contents,
Expand Down

0 comments on commit 4f82afa

Please sign in to comment.