本文整理汇总了Python中lsst.pex.policy.Policy.canValidate方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.canValidate方法的具体用法?Python Policy.canValidate怎么用?Python Policy.canValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.pex.policy.Policy
的用法示例。
在下文中一共展示了Policy.canValidate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSelfValidation
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import canValidate [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 canValidate [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: testSampleCode
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import canValidate [as 别名]
def testSampleCode(self):
policyFile = DefaultPolicyFile("pex_policy", "defaults_dictionary_complete.paf",
"tests/dictionary")
defaults = Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True)
policy = Policy()
policy.mergeDefaults(defaults)
self.assert_(policy.canValidate())
policy = Policy()
policy.mergeDefaults(defaults, False)
self.assert_(not policy.canValidate())
# even if not keeping it around for future validation, validate the merge now
policy = Policy()
policy.set("bad", "worse")
self.assertValidationError(ValidationError.UNKNOWN_NAME,
policy.mergeDefaults, defaults, False)
self.assert_(not policy.canValidate())
示例4: testMergeDefaults
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import canValidate [as 别名]
def testMergeDefaults(self):
# from a non-trivial dictionary
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
p.set("required", "foo")
d = Dictionary(self.getTestDictionary("defaults_dictionary_good.paf"))
d.loadPolicyFiles(self.getTestDictionary(), True)
self.assert_(p.nameCount() == 2)
p.mergeDefaults(d)
self.assert_(p.valueCount("int_range_count") == 3)
self.assert_(p.nameCount() == 7)
# from a policy that's really a dictionary
p = Policy()
pd = Policy(self.getTestDictionary("defaults_dictionary_indirect.paf"))
p.mergeDefaults(pd)
self.assert_(p.getString("string_type") == "foo")
self.assert_(p.getDictionary().isDictionary())
# from a policy that's really a non-trivial dictionary
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
p.set("required", "foo")
pd = Policy(self.getTestDictionary("defaults_dictionary_policy.paf"))
pd.loadPolicyFiles(self.getTestDictionary(), True)
self.assert_(p.nameCount() == 2)
p.mergeDefaults(pd)
self.assert_(p.valueCount("int_range_count") == 3)
self.assert_(p.nameCount() == 5)
# ensure post-load validation
p.set("int_range_count", -5)
self.assertValidationError(ValidationError.UNKNOWN_NAME,
p.add, "unknown", 0)
# test throwing validation
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
try:
p.mergeDefaults(pd)
except ValidationError as ve:
self.assert_(ve.getErrors("required")
== ValidationError.MISSING_REQUIRED)
# non-throwing validation
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
ve = ValidationError("Dictionary_1.py", 1, "testMergeDefaults")
p.mergeDefaults(pd, False, ve.cpp)
self.assert_(ve.getErrors("required") == ValidationError.MISSING_REQUIRED)
self.assert_(ve.getParamCount() == 1)
# non-retention
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
p.set("required", "foo")
p.mergeDefaults(pd, False)
# make sure validate() fails gracefully when no dictionary present
self.assertRaiseLCE(DictionaryError, "No dictionary",
p.validate, "No dictionary assigned")
p.add("unknown", 0) # would be rejected if dictionary was kept
# deep merge from a Policy that's not a Dictionary
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
p.mergeDefaults(Policy(self.getTestDictionary("defaults_policy_most.paf")))
self.assert_(p.nameCount() == 3)
self.assert_(p.getBool("bool_set_count") == True)
self.assert_(p.getString("indirect.string_type") == "bar")
# propagation of a Dictionary from one Policy to another via mergeDefaults
d = Dictionary(self.getTestDictionary("defaults_dictionary_complete.paf"))
d.loadPolicyFiles(self.getTestDictionary())
pEmpty = Policy()
pEmpty.mergeDefaults(d)
self.assert_(pEmpty.canValidate())
pPartial = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
pPartial.mergeDefaults(pEmpty)
self.assert_(pPartial.canValidate(), "Dictionary handed off via mergeDefaults.")
示例5: Policy
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import canValidate [as 别名]
p.validate, "No dictionary assigned")
p.add("unknown", 0) # would be rejected if dictionary was kept
# deep merge from a Policy that's not a Dictionary
p = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
p.mergeDefaults(Policy(self.getTestDictionary("defaults_policy_most.paf")))
self.assert_(p.nameCount() == 3)
self.assert_(p.getBool("bool_set_count") == True)
self.assert_(p.getString("indirect.string_type") == "bar")
# propagation of a Dictionary from one Policy to another via mergeDefaults
d = Dictionary(self.getTestDictionary("defaults_dictionary_complete.paf"))
d.loadPolicyFiles(self.getTestDictionary())
pEmpty = Policy()
pEmpty.mergeDefaults(d)
self.assert_(pEmpty.canValidate())
pPartial = Policy(self.getTestDictionary("defaults_policy_partial.paf"))
pPartial.mergeDefaults(pEmpty)
self.assert_(pPartial.canValidate(), "Dictionary handed off via mergeDefaults.")
# test the sample code at http://dev.lsstcorp.org/trac/wiki/PolicyHowto
def testSampleCode(self):
policyFile = DefaultPolicyFile("pex_policy", "defaults_dictionary_complete.paf",
"tests/dictionary")
defaults = Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True)
policy = Policy()
policy.mergeDefaults(defaults)
self.assert_(policy.canValidate())
policy = Policy()
policy.mergeDefaults(defaults, False)