@@ -833,6 +833,53 @@ def test_retained_dataset_types_invalid_yaml_raises(self):
833833 with self .assertRaises (ValueError ):
834834 script .qgraph (** {** base_kwargs , "retained_dataset_types" : retained_path })
835835
836+ def test_simple_qg_prune_unanchored_anchor_absent (self ):
837+ """With --prune-unanchored-quanta SOURCE:ANCHOR where ANCHOR does not
838+ exist in the pipeline, all source quanta are pruned and the graph is
839+ empty.
840+ """
841+ with DirectButlerRepo .make_temporary () as (helper , root ):
842+ helper .add_task ("source" )
843+ helper .add_task ("anchor" )
844+ helper .insert_datasets ("dataset_auto0" )
845+ kwargs = self ._make_run_args (
846+ "-b" ,
847+ root ,
848+ "-i" ,
849+ helper .input_chain ,
850+ "-o" ,
851+ "output" ,
852+ "--register-dataset-types" ,
853+ "--prune-unanchored-quanta" ,
854+ "source:no_such_task" ,
855+ pipeline_graph_factory = PipelineGraphFactory (pipeline_graph = helper .pipeline_graph ),
856+ )
857+ qg = script .qgraph (** kwargs )
858+ self .assertIsNone (qg )
859+
860+ def test_simple_qg_prune_unanchored_anchor_reachable (self ):
861+ """With --prune-unanchored-quanta SOURCE:ANCHOR where every source
862+ quantum has an anchor quantum downstream, nothing is pruned.
863+ """
864+ with DirectButlerRepo .make_temporary () as (helper , root ):
865+ helper .add_task ("source" )
866+ helper .add_task ("anchor" )
867+ helper .insert_datasets ("dataset_auto0" )
868+ kwargs = self ._make_run_args (
869+ "-b" ,
870+ root ,
871+ "-i" ,
872+ helper .input_chain ,
873+ "-o" ,
874+ "output" ,
875+ "--register-dataset-types" ,
876+ "--prune-unanchored-quanta" ,
877+ "source:anchor" ,
878+ pipeline_graph_factory = PipelineGraphFactory (pipeline_graph = helper .pipeline_graph ),
879+ )
880+ qg = script .qgraph (** kwargs )
881+ self .assertEqual (len (qg ), 2 )
882+
836883
837884class CoverageTestCase (unittest .TestCase ):
838885 """Test the coverage context manager."""
0 commit comments