summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDoug Harris <dharris@truthinitiative.org>2018-05-14 16:12:45 -0400
committerDoug Harris <dharris@truthinitiative.org>2018-05-15 10:21:28 -0400
commit1ac1fb35b13f459e8a9e0f08e68a203ce76ae44d (patch)
tree24d8bb302414daffc4f7d27549232b6e0275fb68 /tests
parent43cb9864680283af37416d3b6ac186fab9bd73ff (diff)
downloadclick-1ac1fb35b13f459e8a9e0f08e68a203ce76ae44d.tar.gz
Better handling of help text for dynamic default option values
Diffstat (limited to 'tests')
-rw-r--r--tests/test_options.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/test_options.py b/tests/test_options.py
index 97b8d90..e8057fa 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -174,6 +174,33 @@ def test_multiple_default_type(runner):
'two --arg2 4 four'.split())
assert not result.exception
+def test_dynamic_default_help_unset(runner):
+ @click.command()
+ @click.option('--username', prompt=True,
+ default=lambda: os.environ.get('USER', ''),
+ show_default=True)
+ def cmd(username):
+ print("Hello,", username)
+
+ result = runner.invoke(cmd, ['--help'])
+ assert result.exit_code == 0
+ assert '--username' in result.output
+ assert 'lambda' not in result.output
+ assert '(dynamic)' in result.output
+
+def test_dynamic_default_help_text(runner):
+ @click.command()
+ @click.option('--username', prompt=True,
+ default=lambda: os.environ.get('USER', ''),
+ show_default='current user')
+ def cmd(username):
+ print("Hello,", username)
+
+ result = runner.invoke(cmd, ['--help'])
+ assert result.exit_code == 0
+ assert '--username' in result.output
+ assert 'lambda' not in result.output
+ assert '(current user)' in result.output
def test_nargs_envvar(runner):
@click.command()
@@ -302,7 +329,6 @@ def test_multiline_help(runner):
assert ' i am' in out
assert ' multiline' in out
-
def test_argument_custom_class(runner):
class CustomArgument(click.Argument):
def get_default(self, ctx):