当前位置: 首页>>代码示例>>Python>>正文


Python KeywordsDialog.age_ratios_are_valid方法代码示例

本文整理汇总了Python中safe_qgis.tools.keywords_dialog.KeywordsDialog.age_ratios_are_valid方法的典型用法代码示例。如果您正苦于以下问题:Python KeywordsDialog.age_ratios_are_valid方法的具体用法?Python KeywordsDialog.age_ratios_are_valid怎么用?Python KeywordsDialog.age_ratios_are_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在safe_qgis.tools.keywords_dialog.KeywordsDialog的用法示例。


在下文中一共展示了KeywordsDialog.age_ratios_are_valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_check_aggregation

# 需要导入模块: from safe_qgis.tools.keywords_dialog import KeywordsDialog [as 别名]
# 或者: from safe_qgis.tools.keywords_dialog.KeywordsDialog import age_ratios_are_valid [as 别名]
    def test_check_aggregation(self):
        """Test for keywords dialog's behavior for aggregation layer."""
        layer = clone_shp_layer(
            name='kabupaten_jakarta',
            include_keywords=True,
            source_directory=BOUNDDATA)
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)

        # Load existing keywords
        keywords = dialog.get_keywords()
        expected_keywords = {
            'category': 'postprocessing',
            'aggregation attribute': 'KAB_NAME',
            'title': 'kabupaten jakarta',
            'elderly ratio attribute': 'Global default',
            'youth ratio default': '0.263',
            'source': 'OpenStreetMap',
            'elderly ratio default': '0.078',
            'adult ratio attribute': 'Global default',
            'female ratio attribute': 'Global default',
            'youth ratio attribute': 'Global default',
            'female ratio default': '0.5',
            'adult ratio default': '0.659'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Don't Use
        dialog.cboYouthRatioAttribute.setCurrentIndex(1)
        keywords = dialog.get_keywords()
        expected_keywords = {
            'category': 'postprocessing',
            'aggregation attribute': 'KAB_NAME',
            'title': 'kabupaten jakarta',
            'elderly ratio attribute': 'Global default',
            'source': 'OpenStreetMap',
            'elderly ratio default': '0.078',
            'adult ratio attribute': 'Global default',
            'female ratio attribute': 'Global default',
            'youth ratio attribute': 'Don\'t use',
            'female ratio default': '0.5',
            'adult ratio default': '0.659'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Global Default
        # Change youth ratio default to 0.99
        dialog.cboYouthRatioAttribute.setCurrentIndex(0)
        dialog.dsbYouthRatioDefault.setValue(0.99)
        keywords = dialog.get_keywords()
        expected_keywords = {
            'category': 'postprocessing',
            'aggregation attribute': 'KAB_NAME',
            'title': 'kabupaten jakarta',
            'elderly ratio attribute': 'Global default',
            'youth ratio default': '0.99',
            'source': 'OpenStreetMap',
            'elderly ratio default': '0.078',
            'adult ratio attribute': 'Global default',
            'female ratio attribute': 'Global default',
            'youth ratio attribute': 'Global default',
            'female ratio default': '0.5',
            'adult ratio default': '0.659'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (False, good_sum_ratio)
        self.assertEqual(False, good_sum_ratio, message)

        # We need to delete reference to layer on Windows before removing
        # the files
        del layer
        del dialog.layer
        # Using clone_shp_layer the files are saved in testing dir under
        # InaSAFE temp dir
        shutil.rmtree(temp_dir(sub_dir='testing'))
开发者ID:cccs-ip,项目名称:inasafe,代码行数:86,代码来源:test_keywords_dialog.py


注:本文中的safe_qgis.tools.keywords_dialog.KeywordsDialog.age_ratios_are_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。