def test_submit_status(self): env = get_environment() sched = env.scheduler_type() sched.reset() project = self.mock_project() for job in project: list(project.classify(job)) self.assertEqual(project.next_operation(job).name, 'a_op') self.assertEqual(project.next_operation(job).job, job) with suspend_logging(): with redirect_stdout(StringIO()): project.submit(env) self.assertEqual(len(list(sched.jobs())), len(project)) for job in project: self.assertEqual( project.next_operation(job).get_status(), JobStatus.submitted) sched.step() sched.step() project._fetch_scheduler_status(file=StringIO()) for job in project: self.assertEqual( project.next_operation(job).get_status(), JobStatus.queued)
def test_submit_test_submission_script(self): env = get_environment(test=True) sscript = env.script(a=0) sscript.seek(0) tmp_out = StringIO() with redirect_stdout(tmp_out): env.submit(sscript, hold=True) tmp_out.seek(0)
def test_print_status(self): project = self.mock_project() for job in project: list(project.classify(job)) self.assertEqual(project.next_operation(job).name, 'a_op') self.assertEqual(project.next_operation(job).job, job) fd = StringIO() with redirect_stderr(StringIO()): with redirect_stdout(StringIO()): project.print_status(file=fd, err=fd)
def test_bundles(self): env = get_environment() sched = env.scheduler_type() sched.reset() project = self.mock_project() self.assertEqual(len(list(sched.jobs())), 0) with suspend_logging(): with redirect_stderr(StringIO()): project.submit(bundle_size=2, num=2) self.assertEqual(len(list(sched.jobs())), 1) project.submit(bundle_size=2, num=4) self.assertEqual(len(list(sched.jobs())), 3) sched.reset() project._fetch_scheduler_status(file=StringIO()) project.submit(bundle_size=0) self.assertEqual(len(list(sched.jobs())), 1)
def test_run_operations_implicit_argument(self): project = self.mock_project() for job in project: ops = project.next_operations(job) with suspend_logging(): with redirect_stderr(StringIO()): project.run(ops) for job in project: self.assertIn('said_hello', list(project.labels(job)))
def test_submit(self): env = get_environment() sched = env.scheduler_type() sched.reset() project = self.mock_project() self.assertEqual(len(list(sched.jobs())), 0) with suspend_logging(): with redirect_stdout(StringIO()): project.submit(env) self.assertEqual(len(list(sched.jobs())), len(project)) sched.reset()
def test_single_submit(self): env = get_environment() env.scheduler_type.reset() self.assertTrue(issubclass(env, MockEnvironment)) sscript = env.script() with suspend_logging(): with redirect_stdout(StringIO()): env.submit(sscript, _id='test') scheduler = env.get_scheduler() self.assertEqual(len(list(scheduler.jobs())), 1) for job in scheduler.jobs(): self.assertEqual(job.status(), JobStatus.submitted)
def test_environment_get_config_value(self): env = get_environment(test=True) with redirect_stdout(StringIO()): with pytest.raises(ConfigKeyError): a = env.get_config_value("a") a = env.get_config_value("a", None) assert a is None a = env.get_config_value("a", 42) assert a == 42
def test_environment_get_config_value(self): env = get_environment(test=True) with redirect_stdout(StringIO()): with self.assertRaises(ConfigKeyError): a = env.get_config_value('a') a = env.get_config_value('a', None) self.assertIsNone(a) a = env.get_config_value('a', 42) self.assertEqual(a, 42)
def test_resubmit(self): env = get_environment() sched = env.scheduler_type() sched.reset() project = self.mock_project() self.assertEqual(len(list(sched.jobs())), 0) with suspend_logging(): with redirect_stdout(StringIO()): project.submit(env) for i in range(5): # push all jobs through the queue self.assertEqual(len(list(sched.jobs())), len(project)) project.submit(env) sched.step() self.assertEqual(len(list(sched.jobs())), 0)
def test_submit_operations(self): env = get_environment() sched = env.scheduler_type() sched.reset() project = self.mock_project() operations = [] for job in project: operations.extend(project.next_operations(job)) self.assertEqual(len(list(sched.jobs())), 0) cluster_job_id = project._store_bundled(operations) with suspend_logging(): with redirect_stderr(StringIO()): project.submit_operations(_id=cluster_job_id, env=env, operations=operations) self.assertEqual(len(list(sched.jobs())), 1) sched.reset()
def test_run(self): project = self.mock_project() with redirect_stderr(StringIO()): project.run() for job in project: self.assertIn('said_hello', list(project.labels(job)))