Skip to content

Commit

Permalink
Merge pull request #279 from lsst/tickets/DM-26160
Browse files Browse the repository at this point in the history
DM-26160: Update tests to use ButlerURI.exists rather than os.path.exists
  • Loading branch information
timj committed Jul 31, 2020
2 parents e8380d5 + 705c5b2 commit 0eb5a41
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/test_butlerFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ def setUpClass(cls):
"visit": [42, 43, 44],
}

cls.creatorButler = makeTestRepo(cls.root, dataIds, config=Config.fromYaml(BUTLER_CONFIG))
# Ensure that we test in a directory that will include some
# metacharacters
subdir = "sub?#dir"
butlerRoot = os.path.join(cls.root, subdir)

cls.creatorButler = makeTestRepo(butlerRoot, dataIds, config=Config.fromYaml(BUTLER_CONFIG))

# Create dataset types used by the tests
for datasetTypeName, storageClassName in (("calexp", "ExposureF"),
Expand Down Expand Up @@ -199,7 +204,7 @@ def testExposureCompositePutGetConcrete(self) -> None:
ref = self.runExposureCompositePutGetTest("calexp")

uri = self.butler.getURI(ref)
self.assertTrue(os.path.exists(uri.path), f"Checking URI {uri} existence")
self.assertTrue(uri.exists(), f"Checking URI {uri} existence")

def testExposureCompositePutGetVirtual(self) -> None:
"""Testing composite disassembly"""
Expand All @@ -209,7 +214,7 @@ def testExposureCompositePutGetVirtual(self) -> None:
self.assertIsNone(primary)
self.assertEqual(set(components), COMPONENTS)
for compName, uri in components.items():
self.assertTrue(os.path.exists(uri.path),
self.assertTrue(uri.exists(),
f"Checking URI {uri} existence for component {compName}")

def runExposureCompositePutGetTest(self, datasetTypeName: str) -> DatasetRef:
Expand Down Expand Up @@ -258,7 +263,7 @@ def runExposureCompositePutGetTest(self, datasetTypeName: str) -> DatasetRef:
self.assertEqual(component.getCanonicalName(), reference.getCanonicalName())
elif compName == "visitInfo":
self.assertEqual(component.getExposureId(), reference.getExposureId(),
f"VisitInfo comparison")
"VisitInfo comparison")
elif compName == "metadata":
# The component metadata has extra fields in it so cannot
# compare directly.
Expand Down Expand Up @@ -290,7 +295,7 @@ def putFits(self, exposure, datasetTypeName, visit):
dataId = {"visit": visit, "instrument": "DummyCam", "physical_filter": "d-r"}
refC = self.butler.put(exposure, datasetTypeName, dataId)
uriC = self.butler.getURI(refC)
stat = os.stat(uriC.path)
stat = os.stat(uriC.ospath)
size = stat.st_size
metaDatasetTypeName = DatasetType.nameWithComponent(datasetTypeName, "metadata")
meta = self.butler.get(metaDatasetTypeName, dataId)
Expand Down

0 comments on commit 0eb5a41

Please sign in to comment.