Coverage for tests/test_UrnPolicyFile_1.py : 24%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # # LSST Data Management System # Copyright 2008, 2009, 2010 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# TODO: test cross-package loading more thoroughly -- mix up the packages and # repositories in a deeply nested and linked policy file.
""" Expect callableObj(args, kwargs) to raise an exception of type excClass, and carres a message that contains excMsg.
excClass: the subclass of LsstCppException we expect to see excMsg: a substring of the message it should carry callableObj: the thing that, when called, should raise an exception failMsg: the assertion message if this fails args, kwargs (optional): arguments to pass to callableObj """ try: callableObj(*args, **kwargs) except excClass as e: self.assertGreater(str(e).find(excMsg), 0, failMsg + ": expected to see the message \"" + excMsg + "\"; actual message was \"" + str(e) + "\".") else: self.fail(failMsg + ": did not raise " + excClass)
if not self.examplesDir: # XXX is this really the best way to find the src_dir? pexPolicyDir = lsst.utils.getPackageDir('pex_policy') self.examplesDir = os.path.join(pexPolicyDir, "examples") if filename: return os.path.join(self.examplesDir, filename) else: return self.examplesDir
addr = "pex_policy:examples:EventTransmitter_policy.paf" p = Policy()
p.set("transmitter.logVerbosity", "not") UrnPolicyFile(addr).load(p) self.assertEqual(p.get("transmitter.logVerbosity"), "debug")
p.set("transmitter.logVerbosity", "not") UrnPolicyFile("urn:eupspkg:" + addr).load(p) self.assertEqual(p.get("transmitter.logVerbosity"), "debug")
p.set("transmitter.logVerbosity", "not") UrnPolicyFile("@@" + addr).load(p) self.assertEqual(p.get("transmitter.logVerbosity"), "debug")
urn = "@urn:eupspkg:pex_policy:tests/urn:indirect_parent_good.paf" p = Policy(urn) self.assertEqual(p.get("urn_full.name"), "Simple Policy") self.assertEqual(p.get("urn_brief.name"), "Simple Policy") self.assertEqual(p.get("urn_mixed_case.name"), "Simple Policy") self.assertEqual(p.get("local.foo"), "bar")
p = Policy() UrnPolicyFile("pex_policy:tests/urn:level_1.paf").load(p) self.assertEqual(p.get("foo.bar.baz.qux.quux"), "schmazzle")
p = Policy("urn:eupspkg:pex_policy:tests/urn:level_1.paf") self.assertEqual(p.get("foo.bar.baz.qux.quux"), "schmazzle")
self.assertRaiseLCE(BadNameError, "Wrong number of terms", Policy, "URN too short", "urn:eupspkg:foo.paf") self.assertRaiseLCE(lsst.pex.exceptions.IoError, "failure opening Policy file", Policy, "URN abbrev '@' not allowed in constructor", "@pex_policy:tests/urn:level_1.paf")
urn = "urn:eupspkg:pex_policy:tests/dictionary:defaults_dictionary_good.paf" self.assertRaiseLCE(lsst.pex.exceptions.IoError, "/./defaults_dictionary_indirect", Policy.createPolicyFromUrn, "doesn't support loading undecorated DictionaryFile", urn) urn = "urn:eupspkg:pex_policy:tests/dictionary:defaults_dictionary_partial.paf" p = Policy.createPolicyFromUrn(urn) # make sure all reference types worked # self.assertEqual(p.get("indirect.string_type"), "foo") # self.assertEqual(p.get("indirect2.string_type"), "foo") self.assertEqual(p.get("indirect3.string_type"), "foo") self.assertEqual(p.get("indirect4.string_type"), "foo")
base = "pex_policy:tests/urn:indirect_parent_typo_" self.assertRaiseLCE(lsst.pex.exceptions.IoError, "failure opening Policy file", UrnPolicyFile(base + "1.paf").load, "Typo in URN", Policy()) self.assertRaiseLCE(lsst.pex.exceptions.IoError, "failure opening Policy file", UrnPolicyFile(base + "2.paf").load, "Typo in URN", Policy())
# when the repository is mis-specified, local files cannot be loaded upf = UrnPolicyFile("pex_policy:tests:urn/indirect_parent_good.paf") # we expect it to look in <package>/tests/simple.paf pexPolicyDir = lsst.utils.getPackageDir('pex_policy') expectedFile = pexPolicyDir + "/tests/simple.paf" self.assertRaiseLCE(lsst.pex.exceptions.IoError, "failure opening Policy file: " + expectedFile, upf.load, "Wrong repository dir.", Policy())
# a PAF file designed to have "tests" as it repository p = Policy() UrnPolicyFile("pex_policy:tests:urn/local_tests_repos.paf").load(p) self.assertEqual(p.get("local.polish"), "fancy")
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |