本文整理汇总了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)
示例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()
示例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")