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


Python IonObject.a_float方法代码示例

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


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

示例1: test_decorator_validation

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import a_float [as 别名]

#.........这里部分代码省略.........
                "dict2": {"key1": 1},
                "unsigned_short_int": -1,
                "an_important_value": "good value",
                "us_phone_number": "555-555-5555",
            },
        )

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.unsigned_short_int = 256

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should work
        validate_interceptor.incoming(invoke)

        # float
        decorator_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",
            },
        )

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.a_float = 1.234

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should work
        validate_interceptor.incoming(invoke)

        #
        # Test string pattern matching
        #
        decorator_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",
            },
        )

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.us_phone_number = "555-555-5555"

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True
        invoke.headers["raise-exception"] = True

        # Should work
        validate_interceptor.incoming(invoke)

        # Check to see if the class level decorators were set properly
        deco_value = decorator_obj.get_class_decorator_value("SpecialObject")
        self.assertEqual(deco_value, "")
        deco_value = decorator_obj.get_class_decorator_value("OriginResourceType")
        self.assertEqual(deco_value, "MyObject")
        deco_value = decorator_obj.get_class_decorator_value("Unknown")
        self.assertEqual(deco_value, None)
开发者ID:shenrie,项目名称:pyon,代码行数:104,代码来源:interceptor_test.py

示例2: test_decorator_validation

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import a_float [as 别名]

#.........这里部分代码省略.........
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should fail since list has zero length
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.list2 = ["Item 1", "Item 2"]

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should work new that item length of list has been corrected
        validate_interceptor.incoming(invoke)
        
        # Dict
        decorator_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"})

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should fail since dict has zero length
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.dict2 = {"key1": 1}

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should work new that item length of dict has been corrected
        validate_interceptor.incoming(invoke)

        #
        # Test numeric value range
        #
        # int
        decorator_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"})

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.unsigned_short_int = 256

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should work
        validate_interceptor.incoming(invoke)

        # float
        decorator_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"})

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.a_float = 1.234

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should work
        validate_interceptor.incoming(invoke)

        #
        # Test string pattern matching
        #
        decorator_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"})

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should fail
        with self.assertRaises(BadRequest):
            validate_interceptor.incoming(invoke)

        decorator_obj.us_phone_number = "555-555-5555"

        invoke = Invocation()
        invoke.message = decorator_obj
        invoke.headers["validate"] = True

        # Should work
        validate_interceptor.incoming(invoke)
开发者ID:daf,项目名称:pyon,代码行数:104,代码来源:interceptor_test.py


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