Пример #1
0
 def test_constructor_with_valid_input(self):
     """
     Test that the JobConfigWriter constructor does not throw any errors
     with known-good input combinations.
     """
     config_writer.JobConfigWriter(
         1234, derive_imls_from_vuln=True, num_of_derived_imls=2)
     config_writer.JobConfigWriter(
         1234, derive_imls_from_vuln=True, num_of_derived_imls=25)
     # num_of_derived_imls should be ignored if derive_imls_from_vuln is not
     # set to True
     config_writer.JobConfigWriter(1234, num_of_derived_imls=-2)
     config_writer.JobConfigWriter(1234, serialize_results_to_db=True)
     config_writer.JobConfigWriter(1234, serialize_results_to_db=False)
Пример #2
0
def prepare_inputs(job):
    """Prepare a config.gem file and symbolic links to the other input files.

    :param job: the :py:class:`geonode.mtapi.models.OqJob` instance in question
    """
    cw = config_writer.JobConfigWriter(job.id)
    cw.serialize()
    for an_input in job.oq_params.upload.input_set.all().order_by("id"):
        basename = os.path.basename(an_input.path)
        os.symlink(an_input.path, os.path.join(job.path, basename))
    def test_classical_config_file_generation_no_serialize_results_to_db(self):
        """
        By default, config files are generated with the [general] parameter
        SERIALIZE_RESULTS_TO_DB set to True. This test exercises config file
        creation with the parameter set to False.
        """
        expected_config = tests.test_data_path('config_no_serialize_to_db.gem')

        cfg_writer = config_writer.JobConfigWriter(
            self.oqjob.id, serialize_results_to_db=False)

        path_to_new_cfg_file = cfg_writer.serialize()

        self._test_config_files_are_the_same(expected_config,
                                             path_to_new_cfg_file,
                                             self.oqjob.id)
    def test_classical_config_file_generation_with_vuln_imls(self):
        """
        Test that the config file output has the proper IML values,
        as determined by the job's vulnerability model.
        """
        expected_config = tests.test_data_path('config_with_vuln_imls.gem')

        cfg_writer = config_writer.JobConfigWriter(self.oqjob.id,
                                                   derive_imls_from_vuln=True,
                                                   num_of_derived_imls=15)

        path_to_new_cfg_file = cfg_writer.serialize()

        self._test_config_files_are_the_same(expected_config,
                                             path_to_new_cfg_file,
                                             oqjob_id=self.oqjob.id)
    def test_classical_config_file_generation(self):
        """
        This is somewhat of a 'blackbox' test. We have an existing 'expected'
        config file; given our sample data (which this test suite has loaded
        into the database), we simply generate a config file and compare it to
        the expected file.
        """
        out_path = os.path.join(self.job_dir, 'config.gem')
        expected_config = tests.test_data_path('expected_config.gem')

        cfg_writer = config_writer.JobConfigWriter(self.oqjob.id)

        path_to_new_cfg_file = cfg_writer.serialize()

        # check that the result directory is what we specified
        self.assertEqual(os.path.abspath(out_path),
                         os.path.abspath(path_to_new_cfg_file))

        self._test_config_files_are_the_same(expected_config,
                                             path_to_new_cfg_file,
                                             oqjob_id=self.oqjob.id)
Пример #6
0
    def test_write_params(self):
        """
        Exercise the private _write_params method. Basically, create a
        JobConfigWriter, call `_write_params`, and verify that the params were
        written to the ConfigParser object of the JobConfigWriter.
        """

        fake_job_id = 1234
        test_params = {
            'general': {'REGION_GRID_SPACING': 0.1},
            'HAZARD': {'MINIMUM_MAGNITUDE': 5.0},
            'RISK': {'CONDITIONAL_LOSS_POE': '0.01 0.10'}}
        cfg_writer = config_writer.JobConfigWriter(fake_job_id)

        cfg_writer._write_params(test_params)

        cfg_parser = cfg_writer.cfg_parser

        for section in test_params.keys():
            self.assertTrue(cfg_parser.has_section(section))

            for k, v in test_params[section].items():
                # we expected the str equivalent of whatever the value is
                self.assertEqual(str(v), cfg_parser.get(section, k))