Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obs_test Tickets/dm 8686 #27

Merged
merged 4 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions python/lsst/obs/test/testMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def _makeCamera(self, policy, repositoryDir):
class MapperForTestCalexpMetadataObjects(lsst.obs.base.CameraMapper):
packageName = "obs_test"

def __init__(self, root):
def __init__(self, root, parentRegistry=None, repositoryCfg=None):
policyFilePath = dafPersist.Policy.defaultPolicyFile(
self.packageName, "testCalexpMetadataObjects.yaml", "policy")
policy = dafPersist.Policy(policyFilePath)
super(MapperForTestCalexpMetadataObjects, self).__init__(
policy, repositoryDir=root, root=root)
policy, repositoryDir=root, root=root, parentRegistry=None, repositoryCfg=None)
self.filterIdMap = {
'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5, 'i2': 5}
# The LSST Filters from L. Jones 04/07/10
Expand All @@ -136,6 +136,3 @@ def _extractDetectorName(self, dataId):
throw (in the base class impl)
"""
return "0"



9 changes: 9 additions & 0 deletions tests/policyTest/a/repositoryCfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!RepositoryCfg_v1
_mapper: !!python/name:lsst.obs.test.testMapper.TestMapper ''
_mapperArgs: null
_parents: []
_policy: !!python/object:lsst.daf.persistence.policy.Policy
data:
exposures:
raw: {template: raw/v%(visit)d_f%(filter)s.fits.gz}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not extend our 4-space indent policy to YAML files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even think about it. 2 spaces seems to be the default for yaml.dump. I can specify the indentation level when I call dump though.
@timj is 2 spaces ok or should I specify 4?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with 2, especially if that is the default for YAML serialization.

_root: null
6 changes: 6 additions & 0 deletions tests/policyTest/b/repositoryCfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!RepositoryCfg_v1
_mapper: !!python/name:lsst.obs.test.testMapper.TestMapper ''
_mapperArgs: null
_parents: [../a]
_policy: null
_root: null
57 changes: 34 additions & 23 deletions tests/testPolicyInRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import unittest

import lsst.pex.policy
import lsst.daf.persistence as dafPersist
# we only import lsst.obs.test.TestMapper from lsst.obs.test, but use the namespace to hide it from pytest
import lsst.obs.test
import lsst.utils.tests
Expand All @@ -39,33 +40,43 @@ class PolicyTestCase(unittest.TestCase):
def testInRepoPolicyOverrides(self):
"""Verify that the template value specified in the policy file in the repository
overrides the template value set in the policy file in the package.
Checks the _parent symlink chain works.
Checks that child repositories do not get the policy from the parent (per specification).
Checks that values not specified in the local _policy file are set with those of the package's
_policy file.
"""
policyOverride = {'exposures': {'raw': {'template': "raw/v%(visit)d_f%(filter)s.fits.gz"}}}
obsTestDir = getPackageDir("obs_test")
obsTestRepoDir = os.path.join(obsTestDir, "data")
testData = (
(os.path.join(obsTestRepoDir, 'policyInRepo1/a'),
os.path.join(obsTestRepoDir, 'policyInRepo1', 'a', '_parent', '_policy.paf')),
(os.path.join(obsTestRepoDir, 'policyInRepo2/a'),
os.path.join(obsTestRepoDir, 'policyInRepo2', 'a', '_parent', '_parent', '_policy.paf'))
)

for mapperRoot, actualPolicyPath in testData:
mapper = lsst.obs.test.TestMapper(root=mapperRoot)
repoPolicy = lsst.pex.policy.Policy.createPolicy(actualPolicyPath)
template = repoPolicy.get('exposures.raw.template')
mapperTemplate = mapper.mappings['raw'].template
self.assertEqual(template, mapperTemplate)

# Run a simple test case to verify that although the package's policy was overloaded with some
# values, other values specified in the policy file in the package are loaded.
policyPath = os.path.join(obsTestDir, 'policy', 'testMapper.paf')
policy = lsst.pex.policy.Policy.createPolicy(policyPath)
template = policy.get('exposures.postISRCCD.template')
mapperTemplate = mapper.mappings['postISRCCD'].template
self.assertEqual(template, mapperTemplate)
policyPath = os.path.join(obsTestDir, 'policy', 'testMapper.paf')
policy = lsst.pex.policy.Policy.createPolicy(policyPath)
postISRCCDtemplate = policy.get('exposures.postISRCCD.template')

testDir = os.path.join(obsTestDir, 'tests', 'policyTest')
repoARoot = os.path.join(testDir, 'a')
butler = dafPersist.Butler(outputs={'root': repoARoot,
'mapper': lsst.obs.test.TestMapper,
'policy': policyOverride})

# check that the declared policy got used in the mapper
mapper = butler._repos.outputs()[0].repo._mapper
self.assertEqual(mapper.mappings['raw'].template, "raw/v%(visit)d_f%(filter)s.fits.gz")
# Run a simple test case to verify that although the package's policy was overloaded with some
# values, other values specified in the policy file in the package are loaded.
self.assertEqual(postISRCCDtemplate, mapper.mappings['postISRCCD'].template)
del butler
del mapper

repoBRoot = os.path.join(testDir, 'b')
butler = dafPersist.Butler(inputs=repoARoot, outputs=repoBRoot)
# check that the reloaded policy got used in the mapper for repo A
mapper = butler._repos.inputs()[0].repo._mapper
self.assertEqual(mapper.mappings['raw'].template, "raw/v%(visit)d_f%(filter)s.fits.gz")
# again, test that another value is loaded from package policy file is loaded correctly.
self.assertEqual(postISRCCDtemplate, mapper.mappings['postISRCCD'].template)
# also check that repo B does not get the in-repo policy from A
mapper = butler._repos.outputs()[0].repo._mapper
self.assertNotEqual(mapper.mappings['raw'].template, "raw/v%(visit)d_f%(filter)s.fits.gz")
# and again, test that another value is loaded from package policy file is loaded correctly.
self.assertEqual(postISRCCDtemplate, mapper.mappings['postISRCCD'].template)


class MemoryTester(lsst.utils.tests.MemoryTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_obs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def setUp(self):
map_python_type = 'lsst.afw.image.DecoratedImageU'
map_cpp_type = 'DecoratedImageU'
map_storage_name = 'FitsStorage'
metadata_output_path = os.path.join(data_dir, 'processCcd_metadata', 'v1_fg.boost')
metadata_output_path = os.path.join('processCcd_metadata', 'v1_fg.boost')
raw_filename = 'raw_v1_fg.fits.gz'
default_level = 'visit'
raw_levels = (('skyTile', set(['filter'])),
Expand Down