def testPafReader(self): """Test that Butler Policy can read a paf file and the keys compare the same as when the same file is read as a pex Policy.""" pexPolicy = lsst.pex.policy.Policy.createPolicy(pafPolicyPath) policy = lsst.daf.persistence.Policy(pafPolicyPath) # go back through the newly created Butler Policy, and verify that values match the paf Policy for name in policy.names(): if pexPolicy.isArray(name): pexVal = pexPolicy.getArray(name) else: pexVal = pexPolicy.get(name) val = policy[name] if isinstance(val, lsst.daf.persistence.Policy): self.assertEqual(pexPolicy.getValueType(name), pexPolicy.POLICY) else: self.assertEqual(val, pexVal) for name in pexPolicy.names(): if pexPolicy.getValueType(name) == pexPolicy.POLICY: self.assertIsInstance(policy.get(name), lsst.daf.persistence.Policy) else: if pexPolicy.isArray(name): pexVal = pexPolicy.getArray(name) else: pexVal = pexPolicy.get(name) self.assertEqual(pexVal, policy.get(name)) # verify a known value, just for sanity: self.assertEqual(policy.get('exposures.raw.template'), 'raw/raw_v%(visit)d_f%(filter)s.fits.gz')
def testPafReader(self): """Test that Butler Policy can read a paf file and the keys compare the same as when the same file is read as a pex Policy.""" pexPolicy = lsst.pex.policy.Policy.createPolicy(pafPolicyPath) policy = lsst.daf.persistence.Policy(pafPolicyPath) # go back through the newly created Butler Policy, and verify that values match the paf Policy for name in policy.names(): if pexPolicy.isArray(name): pexVal = pexPolicy.getArray(name) else: pexVal = pexPolicy.get(name) val = policy[name] if isinstance(val, lsst.daf.persistence.Policy): self.assertEqual(pexPolicy.getValueType(name), pexPolicy.POLICY) else: self.assertEqual(val, pexVal) for name in pexPolicy.names(): if pexPolicy.getValueType(name) == pexPolicy.POLICY: self.assertIsInstance(policy.get(name), lsst.daf.persistence.Policy) else: if pexPolicy.isArray(name): pexVal = pexPolicy.getArray(name) else: pexVal = pexPolicy.get(name) self.assertEqual(pexVal, policy.get(name)) # verify a known value, just for sanity: self.assertEqual(policy.get('exposures.raw.template'), 'raw/raw_v%(visit)d_f%(filter)s.fits.gz')
def __initFromPexPolicy(self, pexPolicy): """Load values from a pex policy. :param pexPolicy: :return: """ names = pexPolicy.names() names.sort() for name in names: if pexPolicy.getValueType(name) == pexPolicy.POLICY: if name in self: continue else: self[name] = {} else: if pexPolicy.isArray(name): self[name] = pexPolicy.getArray(name) else: self[name] = pexPolicy.get(name) return self
def __initFromPexPolicy(self, pexPolicy): """Load values from a pex policy. :param pexPolicy: :return: """ names = pexPolicy.names() names.sort() for name in names: if pexPolicy.getValueType(name) == pexPolicy.POLICY: if name in self: continue else: self[name] = {} else: if pexPolicy.isArray(name): self[name] = pexPolicy.getArray(name) else: self[name] = pexPolicy.get(name) return self