Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-27685 Add butler make gen3 dcr subfilters subcommand #449

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/lsst/daf/butler/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def addArgumentHelp(doc, helpText):
doc = doc.split("\f")[0]

doclines = doc.splitlines()
# The function's docstring may span multiple lines, so combine the
# docstring from all the first lines until a blank line is encountered.
# (Lines after the first blank line will be argument help.)
while len(doclines) > 1 and doclines[1]:
doclines[0] = " ".join((doclines[0], doclines.pop(1).strip()))
doclines.insert(1, helpText)
doclines.insert(1, "\n")
doc = "\n".join(doclines)
Expand Down
39 changes: 27 additions & 12 deletions tests/test_cliUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,36 @@

class ArgumentHelpGeneratorTestCase(unittest.TestCase):

@staticmethod
@click.command()
# Use custom help in the arguments so that any changes to default help text
# do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli help message."""
pass
def testHelp(self):
@click.command()
# Use custom help in the arguments so that any changes to default help
# text do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli help message."""
pass

def test_help(self):
self.runTest(cli)

def testHelpWrapped(self):
@click.command()
# Use custom help in the arguments so that any changes to default help
# text do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli
help
message."""
pass
self.runTest(cli)

def runTest(self, cli):
"""Tests `utils.addArgumentHelp` and its use in repo_argument and
directory_argument; verifies that the argument help gets added to the
command fucntion help, and that it's added in the correct order. See
addArgumentHelp for more details."""
runner = LogCliRunner()
result = runner.invoke(ArgumentHelpGeneratorTestCase.cli, ["--help"])
expected = """Usage: cli [OPTIONS] REPO DIRECTORY

The cli help message.
Expand All @@ -70,6 +83,8 @@ def test_help(self):
Options:
--help Show this message and exit.
"""
runner = LogCliRunner()
result = runner.invoke(cli, ["--help"])
self.assertIn(expected, result.output)


Expand Down