def test_init(self):
        """Test FieldMappingTab initialization."""
        layer = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid_complex.geojson',
            with_keywords=False, clone_to_memory=True)
        layer.keywords = {}

        field_mapping = FieldMappingTab(age_ratio_group, PARENT, IFACE)
        field_mapping.set_layer(layer)

        # Empty keywords should give empty for all aspect
        parameter_values = field_mapping.get_parameter_value()
        self.assertEqual(parameter_values['fields'], {})
        for v in parameter_values['values'].values():
            self.assertIsNone(v)

        # Make sure all keys exist
        fields_keys = parameter_values['fields'].keys()
        values_keys = parameter_values['values'].keys()
        age_ratio_fields_keys = [field['key'] for field in age_ratio_group[
            'fields']]
        for key in fields_keys + values_keys:
            self.assertIn(key, age_ratio_fields_keys)

        # Check field list
        fields = []
        for index in xrange(field_mapping.field_list.count()):
            fields.append(field_mapping.field_list.item(index))
        labels = [i.text() for i in fields]

        for field in layer.dataProvider().fields():
            if field.type() not in qvariant_numbers:
                continue
            self.assertIn(field.name(), labels)
Exemplo n.º 2
0
    def test_init(self):
        """Test FieldMappingTab initialization."""
        layer = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid_complex.geojson',
            with_keywords=False, clone_to_memory=True)
        layer.keywords = {}

        field_mapping = FieldMappingTab(age_ratio_group, PARENT, IFACE)
        field_mapping.set_layer(layer)

        # Empty keywords should give empty for all aspect
        parameter_values = field_mapping.get_parameter_value()
        self.assertEqual(parameter_values['fields'], {})
        for v in parameter_values['values'].values():
            self.assertIsNone(v)

        # Make sure all keys exist
        fields_keys = parameter_values['fields'].keys()
        values_keys = parameter_values['values'].keys()
        age_ratio_fields_keys = [field['key'] for field in age_ratio_group[
            'fields']]
        for key in fields_keys + values_keys:
            self.assertIn(key, age_ratio_fields_keys)

        # Check field list
        fields = []
        for index in xrange(field_mapping.field_list.count()):
            fields.append(field_mapping.field_list.item(index))
        labels = [i.text() for i in fields]

        for field in layer.dataProvider().fields():
            if field.type() not in qvariant_numbers:
                continue
            self.assertIn(field.name(), labels)
Exemplo n.º 3
0
    def test_init_gender_ratio(self):
        """Test FieldMappingTab initialization for gender ratio."""
        layer = load_test_vector_layer('gisv4',
                                       'aggregation',
                                       'small_grid_complex.geojson',
                                       with_keywords=False,
                                       clone_to_memory=True)
        layer.keywords = {
            'inasafe_default_values': {
                female_ratio_field['key']: 0.7
            }
        }

        field_mapping = FieldMappingTab(gender_ratio_group, PARENT, IFACE)
        field_mapping.set_layer(layer)

        parameter_values = field_mapping.get_parameter_value()
        self.assertEqual(parameter_values['fields'], {})
        for k, v in parameter_values['values'].items():
            if k == female_ratio_field['key']:
                self.assertEqual(0.7, v)
            else:
                message = 'Key {key} gives not None, but {value}'.format(
                    key=k, value=v)
                self.assertIsNone(v, message)

        # Make sure all keys exist
        fields_keys = parameter_values['fields'].keys()
        values_keys = parameter_values['values'].keys()
        gender_ratio_fields_keys = [
            field['key'] for field in gender_ratio_group['fields']
        ]
        for key in fields_keys + values_keys:
            self.assertIn(key, gender_ratio_fields_keys)

        # Check field list
        fields = []
        for index in xrange(field_mapping.field_list.count()):
            fields.append(field_mapping.field_list.item(index))
        labels = [i.text() for i in fields]

        for field in layer.dataProvider().fields():
            if field.type() not in qvariant_numbers:
                continue
            self.assertIn(field.name(), labels)
    def test_init_gender_ratio(self):
        """Test FieldMappingTab initialization for gender ratio."""
        layer = load_test_vector_layer(
            'gisv4', 'aggregation', 'small_grid_complex.geojson',
            with_keywords=False, clone_to_memory=True)
        layer.keywords = {
            'inasafe_default_values': {
                female_ratio_field['key']: 0.7
            }
        }

        field_mapping = FieldMappingTab(gender_ratio_group, PARENT, IFACE)
        field_mapping.set_layer(layer)

        parameter_values = field_mapping.get_parameter_value()
        self.assertEqual(parameter_values['fields'], {})
        for k, v in parameter_values['values'].items():
            if k == female_ratio_field['key']:
                self.assertEqual(0.7, v)
            else:
                message = 'Key {key} gives not None, but {value}'.format(
                    key=k, value=v)
                self.assertIsNone(v, message)

        # Make sure all keys exist
        fields_keys = parameter_values['fields'].keys()
        values_keys = parameter_values['values'].keys()
        gender_ratio_fields_keys = [
            field['key'] for field in gender_ratio_group[
            'fields']]
        for key in fields_keys + values_keys:
            self.assertIn(key, gender_ratio_fields_keys)

        # Check field list
        fields = []
        for index in xrange(field_mapping.field_list.count()):
            fields.append(field_mapping.field_list.item(index))
        labels = [i.text() for i in fields]

        for field in layer.dataProvider().fields():
            if field.type() not in qvariant_numbers:
                continue
            self.assertIn(field.name(), labels)