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


Python Policy.setDictionary方法代码示例

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


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

示例1: testSelfValidation

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import setDictionary [as 别名]
    def testSelfValidation(self):
        # assign a dictionary after creation
        p = Policy(self.getTestDictionary("types_policy_good.paf"))
        p.loadPolicyFiles(self.getTestDictionary(), True)
        typesDict = Dictionary(self.getTestDictionary("types_dictionary.paf"))
        valuesDict = Dictionary(self.getTestDictionary("values_dictionary.paf"))
        self.assert_(not p.canValidate())
        p.setDictionary(typesDict)
        self.assert_(p.canValidate())
        p.validate()
        p.set("bool_type", True)
        self.assertValidationError(
            ValidationError.WRONG_TYPE, p.set, "bool_type", "foo")

        # create with dictionary
        p = Policy.createPolicy(self.getTestDictionary("types_dictionary.paf"), "", True)
        self.assert_(p.canValidate())
        p.set("bool_type", True)
        self.assertValidationError(
            ValidationError.WRONG_TYPE, p.set, "bool_type", "foo")

        # assign a dictionary after invalid modifications
        p = Policy()
        p.set("bool_type", "foo")
        p.setDictionary(typesDict)
        ve = ValidationError("Dictionary_1.py", 1, "testSelfValidation")
        p.validate(ve)
        self.assert_(ve.getErrors("bool_type") == ValidationError.WRONG_TYPE)
        try:
            p.validate()
        except ValidationError, e:
            ve = e.args[0]
            self.assert_(ve.getErrors("bool_type") == ValidationError.WRONG_TYPE)
            self.assert_(ve.getParamCount() == 1)
开发者ID:lsst-dm,项目名称:bp,代码行数:36,代码来源:Dictionary_1.py

示例2: testSelfValidation

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import setDictionary [as 别名]
    def testSelfValidation(self):
        # assign a dictionary after creation
        p = Policy(self.getTestDictionary("types_policy_good.paf"))
        p.loadPolicyFiles(self.getTestDictionary(), True)
        typesDict = Dictionary(self.getTestDictionary("types_dictionary.paf"))
        valuesDict = Dictionary(self.getTestDictionary("values_dictionary.paf"))
        self.assert_(not p.canValidate())
        p.setDictionary(typesDict)
        self.assert_(p.canValidate())
        p.validate()
        p.set("bool_type", True)
        self.assertValidationError(
            ValidationError.WRONG_TYPE, p.set, "bool_type", "foo")

        # create with dictionary
        p = Policy.createPolicy(self.getTestDictionary("types_dictionary.paf"), "", True)
        self.assert_(p.canValidate())
        p.set("bool_type", True)
        self.assertValidationError(
            ValidationError.WRONG_TYPE, p.set, "bool_type", "foo")

        # assign a dictionary after invalid modifications
        p = Policy()
        p.set("bool_type", "foo")
        p.setDictionary(typesDict)
        ve = ValidationError("Dictionary_1.py", 1, "testSelfValidation")
        p.validate(ve.cpp)
        self.assert_(ve.getErrors("bool_type") == ValidationError.WRONG_TYPE)
        try:
            p.validate()
        except ValidationError as ve:
            self.assert_(ve.getErrors("bool_type") == ValidationError.WRONG_TYPE)
            self.assert_(ve.getParamCount() == 1)
        p.set("bool_type", True)
        p.set("int_type", 1)
        p.validate()

        # switch dictionaries
        oldD = p.getDictionary()
        p.setDictionary(valuesDict)
        try:
            p.validate()
        except ValidationError as ve:
            self.assert_(ve.getErrors("bool_type")
                         == ValidationError.UNKNOWN_NAME)
        p.set("string_range_type", "moo")
        try:
            p.set("string_range_type", "victor")
        except ValidationError as ve:
            self.assert_(ve.getErrors("string_range_type")
                         == ValidationError.VALUE_OUT_OF_RANGE)
        p.setDictionary(oldD)
        p.remove("string_range_type")
        p.validate()
开发者ID:jonathansick-shadow,项目名称:pex_policy,代码行数:56,代码来源:Dictionary_1.py

示例3: testEmptySubdict

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import setDictionary [as 别名]
    def testEmptySubdict(self):
        d = Dictionary(self.getTestDictionary("empty_subdictionary.paf"))
        p = Policy()
        p.set("empty_required", Policy(self.getTestDictionary("simple_policy.paf")))
        p.mergeDefaults(d)
        self.assert_(p.get("empty_sub_with_default.foo") == "bar")
        p.setDictionary(d)
        # this works because there is a definition for "empty_sub_with_default.foo"
        p.set("empty_sub_with_default.foo", "baz")

        p2 = Policy()
        p2.set("foo", "baz")
        p.set("empty_sub_no_default", p2)
        # this fails because Policy tries to makeDef("empty_sub_no_default.foo")
        # which fails because there's only a definition for "empty_sub_no_default",
        # but it doesn't contain any sub-definitions
        # p.set("empty_sub_no_default.foo", "baz")
        self.assertRaiseLCE(DictionaryError,
                            "empty_sub_no_default.dictionary not found",
                            p.set, "Empty policy definition -- if this fails, "
                            "it means a known bug has been fixed.  That's good.",
                            "empty_sub_no_default.foo", "baz")
开发者ID:jonathansick-shadow,项目名称:pex_policy,代码行数:24,代码来源:Dictionary_1.py


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