예제 #1
0
    def test_successful_job_lifecycle(self):
        with patch('openquake.job.Job.from_file') as from_file:

            # called in place of Job.launch
            def test_status_running_and_succeed():
                self.assertEquals('running', self._job_status())

                return []

            # replaces Job.launch with a mock
            def patch_job_launch(*args, **kwargs):
                self.job = self.job_from_file(*args, **kwargs)
                self.job.launch = mock.Mock(
                    side_effect=test_status_running_and_succeed)

                self.assertEquals('pending', self._job_status())

                return self.job

            from_file.side_effect = patch_job_launch

            with patch('openquake.job.spawn_job_supervisor'):
                run_job(helpers.get_data_path(CONFIG_FILE), 'db')

        self.assertEquals(1, self.job.launch.call_count)
        self.assertEquals('succeeded', self._job_status())
예제 #2
0
    def test_invalid_job_lifecycle(self):
        with patch('openquake.job.Job.from_file') as from_file:

            # replaces Job.is_valid with a mock
            def patch_job_is_valid(*args, **kwargs):
                self.job = self.job_from_file(*args, **kwargs)
                self.job.is_valid = mock.Mock(
                    return_value=(False, ["OMG!"]))

                self.assertEquals('pending', self._job_status())

                return self.job

            from_file.side_effect = patch_job_is_valid
            run_job(helpers.get_data_path(CONFIG_FILE), 'db')

            self.assertEquals(1, self.job.is_valid.call_count)
            self.assertEquals('failed', self._job_status())
예제 #3
0
    def test_supervisor_is_spawned(self):
        with patch('openquake.job.Job.from_file') as from_file:

            # replaces Job.launch with a mock
            def patch_job_launch(*args, **kwargs):
                self.job = self.job_from_file(*args, **kwargs)
                self.job.launch = mock.Mock()

                return self.job

            from_file.side_effect = patch_job_launch

            with patch('openquake.job.spawn_job_supervisor') as mocked_func:
                run_job(helpers.get_data_path(CONFIG_FILE), 'db')

                self.assertEquals(1, mocked_func.call_count)
                self.assertEquals(((self.job.job_id, os.getpid()), {}),
                                  mocked_func.call_args)
예제 #4
0
import sys
import unittest

import git
from git import Git, Repo

from openquake import logs
from openquake import flags
from openquake import job

from openquake.hazard import job as hazjob
from openquake.hazard import opensha
from openquake.risk import job as riskjob
from openquake.risk.job import probabilistic
FLAGS = flags.FLAGS

CHECKOUT_DIR = os.path.abspath(os.path.join(
        os.path.dirname(__file__), '../OpenGemModel'))

REPO_URL = "[email protected]:gem/OpenGemModel.git"

if __name__ == '__main__':
    sys.argv = FLAGS(sys.argv)  
    logs.init_logs()
    
    # Make sure there's a checkout and it's up to date (of OpenGemModel)
    if not os.path.exists(CHECKOUT_DIR):
        repo = Repo.clone_from(REPO_URL, CHECKOUT_DIR)
    job_path = os.path.join(CHECKOUT_DIR, "tests", sys.argv[1], "config.gem")
    job.run_job(job_path)
예제 #5
0
import unittest

import git
from git import Git, Repo

from openquake import logs
from openquake import flags
from openquake import job

from openquake.hazard import job as hazjob
from openquake.hazard import opensha
from openquake.risk import job as riskjob
from openquake.risk.job import probabilistic

FLAGS = flags.FLAGS

CHECKOUT_DIR = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '../OpenGemModel'))

REPO_URL = "[email protected]:gem/OpenGemModel.git"

if __name__ == '__main__':
    sys.argv = FLAGS(sys.argv)
    logs.init_logs()

    # Make sure there's a checkout and it's up to date (of OpenGemModel)
    if not os.path.exists(CHECKOUT_DIR):
        repo = Repo.clone_from(REPO_URL, CHECKOUT_DIR)
    job_path = os.path.join(CHECKOUT_DIR, "tests", sys.argv[1], "config.gem")
    job.run_job(job_path)