本文整理汇总了Python中pyon.core.bootstrap.IonObject.unsigned_short_int方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.unsigned_short_int方法的具体用法?Python IonObject.unsigned_short_int怎么用?Python IonObject.unsigned_short_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.core.bootstrap.IonObject
的用法示例。
在下文中一共展示了IonObject.unsigned_short_int方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decorator_validation
# 需要导入模块: from pyon.core.bootstrap import IonObject [as 别名]
# 或者: from pyon.core.bootstrap.IonObject import unsigned_short_int [as 别名]
def test_decorator_validation(self):
#
# Test required values
#
obj = IonObject('Deco_Example', {"list1": [1], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "us_phone_number": "555-555-5555"})
# Should fail because required value not provided
self.assertRaises(AttributeError, obj._validate)
obj.an_important_value = {"key": "value"}
# Should work now that we have set a value for the required field
obj._validate
#
# Test collection content types validation
#
# List
obj = IonObject('Deco_Example', {"list1": ["Should be a numeric type"], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
self.assertRaises(AttributeError, obj._validate)
obj.list1 = [1, 2]
# Should work now that list content has been corrected
obj._validate
# Dict
obj = IonObject('Deco_Example', {"list1": [1], "list2": ["One element"], "dict1": {"key1": "Should be a numeric type"}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
# Should fail because dict value contains non-numeric value
self.assertRaises(AttributeError, obj._validate)
obj.dict1 = {"key1": 1}
# Should work now that dict value content has been corrected
obj._validate
#
# Test collection length
#
# List
obj = IonObject('Deco_Example', {"list1": [1,2], "list2": [], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
# Should fail since list has zero length
self.assertRaises(AttributeError, obj._validate)
obj.list2 = ["Item 1", "Item 2"]
# Should work new that item length of list has been corrected
obj._validate
# Dict
obj = IonObject('Deco_Example', {"list1": [1,2], "list2": [1,2], "dict1": {"key1": 1}, "dict2": {}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
# Should fail since dict has zero length
self.assertRaises(AttributeError, obj._validate)
obj.dict2 = {"key1": 1}
# Should work new that item length of dict has been corrected
obj._validate
#
# Test numeric value range
#
# int
obj = IonObject('Deco_Example', {"list1": [1,2], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "unsigned_short_int": -1, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
self.assertRaises(AttributeError, obj._validate)
obj.unsigned_short_int = 256
# Should work
obj._validate
# float
obj = IonObject('Deco_Example', {"list1": [1,2], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "a_float": 10.11, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
self.assertRaises(AttributeError, obj._validate)
obj.a_float = 1.234
# Should work
obj._validate
#
# Test string pattern matching
#
obj = IonObject('Deco_Example', {"list1": [1,2], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "5555555555"})
self.assertRaises(AttributeError, obj._validate)
obj.us_phone_number = "555-555-5555"
# Should work
obj._validate