@@ -207,6 +207,22 @@ def test_run_2_snaps(self):
207207
208208 self ._check_run (calibrate , result )
209209
210+ def test_run_no_optionals (self ):
211+ """Test that disabling optional outputs removes them from the output
212+ struct, as appropriate.
213+ """
214+ self .config .optional_outputs = None
215+ calibrate = CalibrateImageTask (config = self .config )
216+ calibrate .astrometry .setRefObjLoader (self .ref_loader )
217+ calibrate .photometry .match .setRefObjLoader (self .ref_loader )
218+ result = calibrate .run (exposures = self .exposure )
219+
220+ self ._check_run (calibrate , result )
221+ # These are the only optional outputs that require extra computation,
222+ # the others are included in the output struct regardless.
223+ self .assertNotIn ("astrometry_matches" , result .getDict ())
224+ self .assertNotIn ("photometry_matches" , result .getDict ())
225+
210226 def test_handle_snaps (self ):
211227 calibrate = CalibrateImageTask (config = self .config )
212228 self .assertEqual (calibrate ._handle_snaps (self .exposure ), self .exposure )
@@ -543,30 +559,39 @@ def test_runQuantum_2_snaps(self):
543559 self .assertEqual (mock_run .call_args .kwargs .keys (), {"exposures" , "result" , "id_generator" })
544560
545561 def test_runQuantum_no_optional_outputs (self ):
546- config = CalibrateImageTask .ConfigClass ()
547- config .optional_outputs = None
548- task = CalibrateImageTask (config = config )
549- lsst .pipe .base .testUtils .assertValidInitOutput (task )
550-
551- quantum = lsst .pipe .base .testUtils .makeQuantum (
552- task , self .butler , self .visit_id ,
553- {"exposures" : [self .exposure0_id ],
554- "astrometry_ref_cat" : [self .htm_id ],
555- "photometry_ref_cat" : [self .htm_id ],
556- # outputs
557- "exposure" : self .visit_id ,
558- "stars" : self .visit_id ,
559- "stars_footprints" : self .visit_id ,
560- "applied_photo_calib" : self .visit_id ,
561- "background" : self .visit_id ,
562- })
563- mock_run = lsst .pipe .base .testUtils .runTestQuantum (task , self .butler , quantum )
564-
565- # Ensure the reference loaders have been configured.
566- self .assertEqual (task .astrometry .refObjLoader .name , "gaia_dr3_20230707" )
567- self .assertEqual (task .photometry .match .refObjLoader .name , "ps1_pv3_3pi_20170110" )
568- # Check that the proper kwargs are passed to run().
569- self .assertEqual (mock_run .call_args .kwargs .keys (), {"exposures" , "result" , "id_generator" })
562+ # All the possible connections: we modify this to test each one by
563+ # popping off the removed connection, then re-setting it.
564+ connections = {"exposures" : [self .exposure0_id , self .exposure1_id ],
565+ "astrometry_ref_cat" : [self .htm_id ],
566+ "photometry_ref_cat" : [self .htm_id ],
567+ # outputs
568+ "exposure" : self .visit_id ,
569+ "stars" : self .visit_id ,
570+ "stars_footprints" : self .visit_id ,
571+ "background" : self .visit_id ,
572+ "psf_stars" : self .visit_id ,
573+ "psf_stars_footprints" : self .visit_id ,
574+ "applied_photo_calib" : self .visit_id ,
575+ "initial_pvi_background" : self .visit_id ,
576+ "astrometry_matches" : self .visit_id ,
577+ "photometry_matches" : self .visit_id ,
578+ }
579+
580+ # Check that we can turn off one output at a time.
581+ for optional in ["psf_stars" , "psf_stars_footprints" , "astrometry_matches" , "photometry_matches" ]:
582+ config = CalibrateImageTask .ConfigClass ()
583+ config .optional_outputs .remove (optional )
584+ task = CalibrateImageTask (config = config )
585+ lsst .pipe .base .testUtils .assertValidInitOutput (task )
586+ # Save the removed one for the next test.
587+ temp = connections .pop (optional )
588+ # This will fail with "Error in connection ..." if we don't pop
589+ # the optional item from the connections list just above.
590+ quantum = lsst .pipe .base .testUtils .makeQuantum (task , self .butler , self .visit_id , connections )
591+ # This confirms that the outputs did skip the removed one.
592+ self .assertNotIn (optional , quantum .outputs )
593+ # Restore the one we removed for the next test.
594+ connections [optional ] = temp
570595
571596 def test_lintConnections (self ):
572597 """Check that the connections are self-consistent.
0 commit comments