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


Python Policy.getBool方法代码示例

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


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

示例1: testMergeDefaults

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getBool [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.")
开发者ID:jonathansick-shadow,项目名称:pex_policy,代码行数:75,代码来源:Dictionary_1.py

示例2: testPolicySetget

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getBool [as 别名]
    def testPolicySetget(self):
        p = Policy()
        self.assert_(not p.exists("foo"), "empty existence test failed")
        self.assertEqual(p.valueCount("foo.bar"), 0,
                         "empty valueCount test failed")

        self.assertRaises(NameNotFound, p.getTypeInfo, "foo")

        p.set("doall", "true")

        # non-existence tests on a non-empty policy
        self.failUnless(not p.exists("foo"),
                        "non-empty non-existence test failed")
        self.assertEqual(p.valueCount("foo.bar"), 0,
                         "empty valueCount test failed")
        self.failUnless(not p.isInt("foo"),
                        "non-empty non-existence type test failed")
        self.assertRaises(NameNotFound, p.getTypeInfo, "foo")

        # existence tests
        self.assert_(p.exists("doall"), "non-empty existence test failed")
        self.assertEquals(p.valueCount("doall"), 1,
                          "single valueCount test failed")

        self.assertRaises(Exception, p.getInt, "doall")
        self.assertRaises(Exception, p.getDoubleArray, "doall")

        self.assertEquals(p.get("doall"), "true",
                          "top-level getString failed")
        p.set("doall", "duh")
        self.assertEquals(p.get("doall"), "duh",
                          "top-level getString failed")
        
        # test array access
        ary = p.getArray("doall")
        self.assertEquals(len(ary), 1,
                          "scalar property has more than one value")


        self.assertEquals(ary[0], "duh", "scalar access via array failed")

        p.add("doall", "never")
        self.assertEquals(p.valueCount("doall"), 2,
                          "2-elem. valueCount test failed")
        self.assertEquals(p.get("doall"), "never", "top-level add failed")
        ary = p.getArray("doall")
        self.assertEquals(len(ary), 2,
                          "scalar property has wrong number of values")
        self.assertEquals(ary[0], "duh",
                          "scalar access via (2-el) array failed")
        self.assertEquals(ary[-1], "never",
                          "scalar access via (2-el) array failed")

        # test hierarchical access

        # list names

        # test types
        p.set("pint", 5)
        self.assertEquals(p.getInt("pint"), 5, "support for type int failed")
        self.assertEquals(type(p.get("pint")), type(5),
                          "auto-typing for int failed")
        p.set("pdbl", 5.1)
        self.assertAlmostEquals(p.getDouble("pdbl"), 5.1, 7, 
                                "support for type double failed")
        self.assertEquals(type(p.get("pdbl")), type(5.1),
                          "auto-typing for double failed")
        p.set("pbool", True)
        self.assert_(p.getBool("pbool"), "support for type bool failed")
        self.assertEquals(type(p.get("pbool")), type(True),
                          "auto-typing for bool failed")
        p.add("pbool", False)

        # test shallow & deep copies

        # test raise NameNotFound if not present
        try:
            p.get("nonexistent")
            self.fail() # should never reach here
        except Exception, e:
            self.assert_(isinstance(e, NameNotFound))
开发者ID:lsst-dm,项目名称:bp,代码行数:83,代码来源:Policy_1.py

示例3: Policy

# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getBool [as 别名]
        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):
        policyFile = DefaultPolicyFile("pex_policy", "defaults_dictionary_complete.paf",
开发者ID:lsst-dm,项目名称:bp,代码行数:33,代码来源:Dictionary_1.py


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