def test_wait_terminated(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) with drmaa2.JobSession() as js: jt = drmaa2.JobTemplate() jt.remoteCommand = Path("/bin/sleep") jt.args = ["30"] jobs = list() job_cnt = 2 for idx in range(job_cnt): LOGGER.debug("submitting job {} {}".format(idx, jt)) jobs.append(js.run(jt)) print("submitted job is {}".format(jobs[-1])) job_list = drmaa2.DRMAA2List(jobs, "joblist") returned = list() # This should remove completed jobs from the list every # time one is returned, as shown in src/hold.c. for reap_idx in range(job_cnt): job = None while not job: job = js.wait_any_terminated(job_list, 10) LOGGER.debug("Returned from wait {}".format(job)) returned.append(job) LOGGER.debug("completed: {}".format(returned[-1])) assert returned[0] != returned[1]
def test_job_template_bool(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.submitAsHold jt.submitAsHold = True assert jt.submitAsHold jt.submitAsHold = True assert jt.submitAsHold jt.submitAsHold = False assert not jt.submitAsHold
def test_job_template_dotted(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.pe jt.pe = "slots=10000" assert jt.pe == "slots=10000" jt.pe = "blah" assert jt.pe == "blah" jt.pe = None assert not jt.pe
def test_job_template_extensible(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert jt.implementation_specific() == ["uge_jt_pe"] jt.uge_jt_pe = "slots=5" assert jt.uge_jt_pe == "slots=5" jt.uge_jt_pe = "slots=7" assert jt.uge_jt_pe == "slots=7" jt.uge_jt_pe = None assert not jt.uge_jt_pe
def test_job_template_list(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.args jt.args = ["one", "two", "three"] assert jt.args == ["one", "two", "three"] jt.args = ["one", "two", "four"] assert jt.args == ["one", "two", "four"] jt.args = None assert not jt.args jt.args = [] assert not jt.args
def test_job_template_command(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.remoteCommand jt.remoteCommand = "/bin/true" assert jt.remoteCommand == "/bin/true" LOGGER.debug("setting to false") jt.remoteCommand = "/bin/false" assert jt.remoteCommand == "/bin/false" LOGGER.debug("Setting to None") jt.remoteCommand = None assert not jt.remoteCommand
def test_job_template_longlong(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.minSlots jt.minSlots = None assert not jt.minSlots jt.minSlots = 3 assert jt.minSlots == 3 jt.minSlots = 5 assert jt.minSlots == 5 jt.minSlots = None assert not jt.minSlots
def test_job_template_enum(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.machineOS jt.machineOS = None assert not jt.machineOS jt.machineOS = "LINUX" assert jt.machineOS == "LINUX" jt.machineOS = "WIN" assert jt.machineOS == "WIN" jt.machineOS = None assert not jt.machineOS
def test_submit_with_pe(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) with drmaa2.JobSession() as js: jt = drmaa2.JobTemplate() jt.remoteCommand = Path("/bin/sleep") jt.args = ["60"] jt.set_impl_spec("uge_jt_pe", "multi_slot") for run_idx in range(3): js.args = str(60 + run_idx) job = js.run(jt) LOGGER.debug("Ran job {}".format(job)) assert job
def test_job_template_dict(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.jobEnvironment jt.jobEnvironment = dict() assert not jt.jobEnvironment jt.jobEnvironment = {"PATH": "/bin:/homes/kheuton/bin", "LIB": "libm"} env = jt.jobEnvironment assert env["PATH"] == "/bin:/homes/kheuton/bin" assert "LIB" in env jt.jobEnvironment = {"SPACE": "race"} assert jt.jobEnvironment["SPACE"] == "race" assert len(jt.jobEnvironment) == 1
def test_run_job(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) js = drmaa2.JobSession() jt = drmaa2.JobTemplate() jt.remoteCommand = Path("/bin/true") job1 = js.run(jt) jt.remoteCommand = Path("/bin/false") job2 = js.run(jt) print(job1, job2) js.close() js.__del__() js.destroy()
def test_job_template_time(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) jt = drmaa2.JobTemplate() assert not jt.startTime jt.startTime = None assert not jt.startTime jt.startTime = datetime.datetime.now() assert jt.startTime jt.startTime = None assert not jt.startTime jt.startTime = "now" assert jt.startTime == "now" jt.startTime = "infinite" assert jt.startTime == "infinite" jt.startTime = "zero" assert jt.startTime == "zero" assert not jt.deadlineTime
def test_submit_with_impl_spec(): logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) # The error is that spaces aren't allowed. with pytest.raises(RuntimeError): with drmaa2.JobSession() as js: jt = drmaa2.JobTemplate() jt.remoteCommand = Path("/bin/sleep") jt.args = ["60"] jt.minSlots = 2 jobs = list() for idx in range(3): if idx > 0: previous = jobs[-1].id pe_str = "-pe multi_slot -hold_jid={}".format(previous) LOGGER.debug("Using pe string: {}".format(pe_str)) jt.set_impl_spec("uge_jt_pe", pe_str) jobs.append(js.run(jt)) print("Returned job is {}".format(jobs[-1])) else: LOGGER.debug("submitting job {} {}".format(idx, jt)) jobs.append(js.run(jt)) print("Returned job is {}".format(jobs[-1]))