本文整理汇总了Python中safe.common.resource_parameter.ResourceParameter.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceParameter.serialize方法的具体用法?Python ResourceParameter.serialize怎么用?Python ResourceParameter.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.common.resource_parameter.ResourceParameter
的用法示例。
在下文中一共展示了ResourceParameter.serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_evacuated_population_needs
# 需要导入模块: from safe.common.resource_parameter import ResourceParameter [as 别名]
# 或者: from safe.common.resource_parameter.ResourceParameter import serialize [as 别名]
def test_evacuated_population_needs(self):
"""Test evacuated_population_needs function."""
water = ResourceParameter()
water.name = 'Water'
water.unit.name = 'litre'
water.unit.abbreviation = 'l'
water.unit.plural = 'litres'
water.frequency = 'weekly'
water.maximum_allowed_value = 10
water.minimum_allowed_value = 0
water.value = 5
rice = ResourceParameter()
rice.name = 'Rice'
rice.unit.name = 'kilogram'
rice.unit.abbreviation = 'kg'
rice.unit.plural = 'kilograms'
rice.frequency = 'daily'
rice.maximum_allowed_value = 1
rice.minimum_allowed_value = 0
rice.value = 0.5
total_needs = evacuated_population_needs(
10,
[water.serialize(), rice.serialize()]
)
self.assertEqual(total_needs['weekly'][0]['name'], 'Water')
self.assertEqual(total_needs['weekly'][0]['amount'], 50)
self.assertEqual(total_needs['weekly'][0]['table name'], 'Water [l]')
self.assertEqual(total_needs['daily'][0]['name'], 'Rice')
self.assertEqual(total_needs['daily'][0]['amount'], 5)
self.assertEqual(total_needs['daily'][0]['table name'], 'Rice [kg]')