Exemple #1
0
    def test_large_rating_from_criteria_csv(self):
        """HRA: exception raised when rating is larger than maximum rating."""
        from natcap.invest.hra import _get_criteria_dataframe, _get_overlap_dataframe

        # Use a criteria CSV that's missing a criteria type
        bad_criteria_table_path = os.path.join(
            self.workspace_dir, 'bad_criteria.csv')
        _make_criteria_csv(
            bad_criteria_table_path, self.workspace_dir, large_rating=True)

        with self.assertRaises(ValueError) as cm:
            criteria_df = _get_criteria_dataframe(bad_criteria_table_path)
            _get_overlap_dataframe(
                criteria_df, ['habitat_0', 'habitat_1'],
                {'stressor_0': ['criteria 3', 'criteria 4'],
                 'stressor_1': ['criteria 5', 'criteria 6']},
                3, self.workspace_dir, self.workspace_dir, '')

        expected_message = 'rating 99999.0 larger than the maximum rating 3'
        actual_message = str(cm.exception)
        self.assertTrue(expected_message in actual_message, actual_message)
Exemple #2
0
    def test_missing_criteria_header(self):
        """HRA: exception raised when missing criteria from criteria CSV."""
        from natcap.invest.hra import _get_criteria_dataframe, _get_overlap_dataframe

        # Create a criteria CSV that misses a criteria type
        bad_criteria_table_path = os.path.join(
            self.workspace_dir, 'bad_criteria.csv')
        _make_criteria_csv(
            bad_criteria_table_path, self.workspace_dir, missing_criteria=True)

        with self.assertRaises(ValueError) as cm:
            criteria_df = _get_criteria_dataframe(bad_criteria_table_path)
            _get_overlap_dataframe(
                criteria_df, ['habitat_0', 'habitat_1'],
                {'stressor_0': ['criteria 3', 'criteria 4'],
                 'stressor_1': ['criteria 5', 'criteria 6']},
                3, self.workspace_dir, self.workspace_dir, '')

        expected_message = 'The following stressor-habitat pair(s)'
        actual_message = str(cm.exception)
        self.assertTrue(expected_message in actual_message, actual_message)
Exemple #3
0
    def test_wrong_criteria_type_type(self):
        """HRA: exception raised when type is not C or E from criteria CSV."""
        from natcap.invest.hra import _get_criteria_dataframe, _get_overlap_dataframe

        # Use a criteria CSV that's missing a criteria type
        bad_criteria_table_path = os.path.join(self.workspace_dir,
                                               'bad_criteria.csv')
        _make_criteria_csv(bad_criteria_table_path,
                           self.workspace_dir,
                           wrong_criteria_type=True)

        with self.assertRaises(ValueError) as cm:
            criteria_df = _get_criteria_dataframe(bad_criteria_table_path)
            _get_overlap_dataframe(
                criteria_df, ['habitat_0', 'habitat_1'], {
                    'stressor_0': ['criteria 3', 'criteria 4'],
                    'stressor_1': ['criteria 5', 'criteria 6']
                }, 3, self.workspace_dir, self.workspace_dir, '')

        expected_message = 'Criteria Type in the criteria scores table'
        actual_message = str(cm.exception)
        self.assertTrue(expected_message in actual_message, actual_message)
Exemple #4
0
    def test_wrong_weight_from_criteria_csv(self):
        """HRA: exception raised when weight is not a number from CSV."""
        from natcap.invest.hra import _get_criteria_dataframe, _get_overlap_dataframe

        # Use a criteria CSV that's missing a criteria type
        bad_criteria_table_path = os.path.join(
            self.workspace_dir, 'bad_criteria.csv')
        _make_criteria_csv(
            bad_criteria_table_path, self.workspace_dir, wrong_weight=True)

        with self.assertRaises(ValueError) as cm:
            criteria_df = _get_criteria_dataframe(bad_criteria_table_path)
            _get_overlap_dataframe(
                criteria_df, ['habitat_0', 'habitat_1'],
                {'stressor_0': ['criteria 3', 'criteria 4'],
                 'stressor_1': ['criteria 5', 'criteria 6']},
                3, self.workspace_dir, self.workspace_dir, '')

        expected_message = (
            'Weight column for habitat "habitat_0" and stressor "stressor_1"')
        actual_message = str(cm.exception)
        self.assertTrue(expected_message in actual_message, actual_message)