Skip to content

Commit

Permalink
Handle deprecation in query-datasets test
Browse files Browse the repository at this point in the history
Collections and dataset type arguments are becoming mandatory, so add them to tests that were using the default 'all' values.
  • Loading branch information
dhirving committed Oct 14, 2024
1 parent ecf452d commit 900a39e
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions tests/test_cliCmdQueryDatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def testChained(self):
self.repoDir, configFile=os.path.join(TESTDIR, "config/basic/butler-chained.yaml")
)

tables = self._queryDatasets(repo=testRepo.butler, show_uri=True)
tables = self._queryDatasets(repo=testRepo.butler, show_uri=True, collections="*", glob="*")

# Want second datastore root since in-memory is ephemeral and
# all the relevant datasets are stored in the second as well as third
Expand All @@ -192,7 +192,7 @@ def testShowURI(self):
"""Test for expected output with show_uri=True."""
testRepo = MetricTestRepo(self.repoDir, configFile=self.configFile)

tables = self._queryDatasets(repo=testRepo.butler, show_uri=True)
tables = self._queryDatasets(repo=testRepo.butler, show_uri=True, collections="*", glob="*")

roots = testRepo.butler.get_datastore_roots()
datastore_root = list(roots.values())[0]
Expand All @@ -209,7 +209,7 @@ def testShowUriNoDisassembly(self):
storageClassName="StructuredCompositeReadCompNoDisassembly",
)

tables = self._queryDatasets(repo=testRepo.butler, show_uri=True)
tables = self._queryDatasets(repo=testRepo.butler, show_uri=True, collections="*", glob="*")

roots = testRepo.butler.get_datastore_roots()
datastore_root = list(roots.values())[0]
Expand Down Expand Up @@ -252,7 +252,7 @@ def testNoShowURI(self):
"""Test for expected output without show_uri (default is False)."""
testRepo = MetricTestRepo(self.repoDir, configFile=self.configFile)

tables = self._queryDatasets(repo=testRepo.butler)
tables = self._queryDatasets(repo=testRepo.butler, collections="*", glob="*")

expectedTables = (
AstropyTable(
Expand All @@ -274,7 +274,9 @@ def testWhere(self):
"""
testRepo = MetricTestRepo(self.repoDir, configFile=self.configFile)

tables = self._queryDatasets(repo=testRepo.butler, where="instrument='DummyCamComp' AND visit=423")
tables = self._queryDatasets(
repo=testRepo.butler, where="instrument='DummyCamComp' AND visit=423", collections="*", glob="*"
)

expectedTables = (
AstropyTable(
Expand All @@ -286,7 +288,7 @@ def testWhere(self):
self.assertAstropyTablesEqual(tables, expectedTables, filterColumns=True)

with self.assertRaises(RuntimeError):
self._queryDatasets(repo=testRepo.butler, collections="*", find_first=True)
self._queryDatasets(repo=testRepo.butler, collections="*", find_first=True, glob="*")

def testGlobDatasetType(self):
"""Test specifying dataset type."""
Expand All @@ -311,7 +313,7 @@ def testGlobDatasetType(self):
testRepo.addDataset(dataId={"instrument": "DummyCamComp", "visit": 425}, datasetType=datasetType)

# verify the new dataset type increases the number of tables found:
tables = self._queryDatasets(repo=testRepo.butler)
tables = self._queryDatasets(repo=testRepo.butler, collections="*", glob="*")

expectedTables = (
AstropyTable(
Expand All @@ -331,13 +333,19 @@ def testGlobDatasetType(self):

self.assertAstropyTablesEqual(tables, expectedTables, filterColumns=True)

# Dataset type (glob) argument will become mandatory soon
with self.assertWarns(FutureWarning):
self._queryDatasets(repo=testRepo.butler, collections="*")

def test_limit_order(self):
"""Test limit and ordering."""
# Create and register an additional DatasetType
testRepo = MetricTestRepo(self.repoDir, configFile=self.configFile)

with self.assertLogs("lsst.daf.butler.script.queryDatasets", level="WARNING") as cm:
tables = self._queryDatasets(repo=testRepo.butler, limit=-1, order_by=("visit"))
tables = self._queryDatasets(
repo=testRepo.butler, limit=-1, order_by=("visit"), collections="*", glob="*"
)

self.assertIn("increase this limit", cm.output[0])

Expand All @@ -350,7 +358,9 @@ def test_limit_order(self):
self.assertAstropyTablesEqual(tables, expectedTables, filterColumns=True)

with self.assertLogs("lsst.daf.butler.script.queryDatasets", level="WARNING") as cm:
tables = self._queryDatasets(repo=testRepo.butler, limit=-1, order_by=("-visit"))
tables = self._queryDatasets(
repo=testRepo.butler, limit=-1, order_by=("-visit"), collections="*", glob="*"
)
self.assertIn("increase this limit", cm.output[0])

expectedTables = [
Expand All @@ -376,7 +386,7 @@ def testFindFirstAndCollections(self):
testRepo.butler.collections.redefine_chain("chain", ["foo", "ingest/run"])

# Verify that without find-first, duplicate datasets are returned
tables = self._queryDatasets(repo=testRepo.butler, collections=["chain"], show_uri=True)
tables = self._queryDatasets(repo=testRepo.butler, collections=["chain"], show_uri=True, glob="*")

# The test should be running with a single FileDatastore.
roots = testRepo.butler.get_datastore_roots()
Expand Down Expand Up @@ -519,7 +529,7 @@ def testFindFirstAndCollections(self):
# Verify that with find first the duplicate dataset is eliminated and
# the more recent dataset is returned.
tables = self._queryDatasets(
repo=testRepo.butler, collections=["chain"], show_uri=True, find_first=True
repo=testRepo.butler, collections=["chain"], show_uri=True, find_first=True, glob="*"
)

expectedTables = (
Expand Down Expand Up @@ -621,7 +631,13 @@ def testFindFirstAndCollections(self):

# Verify that globs are not supported with find_first=True.
with self.assertRaises(RuntimeError):
self._queryDatasets(repo=testRepo.butler, collections=["*"], show_uri=True, find_first=True)
self._queryDatasets(
repo=testRepo.butler, collections=["*"], show_uri=True, find_first=True, glob="*"
)

# Collections argument will become mandatory soon
with self.assertWarns(FutureWarning):
self._queryDatasets(repo=testRepo.butler, glob="*")


if __name__ == "__main__":
Expand Down

0 comments on commit 900a39e

Please sign in to comment.