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


Python ResourceParameter.unit方法代码示例

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


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

示例1: test_init

# 需要导入模块: from safe.common.resource_parameter import ResourceParameter [as 别名]
# 或者: from safe.common.resource_parameter.ResourceParameter import unit [as 别名]
    def test_init(self):
        unit_feet = Unit("130790")
        unit_feet.load_dictionary(unit_feet_depth)

        unit_metres = Unit("900713")
        unit_metres.load_dictionary(unit_metres_depth)

        resource_parameter = ResourceParameter()
        resource_parameter.name = "Flood Depth"
        resource_parameter.is_required = True
        resource_parameter.precision = 3
        resource_parameter.minimum_allowed_value = 1.0
        resource_parameter.maximum_allowed_value = 2.0
        resource_parameter.help_text = "The depth of flood."
        resource_parameter.description = (
            "A <b>test _description</b> that is very long so that you need "
            "to read it for one minute and you will be tired after read this "
            "description. You are the best user so far. Even better if you "
            "read this description loudly so that all of your friends will be "
            "able to hear you"
        )
        resource_parameter.unit = unit_feet
        resource_parameter.allowed_units = [unit_metres, unit_feet]
        resource_parameter.value = 1.12

        widget = ResourceParameterWidget(resource_parameter)

        expected_value = resource_parameter.name
        real_value = widget._label.text()
        message = "Expected %s get %s" % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        expected_value = resource_parameter.value
        real_value = widget.get_parameter().value
        message = "Expected %s get %s" % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget.set_value(1.5)

        expected_value = 1.5
        real_value = widget.get_parameter().value
        message = "Expected %s get %s" % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget.set_value(1.55555)

        expected_value = 1.556
        real_value = widget.get_parameter().value
        message = "Expected %s get %s" % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)

        widget.set_value(7)

        expected_value = 2
        real_value = widget.get_parameter().value
        message = "Expected %s get %s" % (expected_value, real_value)
        self.assertEqual(expected_value, real_value, message)
开发者ID:tomkralidis,项目名称:inasafe,代码行数:59,代码来源:test_resource_parameter_widget.py

示例2: test_all

# 需要导入模块: from safe.common.resource_parameter import ResourceParameter [as 别名]
# 或者: from safe.common.resource_parameter.ResourceParameter import unit [as 别名]
    def test_all(self):
        """Basic test of all properties."""
        unit = Unit()
        unit.name = "meter"
        unit.plural = "metres"
        unit.abbreviation = "m"
        unit.description = (("<b>metres</b> are a metric unit of measure. There are 100 " "centimetres in 1 metre."),)
        unit.help_text = "Help for meter unit"

        parameter = ResourceParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123
        parameter.frequency = "weekly"
        parameter.unit = unit

        self.assertEqual(1.123, parameter.value)
        self.assertDictEqual(unit.serialize(), parameter.unit.serialize())
        self.assertEqual("weekly", parameter.frequency)
开发者ID:inasafe,项目名称:inasafe,代码行数:22,代码来源:test_resource_parameter.py

示例3: test_all

# 需要导入模块: from safe.common.resource_parameter import ResourceParameter [as 别名]
# 或者: from safe.common.resource_parameter.ResourceParameter import unit [as 别名]
    def test_all(self):
        """Basic test of all properties."""
        unit = Unit()
        unit.name = 'meter'
        unit.plural = 'metres'
        unit.abbreviation = 'm'
        unit.description = (
            '<b>metres</b> are a metric unit of measure. There are 100 '
            'centimetres in 1 metre.'),
        unit.help_text = 'Help for meter unit'

        parameter = ResourceParameter()
        parameter.is_required = True
        parameter.minimum_allowed_value = 1.0
        parameter.maximum_allowed_value = 2.0
        parameter.value = 1.123
        parameter.frequency = 'weekly'
        parameter.unit = unit

        self.assertEqual(1.123, parameter.value)
        self.assertDictEqual(unit.serialize(), parameter.unit.serialize())
        self.assertEqual('weekly', parameter.frequency)
开发者ID:felix-yew,项目名称:inasafe,代码行数:24,代码来源:test_resource_parameter.py


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