本文整理汇总了Python中lsst.pex.policy.Policy.getArray方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.getArray方法的具体用法?Python Policy.getArray怎么用?Python Policy.getArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.pex.policy.Policy
的用法示例。
在下文中一共展示了Policy.getArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BigBoolTestCase
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getArray [as 别名]
class BigBoolTestCase(unittest.TestCase):
def setUp(self):
self.policy = Policy()
def tearDown(self):
del self.policy
def testBigBoolArray(self):
biglen = 1000
self.policy.isBool("true")
for i in range(biglen):
self.policy.add("true", True)
v = self.policy.getArray("true")
self.assertEqual(len(v), biglen, "wrong big number of values in array")
for i in range(biglen):
self.assertTrue(v[i], "big array with bad value")
del v
self.assertTrue(True, "Blew up True")
fd = open("/dev/null", "w")
print("look: %s" % True, file=fd)
fd.close()
示例2: testPolicySetget
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getArray [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))
示例3: PolicyBlackboardItem
# 需要导入模块: from lsst.pex.policy import Policy [as 别名]
# 或者: from lsst.pex.policy.Policy import getArray [as 别名]
class PolicyBlackboardItem(BlackboardItem):
"""
An implementation of a BlackboardItem that stores properities via a
policy
"""
def __init__(self, policyfile=None):
"""
create an item with the given properties.
@param policyfile A policy
"""
# the properties attached to this items
self._props = None
if policyfile:
self._props = Policy.createPolicy(policyfile)
else:
self._props = Policy()
def getProperty(self, name, default=None):
"""
return the value for a property
@param name the property name
@parma default the default value to return if the name is not set
"""
if not self._props.exists(name):
return default
elif self._props.isArray(name):
return self._props.getArray(name)
else:
return self._props.get(name)
def hasProperty(self, name):
"""
return True if the property with the given name is available
"""
return self._props.exists(name)
def __getitem__(self, name):
if not self._props.exists(name):
raise KeyError(name)
return BlackboardItem.__getitem__(self, name)
def _setProperty(self, name, val):
# set a property value
if isinstance(val, list):
self._props.set(name, val.pop(0))
for v in val:
self._props.add(name, v)
else:
self._props.set(name, val)
def getPropertyNames(self):
"""
return the property names that make up this item
"""
return self._props.names()
def _copyFrom(self, item):
for name in item.getPropertyNames():
self._setProperty(name, item.getProperty(name))
@staticmethod
def createFormatter():
return PolicyBlackboardItem._Fmtr()
class _Fmtr(object):
def write(self, filename, item):
pol = None
if isinstance(item, PolicyBlackboardItem):
pol = item._props
else:
delegate = PolicyBlackboardItem()
delegate._copyFrom(item)
pol = delegate._props
writer = PAFWriter(filename)
try:
writer.write(pol, True)
finally:
writer.close()
def openItem(self, filename):
out = PolicyBlackboardItem()
out._props = Policy.createPolicy(filename)
return out
def filenameExt(self):
"""
return the recommended extension for the format this writes out
"""
return "paf"