def test_purgeImpliedArgs(self, mockGetCollectionType):
        """Verify the arguments implied by --purge.

        --purge <run> implies the following arguments to butler.pruneDatasets:
        purge=True, run=<run>, disassociate=True, unstore=True
        And for QueryDatasets, if COLLECTIONS is not passed then <run> gets
        used as the value of COLLECTIONS (and when there is a COLLECTIONS
        value then find_first gets set to True)
        """
        self.run_test(
            cliArgs=["--purge", "run"],
            invokeInput="yes",
            exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(
                purge=True,
                run="run",
                refs=getDatasets(),
                disassociate=True,
                unstore=True
            ),
            exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                               collections=("run",),
                                                               find_first=True),
            exGetTablesCalled=True,
            exMsgs=(pruneDatasets_willRemoveMsg,
                    pruneDatasets_askContinueMsg,
                    astropyTablesToStr(getTables()),
                    pruneDatasets_didRemoveAforementioned)
        )
    def test_disassociateImpliedArgs(self):
        """Verify the arguments implied by --disassociate.

        --disassociate <tags> implies the following arguments to
        butler.pruneDatasets:
        disassociate=True, tags=<tags>
        and if COLLECTIONS is not passed then <tags> gets used as the value
        of COLLECTIONS.

        Use the --no-confirm flag instead of invokeInput="yes", and check for
        the associated output.
        """
        self.run_test(
            cliArgs=["--disassociate", "tag1", "--disassociate", "tag2", "--no-confirm"],
            exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(
                tags=("tag1", "tag2"),
                disassociate=True,
                refs=getDatasets()
            ),
            exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                               collections=("tag1", "tag2"),
                                                               find_first=True),
            exGetTablesCalled=True,
            exMsgs=(pruneDatasets_didRemoveMsg,
                    astropyTablesToStr(getTables()))
        )
    def test_dryRun_unstore(self):
        """Test the --dry-run flag with --unstore.

        Verify that with the dry-run flag the subcommand says what it would
        remove, but does not remove the datasets."""
        self.run_test(cliArgs=["myCollection", "--dry-run", "--unstore"],
                      exPruneDatasetsCallArgs=None,
                      exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                                         collections=("myCollection",)),
                      exGetTablesCalled=True,
                      exMsgs=(pruneDatasets_wouldRemoveMsg,
                              astropyTablesToStr(getTables())))
    def test_dryRun_unstoreAndDisassociate(self):
        """Test the --dry-run flag with --unstore and --disassociate.

        Verify that with the dry-run flag the subcommand says what it would
        remove, but does not remove the datasets. """
        collection = "myCollection"
        self.run_test(cliArgs=[collection, "--dry-run", "--unstore", "--disassociate", "tag1"],
                      exPruneDatasetsCallArgs=None,
                      exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                                         collections=(collection,)),
                      exGetTablesCalled=True,
                      exMsgs=(pruneDatasets_wouldDisassociateAndRemoveMsg.format(collections=(collection,)),
                              astropyTablesToStr(getTables())))
    def test_noConfirm(self):
        """Test the --no-confirm flag.

        Verify that with the no-confirm flag the subcommand does not ask for
        a confirmation, prints the did remove message and the tables that were
        passed for removal."""
        self.run_test(cliArgs=["myCollection", "--no-confirm", "--unstore"],
                      exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(refs=getDatasets(),
                                                                         unstore=True),
                      exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                                         collections=("myCollection",)),
                      exGetTablesCalled=True,
                      exMsgs=(pruneDatasets_didRemoveMsg,
                              astropyTablesToStr(getTables())))
    def test_defaults_doContinue(self):
        """Test running with the default values.

        Verify that with the default flags that the subcommand says what it
        will do, prompts for input, and says that it's done."""
        self.run_test(cliArgs=["myCollection", "--unstore"],
                      exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(refs=getDatasets(),
                                                                         unstore=True),
                      exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                                         collections=("myCollection",)),
                      exGetTablesCalled=True,
                      exMsgs=(pruneDatasets_willRemoveMsg,
                              pruneDatasets_askContinueMsg,
                              astropyTablesToStr(getTables()),
                              pruneDatasets_didRemoveAforementioned),
                      invokeInput="yes")
 def test_disassociateImpliedArgsWithCollections(self):
     """Verify the arguments implied by --disassociate, with a --collection
     flag."""
     self.run_test(
         cliArgs=["myCollection", "--disassociate", "tag1", "--disassociate", "tag2", "--no-confirm"],
         exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(
             tags=("tag1", "tag2"),
             disassociate=True,
             refs=getDatasets()
         ),
         exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(repo=self.repo,
                                                            collections=("myCollection",),
                                                            find_first=True),
         exGetTablesCalled=True,
         exMsgs=(pruneDatasets_didRemoveMsg,
                 astropyTablesToStr(getTables()))
     )
 def test_purgeImpliedArgsWithCollections(self, mockGetCollectionType):
     """Verify the arguments implied by --purge, with a COLLECTIONS."""
     self.run_test(cliArgs=["myCollection", "--purge", "run"],
                   invokeInput="yes",
                   exPruneDatasetsCallArgs=self.makePruneDatasetsArgs(
                       purge=True,
                       run="run",
                       disassociate=True,
                       unstore=True,
                       refs=getDatasets()),
                   exQueryDatasetsCallArgs=self.makeQueryDatasetsArgs(
                       repo=self.repo,
                       collections=("myCollection", ),
                       find_first=True),
                   exGetTablesCalled=True,
                   exMsgs=(pruneDatasets_willRemoveMsg,
                           pruneDatasets_askContinueMsg,
                           astropyTablesToStr(getTables()),
                           pruneDatasets_didRemoveAforementioned))