本文整理汇总了Python中lsst.pex.policy.Policy.nameCount方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.nameCount方法的具体用法?Python Policy.nameCount怎么用?Python Policy.nameCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.pex.policy.Policy
的用法示例。
在下文中一共展示了Policy.nameCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMergeDefaults
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import nameCount [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, e:
self.assert_(e.args[0].getErrors("required")
== ValidationError.MISSING_REQUIRED)
示例2: testMergeDefaults
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import nameCount [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.")
示例3: Policy
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import nameCount [as 别名]
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.assertRaisesEx(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.")
# test the sample code at http://dev.lsstcorp.org/trac/wiki/PolicyHowto
def testSampleCode(self):