From 0800bd04611ca689dd6fc348ba2276a7b0b3c79b Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Thu, 4 Jan 2024 10:43:31 -0500 Subject: [PATCH] Make sure bands exist in DCR subfilter registration test. 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. --- tests/test_cliCmd.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/test_cliCmd.py b/tests/test_cliCmd.py index 1217c7963c..3837cd1e1d 100644 --- a/tests/test_cliCmd.py +++ b/tests/test_cliCmd.py @@ -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)