def test__given_jobid__when_running__should_poll_job(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) sut(Mock(spec=UI)) assert_job_polled(executor, DEFAULT_JOB_ID)
def test__when_job_completes__should_return_true(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) result = sut(Mock(spec=UI)) assert result is True
def test__when_status_poll_fails__should_exit_with_code_1(options): executor = SlurmJobExecutorSpy(sacct_cmd=RunningCommandStub(exit_code=1)) sut = make_sut(executor, Mock()) actual = sut.run(options) assert actual == 1
def test__when_job_completes_with_failure__should_return_false(): executor = SlurmJobExecutorSpy(sacct_cmd=FailedSlurmJobCommandStub()) sut = make_sut(executor) result = sut(Mock(spec=UI)) assert result is False
def test__given_watch_options__when_running__should_poll_job_until_done(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) sut.run(cancel_options_with_proxy()) assert_job_canceled(executor, DEFAULT_JOB_ID)
def test__when_running__should_cancel_job(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) actual = sut(Mock(spec=UI)) assert_job_canceled(executor, DEFAULT_JOB_ID) assert actual is True
def test__when_canceling_job__should_call_scancel_on_executor(): jobid = "12345" executor = SlurmJobExecutorSpy(jobid=jobid) sut = make_sut(executor) sut.cancel(jobid) assert_job_canceled(executor, jobid)
def test__when_polling_job__should_return_job_status(): jobid = "12345" executor = SlurmJobExecutorSpy(jobid=jobid) sut = make_sut(executor) actual = sut.poll_status(jobid) assert actual == completed_slurm_job()
def test__when_polling_job__should_call_sacct_on_executor(): jobid = "12345" executor = SlurmJobExecutorSpy(jobid=jobid) sut = make_sut(executor) sut.poll_status(jobid) assert_job_polled(executor, jobid)
def test__when_submitting_job__should_return_slurm_batch_job(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) jobfile = "jobfile.job" actual = sut.submit(jobfile) assert isinstance(actual, SlurmBatchJob)
def test__when_submitting_job__should_call_sbatch_on_executor(): executor = SlurmJobExecutorSpy() sut = make_sut(executor) jobfile = "jobfile.job" sut.submit(jobfile) assert_job_submitted(executor, jobfile)
def run_launch_workflow(options: LaunchOptions, executor: CommandExecutor = None, watcher_factory: JobWatcherFactory = None) -> int: executor = executor or SlurmJobExecutorSpy() controller = SlurmController(executor, watcher_factory) sut = LaunchStage(controller, options.sbatch) return sut(Mock(spec=UI))
def test__given_watch_options__when_running_with_failing_job__should_exit_with_1( ): executor = SlurmJobExecutorSpy(sacct_cmd=FailedSlurmJobCommandStub()) sut = make_sut(executor) actual = sut.run(watch_options_with_proxy()) assert actual == 1
def test__given_watch_options__when_running_with_successful_job__should_exit_with_0( ): executor = SlurmJobExecutorSpy() sut = make_sut(executor) actual = sut.run(watch_options_with_proxy()) assert actual == 0
def test__when_running__should_update_ui_with_job_status(): ui = Mock(spec=UI) executor = SlurmJobExecutorSpy() sut = make_sut(executor) sut(ui) ui.update.assert_called_once_with(completed_slurm_job())
def test__when_submitting_job__job_should_have_jobid(): jobid = "12345" executor = SlurmJobExecutorSpy(jobid=jobid) sut = make_sut(executor) jobfile = "jobfile.job" actual = sut.submit(jobfile) assert actual.jobid == "12345"
def test__given_job_options_with_status_action__when_running__should_poll_job_status_once_and_exit( options): executor = SlurmJobExecutorSpy(sacct_cmd=AssertWaitRunningCommandStub()) sut = make_sut(executor) actual = sut.run(options) assert_job_polled(executor) assert actual == 0
def test__given_job_option_with_status_action__when_running__should_update_ui_with_job_status( options): executor = SlurmJobExecutorSpy(sacct_cmd=SuccessfulSlurmJobCommandStub()) ui_spy = Mock() sut = make_sut(executor, ui_spy) sut.run(options) ui_spy.update.assert_called_with(completed_slurm_job())
def test__given_running_workflow__when_canceling__should_call_cancel_on_job(): executor = SlurmJobExecutorSpy() controller = SlurmController(executor) opts = launch_options(watch=True) sut = LaunchStage(controller, opts) sut(Mock(spec=UI)) sut.cancel(Mock(spec=UI)) assert_job_canceled(executor, DEFAULT_JOB_ID, command_index=-1)
def test__given_running_stage__when_canceling__should_stop_watcher(): watcher = Mock(spec=JobWatcher) def factory(*args, **kwargs): return watcher executor = SlurmJobExecutorSpy() sut = make_sut(executor, factory=factory) sut(Mock(spec=UI)) sut.cancel(Mock(spec=UI)) assert watcher.stop.called is True
def test__given_watcher_factory__when_submitting_job__should_pass_factory_to_slurm_job( ): executor = SlurmJobExecutorSpy() watcher_dummy = Mock(spec=JobWatcher) def factory(job): return watcher_dummy sut = make_sut(executor, factory) job = sut.submit("jobfile") actual = job.get_watcher() assert actual is watcher_dummy
def make_sut(options, ui=None): return Application(SlurmJobExecutorSpy(), PyFilesystemFactory(options), ui or Mock())
def executor_spy(): return SlurmJobExecutorSpy()
def executor_spy(): return SlurmJobExecutorSpy(jobid=JOB_ID)
def make_sut(): executor = SlurmJobExecutorSpy(sacct_cmd=SuccessfulSlurmJobCommandStub()) controller = SlurmController(executor) return StatusStage(controller, DEFAULT_JOB_ID)