本文整理匯總了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]')