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_write_test_submission_script(self):
     env = get_environment(test=True)
     sscript = env.script()
     self.assertTrue(isinstance(sscript, JobScript))
     sscript = env.script(a=0)
     sscript.seek(0)
     self.assertEqual(sscript.read(), '#TEST a=0\n')
 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_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)
Beispiel #6
0
    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)
Beispiel #9
0
 def __init__(self, *args, **kwargs):
     super(RhacoProject, self).__init__(*args, **kwargs)
     env = flow.get_environment()
     self.add_operation(
         name="generate",
         cmd=lambda job: "python -u operations.py generate {}".format(job),
         pre=[RhacoProject.parent_job],
         post=[RhacoProject.generated],
     )
     self.add_operation(
         name="simulate",
         cmd=lambda job: "python -u operations.py simulate {}".format(job),
         pre=[RhacoProject.generated],
         post=[RhacoProject.simulated],
     )
 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_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_JobScript(self):
     env = get_environment(test=True)
     sscript = env.script()
     sscript_ = JobScript(env)
     self.assertEqual(type(sscript), type(sscript_))
     self.assertEqual(sscript._env, sscript_._env)
     self.assertEqual(len(sscript.read()), 0)
     sscript.writeline('test')
     sscript.seek(0)
     self.assertEqual(sscript.read(), 'test\n')
     sscript = env.script()
     sscript.write_cmd('test')
     sscript.seek(0)
     self.assertEqual(sscript.read(), 'test\n')
     sscript = env.script()
     sscript.write_cmd('test', bg=True)
     sscript.seek(0)
     self.assertTrue(sscript.read().endswith('&\n'))
Beispiel #13
0
 def test_get_TestEnvironment(self):
     env = get_environment()
     assert issubclass(env, ComputeEnvironment)
     assert not issubclass(env, TestEnvironment)
     env = get_environment(test=True)
     assert issubclass(env, TestEnvironment)
 def test_get_TestEnvironment(self):
     env = get_environment()
     self.assertTrue(issubclass(env, ComputeEnvironment))
     self.assertFalse(issubclass(env, TestEnvironment))
     env = get_environment(test=True)
     self.assertTrue(issubclass(env, TestEnvironment))