Skip to content

Commit

Permalink
Make sure bands exist in DCR subfilter registration test.
Browse files Browse the repository at this point in the history
It shouldn't be possible to register a subfilter that references a band
that doesn't exist; this is a variant of DM-40818.

*If* one does manage to register such a subfilter, querying for it with
a band constraint (as the CLI script does) is ill-defined - should it
return no records since the band does not exist?  Or should it return
the referencing subfilter recoreds anyway?  The previous test assumed
the latter, but changes to daf_butler on this ticket are changing the
behavior to the former.  Registering the band (by registering an
instrument and hence some physical_filters) first here avoids that
ill-defined behavior, and it should make this test continue to work
when DM-40818 is done.
  • Loading branch information
TallJimbo committed Jan 4, 2024
1 parent 4544ed0 commit 0800bd0
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tests/test_cliCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,38 +183,46 @@ def testRegisterFilters(self):
result = self.runner.invoke(butlerCli, ["create", self.repo])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))

result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "3", "foo"])
# Since a subfilter requires a band, and a band is implied by a
# physical_filter, we register an instrument to define these.
result = self.runner.invoke(
butlerCli,
["register-instrument", self.repo, "lsst.obs.base.instrument_tests.DummyCam"],
)
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertIn(registerDcrSubfilters.registeredMsg.format(band="foo", subfilters="[0, 1, 2]"),

result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "3", "u"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertIn(registerDcrSubfilters.registeredMsg.format(band="u", subfilters="[0, 1, 2]"),
result.output)

result = self.runner.invoke(butlerCli, ["query-dimension-records", self.repo, "subfilter"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertAstropyTablesEqual(
AstropyTable((("foo", "foo", "foo"), (0, 1, 2)), names=("band", "id")),
AstropyTable((("u", "u", "u"), (0, 1, 2)), names=("band", "id")),
readTable(result.output))

# Verify expected output message for registering subfilters in a
# band that already has subfilters
result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "5", "foo"])
result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "5", "u"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertIn(registerDcrSubfilters.notRegisteredMsg.format(band="foo", subfilters="[0, 1, 2]"),
self.assertIn(registerDcrSubfilters.notRegisteredMsg.format(band="u", subfilters="[0, 1, 2]"),
result.output)

# Add subfilters for two filters, one new filter and one existing.
# Verify expected result messages and registry values.
result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "3", "foo", "bar"])
result = self.runner.invoke(butlerCli, ["register-dcr-subfilters", self.repo, "3", "u", "g"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertIn(registerDcrSubfilters.notRegisteredMsg.format(band="foo", subfilters="[0, 1, 2]"),
self.assertIn(registerDcrSubfilters.notRegisteredMsg.format(band="u", subfilters="[0, 1, 2]"),
result.output)
self.assertIn(registerDcrSubfilters.registeredMsg.format(band="bar", subfilters="[0, 1, 2]"),
self.assertIn(registerDcrSubfilters.registeredMsg.format(band="g", subfilters="[0, 1, 2]"),
result.output)
result = self.runner.invoke(butlerCli, ["query-dimension-records", self.repo, "subfilter"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
resultTable = readTable(result.output)
resultTable.sort(["band", "id"])
self.assertAstropyTablesEqual(
AstropyTable((("bar", "bar", "bar", "foo", "foo", "foo"),
AstropyTable((("g", "g", "g", "u", "u", "u"),
(0, 1, 2, 0, 1, 2)), names=("band", "id")),
resultTable)

Expand Down

0 comments on commit 0800bd0

Please sign in to comment.