Skip to content

Commit

Permalink
add test for composite dotted dataset type
Browse files Browse the repository at this point in the history
  • Loading branch information
n8pease committed Oct 24, 2016
1 parent a8b5351 commit c5b6336
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions tests/testComposite.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,9 @@ class TestCompositeTestCase(unittest.TestCase):
def setUp(self):
packageDir = getPackageDir('obs_base')
self.testData = os.path.join(packageDir, 'tests', 'composite')

def tearDown(self):
if os.path.exists(self.testData):
shutil.rmtree(self.testData)

def testType3GetAndPut(self):
"""Verify that a composite can be loaded and that its components are the same as when the type1
components are loaded individually (verifies correct lookup in this case).
Also verify that when the individual components are put and when the composite is put (which
disassembles into individual components) that the objects that are written are the same.
"""

objA = dpTest.TestObject("abc")
objB = dpTest.TestObject("def")

firstRepoPath = os.path.join(self.testData, 'repo1')
secondRepoPath = os.path.join(self.testData, 'repo2')

self.firstRepoPath = os.path.join(self.testData, 'repo1')
self.objA = dpTest.TestObject("abc")
self.objB = dpTest.TestObject("def")
policy = dafPersist.Policy({'camera': 'lsst.afw.cameraGeom.Camera',
'datasets': {
'basicObject1': {
Expand All @@ -84,41 +69,78 @@ def testType3GetAndPut(self):

# We need a way to put policy into a repo. Butler does not support it yet. This is a cheat.
# The ticket to fix it is DM-7777
if not os.path.exists(firstRepoPath):
os.makedirs(firstRepoPath)
if not os.path.exists(self.firstRepoPath):
os.makedirs(self.firstRepoPath)
policy.dumpToFile(os.path.join(self.testData, 'policy.yaml'))
del policy

repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath,
repoArgs = dafPersist.RepositoryArgs(root=self.firstRepoPath,
mapper='lsst.obs.base.test.CompositeMapper',
mapperArgs={'policyDir': self.testData})
butler = dafPersist.Butler(outputs=repoArgs)
butler.put(objA, 'basicObject1', dataId={'id': 'foo'})
butler.put(objB, 'basicObject2', dataId={'name': 'bar'})
butler.put(self.objA, 'basicObject1', dataId={'id': 'foo'})
butler.put(self.objB, 'basicObject2', dataId={'name': 'bar'})
del butler
del repoArgs



def tearDown(self):
if os.path.exists(self.testData):
shutil.rmtree(self.testData)

def testType3GetAndPut(self):
"""Verify that a composite can be loaded and that its components are the same as when the type1
components are loaded individually (verifies correct lookup in this case).
Also verify that when the individual components are put and when the composite is put (which
disassembles into individual components) that the objects that are written are the same.
"""
secondRepoPath = os.path.join(self.testData, 'repo2')
# child repositories do not look up in-repo policies. We need to fix that.
# The ticket to fix this is DM-7778
repoArgs = dafPersist.RepositoryArgs(root=secondRepoPath,
mapperArgs={'policyDir': self.testData})
butler = dafPersist.Butler(inputs=firstRepoPath, outputs=repoArgs)
butler = dafPersist.Butler(inputs=self.firstRepoPath, outputs=repoArgs)
objABPair = butler.get('basicPair', dataId={'id': 'foo', 'name': 'bar'})

self.assertEqual(objA, objABPair.objA)
self.assertEqual(objB, objABPair.objB)
self.assertEqual(self.objA, objABPair.objA)
self.assertEqual(self.objB, objABPair.objB)

# For now also test that the type 1 and type 3 components are not the same object.
# When we add caching they may end up becoming the same object.
self.assertIsNot(objA, objABPair.objA)
self.assertIsNot(objB, objABPair.objB)
self.assertIsNot(self.objA, objABPair.objA)
self.assertIsNot(self.objB, objABPair.objB)

butler.put(objABPair, 'basicPair', dataId={'id': 'foo', 'name': 'bar'})
# comparing the output files directly works so long as the storage is posix:
self.assertTrue(filecmp.cmp(os.path.join(firstRepoPath, 'basic', 'idfoo.pickle'),
self.assertTrue(filecmp.cmp(os.path.join(self.firstRepoPath, 'basic', 'idfoo.pickle'),
os.path.join(secondRepoPath, 'basic', 'idfoo.pickle')))
self.assertTrue(filecmp.cmp(os.path.join(firstRepoPath, 'basic', 'namebar.pickle'),
self.assertTrue(filecmp.cmp(os.path.join(self.firstRepoPath, 'basic', 'namebar.pickle'),
os.path.join(secondRepoPath, 'basic', 'namebar.pickle')))
del butler



def testDottedDatasetType(self):
"""Verify that components of a composite can be loaded by dotted name in the form
DatasetType.componentName
"""
thirdRepoPath = os.path.join(self.testData, 'repo3')
# child repositories do not look up in-repo policies. We need to fix that.
repoArgs = dafPersist.RepositoryArgs(root=thirdRepoPath,
mapperArgs={'policyDir': self.testData})
butler = dafPersist.Butler(inputs=self.firstRepoPath, outputs=repoArgs)
componentObjA = butler.get('basicPair.a', dataId={'id': 'foo', 'name': 'bar'})
componentObjB = butler.get('basicPair.b', dataId={'id': 'foo', 'name': 'bar'})
self.assertEqual(self.objA, componentObjA)
self.assertEqual(self.objB, componentObjB)
butler.put(componentObjA, 'basicPair.a', dataId={'id': 'foo', 'name': 'bar'})
butler.put(componentObjB, 'basicPair.b', dataId={'id': 'foo', 'name': 'bar'})
# comparing the output files directly works so long as the storage is posix:
self.assertTrue(filecmp.cmp(os.path.join(self.firstRepoPath, 'basic', 'idfoo.pickle'),
os.path.join(thirdRepoPath, 'basic', 'idfoo.pickle')))
self.assertTrue(filecmp.cmp(os.path.join(self.firstRepoPath, 'basic', 'namebar.pickle'),
os.path.join(thirdRepoPath, 'basic', 'namebar.pickle')))


class MemoryTester(lsst.utils.tests.MemoryTestCase):
Expand Down

0 comments on commit c5b6336

Please sign in to comment.