def test_actor(): try: shutil.rmtree('tests/tmp') except OSError: pass os.mkdir('tests/tmp') cfg = simcity.util.Config(from_file=False) cfg.add_section('Execution', { 'tmp_dir': 'tests/tmp/tmp_alala', 'output_dir': 'tests/tmp/out_alala', 'input_dir': 'tests/tmp/in_alala', }) db = MockDB() db.tasks = {'mytask': {'_id': 'mytask', 'command': 'echo'}} assert_raises(KeyError, simcity.management.set_config, cfg) simcity.management.set_task_database(db) simcity.management.set_job_database(db) simcity.management.set_current_job_id('myjob') actor = simcity.ExecuteActor() actor.run() assert_true(db.jobs['myjob']['done'] > 0) assert_true(db.saved['mytask']['done'] > 0) assert_true(os.path.exists('tests/tmp/tmp_alala')) assert_true(os.path.exists('tests/tmp/out_alala')) assert_true(os.path.exists('tests/tmp/in_alala')) shutil.rmtree('tests/tmp')
class TestJob(): def setup(self): self.db = MockDB() self.test_id = MockDB.JOBS[0]['_id'] self.test_other_id = MockDB.JOBS[1]['_id'] simcity.set_current_job_id(self.test_id) simcity.management._job_db = self.db def test_get_job(self): job = simcity.get_job() assert_equals(job.id, self.test_id) simcity.set_current_job_id(None) assert_raises(EnvironmentError, simcity.get_job) otherJob = simcity.get_job(self.test_other_id) assert_equals(otherJob.id, self.test_other_id) assert_equals(type(otherJob), type(Job({'_id': 'aaaa'}))) def test_start_job(self): job = simcity.start_job() assert_equals(job.id, self.test_id) assert_true(job['start'] > 0) assert_true(simcity.get_job()['start'] > 0) assert_equals(job['queue'], 0) assert_equals(job['done'], 0) def test_finish_job(self): job = simcity.start_job() simcity.finish_job(job) assert_true(job['start'] > 0) assert_true(job['done'] > 0) assert_true(simcity.get_job()['done'] > 0) job = simcity.queue_job(job, 'ssh') assert_true(job['archive'] > 0) def test_queue_job(self): job = simcity.queue_job(Job({'_id': 'aaaa'}), 'ssh') assert_true(job['queue'] > 0) assert_equals(len(self.db.saved), 1) job = simcity.queue_job(simcity.get_job(), 'ssh') assert_true(job['queue'] > 0) assert_true(simcity.get_job()['queue'] > 0) job = simcity.finish_job(job) assert_true(job['archive'] > 0) def test_archive_job(self): job = simcity.get_job() self.db.save(job) job = simcity.archive_job(simcity.get_job()) assert_not_equals(job.id, self.test_id)
def setup(self): self.db = MockDB() self.test_id = MockDB.JOBS[0]['_id'] self.test_other_id = MockDB.JOBS[1]['_id'] simcity.set_current_job_id(self.test_id) simcity.management._job_db = self.db