diff options
| author | David Lord <davidism@gmail.com> | 2020-03-08 08:57:08 -0700 |
|---|---|---|
| committer | David Lord <davidism@gmail.com> | 2020-03-08 08:57:08 -0700 |
| commit | 718485be48263056e7036ea9a60ce11b47e2fc26 (patch) | |
| tree | 0fa1b49ed926f18ab3d247c2cacada892908123a /tests | |
| parent | f8f02bfc63cb6e63b7a3373384758f7226553408 (diff) | |
| download | click-718485be48263056e7036ea9a60ce11b47e2fc26.tar.gz | |
manual cleanup
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_arguments.py | 56 | ||||
| -rw-r--r-- | tests/test_basic.py | 55 | ||||
| -rw-r--r-- | tests/test_chain.py | 59 | ||||
| -rw-r--r-- | tests/test_commands.py | 10 | ||||
| -rw-r--r-- | tests/test_context.py | 6 | ||||
| -rw-r--r-- | tests/test_defaults.py | 14 | ||||
| -rw-r--r-- | tests/test_formatting.py | 30 | ||||
| -rw-r--r-- | tests/test_options.py | 21 | ||||
| -rw-r--r-- | tests/test_testing.py | 8 | ||||
| -rw-r--r-- | tests/test_utils.py | 8 |
10 files changed, 103 insertions, 164 deletions
diff --git a/tests/test_arguments.py b/tests/test_arguments.py index 85ba212..0b510c0 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -13,15 +13,12 @@ def test_nargs_star(runner): @click.argument("src", nargs=-1) @click.argument("dst") def copy(src, dst): - click.echo("src=%s" % "|".join(src)) - click.echo("dst=%s" % dst) + click.echo("src={}".format("|".join(src))) + click.echo("dst={}".format(dst)) result = runner.invoke(copy, ["foo.txt", "bar.txt", "dir"]) assert not result.exception - assert result.output.splitlines() == [ - "src=foo.txt|bar.txt", - "dst=dir", - ] + assert result.output.splitlines() == ["src=foo.txt|bar.txt", "dst=dir"] def test_nargs_default(runner): @@ -38,15 +35,12 @@ def test_nargs_tup(runner): @click.argument("name", nargs=1) @click.argument("point", nargs=2, type=click.INT) def copy(name, point): - click.echo("name=%s" % name) - click.echo("point=%d/%d" % point) + click.echo("name={}".format(name)) + click.echo("point={0[0]}/{0[1]}".format(point)) result = runner.invoke(copy, ["peter", "1", "2"]) assert not result.exception - assert result.output.splitlines() == [ - "name=peter", - "point=1/2", - ] + assert result.output.splitlines() == ["name=peter", "point=1/2"] def test_nargs_tup_composite(runner): @@ -62,13 +56,11 @@ def test_nargs_tup_composite(runner): @click.command() @click.argument("item", **opts) def copy(item): - click.echo("name=%s id=%d" % item) + click.echo("name={0[0]} id={0[1]:d}".format(item)) result = runner.invoke(copy, ["peter", "1"]) assert not result.exception - assert result.output.splitlines() == [ - "name=peter id=1", - ] + assert result.output.splitlines() == ["name=peter id=1"] def test_nargs_err(runner): @@ -203,7 +195,7 @@ def test_empty_nargs(runner): @click.command() @click.argument("arg", nargs=-1) def cmd(arg): - click.echo("arg:" + "|".join(arg)) + click.echo("arg:{}".format("|".join(arg))) result = runner.invoke(cmd, []) assert result.exit_code == 0 @@ -212,22 +204,22 @@ def test_empty_nargs(runner): @click.command() @click.argument("arg", nargs=-1, required=True) def cmd2(arg): - click.echo("arg:" + "|".join(arg)) + click.echo("arg:{}".format("|".join(arg))) result = runner.invoke(cmd2, []) assert result.exit_code == 2 - assert 'Missing argument "ARG..."' in result.output + assert "Missing argument 'ARG...'" in result.output def test_missing_arg(runner): @click.command() @click.argument("arg") def cmd(arg): - click.echo("arg:" + arg) + click.echo("arg:{}".format(arg)) result = runner.invoke(cmd, []) assert result.exit_code == 2 - assert 'Missing argument "ARG".' in result.output + assert "Missing argument 'ARG'." in result.output def test_missing_argument_string_cast(): @@ -260,18 +252,10 @@ def test_eat_options(runner): click.echo(f) result = runner.invoke(cmd, ["--", "-foo", "bar"]) - assert result.output.splitlines() == [ - "-foo", - "bar", - "", - ] + assert result.output.splitlines() == ["-foo", "bar", ""] result = runner.invoke(cmd, ["-f", "-x", "--", "-foo", "bar"]) - assert result.output.splitlines() == [ - "-foo", - "bar", - "-x", - ] + assert result.output.splitlines() == ["-foo", "bar", "-x"] def test_nargs_star_ordering(runner): @@ -284,11 +268,7 @@ def test_nargs_star_ordering(runner): click.echo(arg) result = runner.invoke(cmd, ["a", "b", "c"]) - assert result.output.splitlines() == [ - PY2 and "(u'a',)" or "('a',)", - "b", - "c", - ] + assert result.output.splitlines() == ["(u'a',)" if PY2 else "('a',)", "b", "c"] def test_nargs_specified_plus_star_ordering(runner): @@ -302,9 +282,9 @@ def test_nargs_specified_plus_star_ordering(runner): result = runner.invoke(cmd, ["a", "b", "c", "d", "e", "f"]) assert result.output.splitlines() == [ - PY2 and "(u'a', u'b', u'c')" or "('a', 'b', 'c')", + "(u'a', u'b', u'c')" if PY2 else "('a', 'b', 'c')", "d", - PY2 and "(u'e', u'f')" or "('e', 'f')", + "(u'e', u'f')" if PY2 else "('e', 'f')", ] diff --git a/tests/test_basic.py b/tests/test_basic.py index 59566cb..f07b6d1 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -82,7 +82,7 @@ def test_basic_option(runner): @click.command() @click.option("--foo", default="no value") def cli(foo): - click.echo("FOO:[%s]" % foo) + click.echo(u"FOO:[{}]".format(foo)) result = runner.invoke(cli, []) assert not result.exception @@ -109,7 +109,7 @@ def test_int_option(runner): @click.command() @click.option("--foo", default=42) def cli(foo): - click.echo("FOO:[%s]" % (foo * 2)) + click.echo("FOO:[{}]".format(foo * 2)) result = runner.invoke(cli, []) assert not result.exception @@ -121,7 +121,7 @@ def test_int_option(runner): result = runner.invoke(cli, ["--foo=bar"]) assert result.exception - assert 'Invalid value for "--foo": bar is not a valid integer' in result.output + assert "Invalid value for '--foo': bar is not a valid integer" in result.output def test_uuid_option(runner): @@ -131,7 +131,7 @@ def test_uuid_option(runner): ) def cli(u): assert type(u) is uuid.UUID - click.echo("U:[%s]" % u) + click.echo("U:[{}]".format(u)) result = runner.invoke(cli, []) assert not result.exception @@ -143,7 +143,7 @@ def test_uuid_option(runner): result = runner.invoke(cli, ["--u=bar"]) assert result.exception - assert 'Invalid value for "--u": bar is not a valid UUID value' in result.output + assert "Invalid value for '--u': bar is not a valid UUID value" in result.output def test_float_option(runner): @@ -151,7 +151,7 @@ def test_float_option(runner): @click.option("--foo", default=42, type=click.FLOAT) def cli(foo): assert type(foo) is float - click.echo("FOO:[%s]" % foo) + click.echo("FOO:[{}]".format(foo)) result = runner.invoke(cli, []) assert not result.exception @@ -163,7 +163,7 @@ def test_float_option(runner): result = runner.invoke(cli, ["--foo=bar"]) assert result.exception - assert 'Invalid value for "--foo": bar is not a valid float' in result.output + assert "Invalid value for '--foo': bar is not a valid float" in result.output def test_boolean_option(runner): @@ -182,7 +182,7 @@ def test_boolean_option(runner): assert result.output == "False\n" result = runner.invoke(cli, []) assert not result.exception - assert result.output == "%s\n" % default + assert result.output == "{}\n".format(default) for default in True, False: @@ -193,10 +193,10 @@ def test_boolean_option(runner): result = runner.invoke(cli, ["--flag"]) assert not result.exception - assert result.output == "%s\n" % (not default) + assert result.output == "{}\n".format(not default) result = runner.invoke(cli, []) assert not result.exception - assert result.output == "%s\n" % (default) + assert result.output == "{}\n".format(default) def test_boolean_conversion(runner): @@ -219,7 +219,7 @@ def test_boolean_conversion(runner): result = runner.invoke(cli, []) assert not result.exception - assert result.output == "%s\n" % default + assert result.output == "{}\n".format(default) def test_file_option(runner): @@ -281,7 +281,7 @@ def test_file_lazy_mode(runner): result_in = runner.invoke(input_non_lazy, ["--file=example.txt"]) assert result_in.exit_code == 2 assert ( - 'Invalid value for "--file": Could not open file: example.txt' + "Invalid value for '--file': Could not open file: example.txt" in result_in.output ) @@ -303,22 +303,17 @@ def test_path_option(runner): assert f.read() == b"meh\n" result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"]) - assert ( - 'Invalid value for "-O": Directory "test/foo.txt" is a file.' - in result.output - ) + assert "is a file" in result.output @click.command() @click.option("-f", type=click.Path(exists=True)) def showtype(f): - click.echo("is_file=%s" % os.path.isfile(f)) - click.echo("is_dir=%s" % os.path.isdir(f)) + click.echo("is_file={}".format(os.path.isfile(f))) + click.echo("is_dir={}".format(os.path.isdir(f))) with runner.isolated_filesystem(): result = runner.invoke(showtype, ["-f", "xxx"]) - assert ( - 'Error: Invalid value for "-f": Path "xxx" does not exist' in result.output - ) + assert "does not exist" in result.output result = runner.invoke(showtype, ["-f", "."]) assert "is_file=False" in result.output @@ -327,7 +322,7 @@ def test_path_option(runner): @click.command() @click.option("-f", type=click.Path()) def exists(f): - click.echo("exists=%s" % os.path.exists(f)) + click.echo("exists={}".format(os.path.exists(f))) with runner.isolated_filesystem(): result = runner.invoke(exists, ["-f", "xxx"]) @@ -350,8 +345,8 @@ def test_choice_option(runner): result = runner.invoke(cli, ["--method=meh"]) assert result.exit_code == 2 assert ( - 'Invalid value for "--method": invalid choice: meh. ' - "(choose from foo, bar, baz)" in result.output + "Invalid value for '--method': invalid choice: meh." + " (choose from foo, bar, baz)" in result.output ) result = runner.invoke(cli, ["--help"]) @@ -375,9 +370,9 @@ def test_datetime_option_default(runner): result = runner.invoke(cli, ["--start_date=2015-09"]) assert result.exit_code == 2 assert ( - 'Invalid value for "--start_date": ' - "invalid datetime format: 2015-09. " - "(choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)" + "Invalid value for '--start_date':" + " invalid datetime format: 2015-09." + " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)" ) in result.output result = runner.invoke(cli, ["--help"]) @@ -410,7 +405,7 @@ def test_int_range_option(runner): result = runner.invoke(cli, ["--x=6"]) assert result.exit_code == 2 assert ( - 'Invalid value for "--x": 6 is not in the valid range of 0 to 5.\n' + "Invalid value for '--x': 6 is not in the valid range of 0 to 5.\n" in result.output ) @@ -445,7 +440,7 @@ def test_float_range_option(runner): result = runner.invoke(cli, ["--x=6.0"]) assert result.exit_code == 2 assert ( - 'Invalid value for "--x": 6.0 is not in the valid range of 0 to 5.\n' + "Invalid value for '--x': 6.0 is not in the valid range of 0 to 5.\n" in result.output ) @@ -475,7 +470,7 @@ def test_required_option(runner): result = runner.invoke(cli, []) assert result.exit_code == 2 - assert 'Missing option "--foo"' in result.output + assert "Missing option '--foo'" in result.output def test_evaluation_order(runner): diff --git a/tests/test_chain.py b/tests/test_chain.py index 6aa452c..c227270 100644 --- a/tests/test_chain.py +++ b/tests/test_chain.py @@ -7,8 +7,9 @@ import click def debug(): click.echo( - "%s=%s" - % (sys._getframe(1).f_code.co_name, "|".join(click.get_current_context().args),) + "{}={}".format( + sys._getframe(1).f_code.co_name, "|".join(click.get_current_context().args) + ) ) @@ -76,19 +77,16 @@ def test_chaining_with_options(runner): @cli.command("sdist") @click.option("--format") def sdist(format): - click.echo("sdist called %s" % format) + click.echo("sdist called {}".format(format)) @cli.command("bdist") @click.option("--format") def bdist(format): - click.echo("bdist called %s" % format) + click.echo("bdist called {}".format(format)) result = runner.invoke(cli, ["bdist", "--format=1", "sdist", "--format=2"]) assert not result.exception - assert result.output.splitlines() == [ - "bdist called 1", - "sdist called 2", - ] + assert result.output.splitlines() == ["bdist called 1", "sdist called 2"] def test_chaining_with_arguments(runner): @@ -99,19 +97,16 @@ def test_chaining_with_arguments(runner): @cli.command("sdist") @click.argument("format") def sdist(format): - click.echo("sdist called %s" % format) + click.echo("sdist called {}".format(format)) @cli.command("bdist") @click.argument("format") def bdist(format): - click.echo("bdist called %s" % format) + click.echo("bdist called {}".format(format)) result = runner.invoke(cli, ["bdist", "1", "sdist", "2"]) assert not result.exception - assert result.output.splitlines() == [ - "bdist called 1", - "sdist called 2", - ] + assert result.output.splitlines() == ["bdist called 1", "sdist called 2"] def test_pipeline(runner): @@ -146,24 +141,15 @@ def test_pipeline(runner): result = runner.invoke(cli, ["-i", "-"], input="foo\nbar") assert not result.exception - assert result.output.splitlines() == [ - "foo", - "bar", - ] + assert result.output.splitlines() == ["foo", "bar"] result = runner.invoke(cli, ["-i", "-", "strip"], input="foo \n bar") assert not result.exception - assert result.output.splitlines() == [ - "foo", - "bar", - ] + assert result.output.splitlines() == ["foo", "bar"] result = runner.invoke(cli, ["-i", "-", "strip", "uppercase"], input="foo \n bar") assert not result.exception - assert result.output.splitlines() == [ - "FOO", - "BAR", - ] + assert result.output.splitlines() == ["FOO", "BAR"] def test_args_and_chain(runner): @@ -185,12 +171,7 @@ def test_args_and_chain(runner): result = runner.invoke(cli, ["a", "b", "c"]) assert not result.exception - assert result.output.splitlines() == [ - "cli=", - "a=", - "b=", - "c=", - ] + assert result.output.splitlines() == ["cli=", "a=", "b=", "c="] def test_multicommand_arg_behavior(runner): @@ -211,7 +192,7 @@ def test_multicommand_arg_behavior(runner): @click.group(chain=True) @click.argument("arg") def cli(arg): - click.echo("cli:%s" % arg) + click.echo("cli:{}".format(arg)) @cli.command() def a(): @@ -219,10 +200,7 @@ def test_multicommand_arg_behavior(runner): result = runner.invoke(cli, ["foo", "a"]) assert not result.exception - assert result.output.splitlines() == [ - "cli:foo", - "a", - ] + assert result.output.splitlines() == ["cli:foo", "a"] @pytest.mark.xfail @@ -249,9 +227,4 @@ def test_multicommand_chaining(runner): result = runner.invoke(cli, ["l1a", "l2a", "l1b"]) assert not result.exception - assert result.output.splitlines() == [ - "cli=", - "l1a=", - "l2a=", - "l1b=", - ] + assert result.output.splitlines() == ["cli=", "l1a=", "l2a=", "l1b="] diff --git a/tests/test_commands.py b/tests/test_commands.py index bcb30bd..1d99218 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -26,7 +26,7 @@ def test_other_command_forward(runner): @cli.command() @click.option("--count", default=1) def test(count): - click.echo("Count: %d" % count) + click.echo("Count: {:d}".format(count)) @cli.command() @click.option("--count", default=1) @@ -102,7 +102,7 @@ def test_group_with_args(runner): @click.group() @click.argument("obj") def cli(obj): - click.echo("obj=%s" % obj) + click.echo("obj={}".format(obj)) @cli.command() def move(): @@ -211,7 +211,7 @@ def test_object_propagation(runner): @cli.command() @click.pass_context def sync(ctx): - click.echo("Debug is %s" % (ctx.obj["DEBUG"] and "on" or "off")) + click.echo("Debug is {}".format("on" if ctx.obj["DEBUG"] else "off")) result = runner.invoke(cli, ["sync"]) assert result.exception is None @@ -264,8 +264,8 @@ def test_unprocessed_options(runner): @click.argument("args", nargs=-1, type=click.UNPROCESSED) @click.option("--verbose", "-v", count=True) def cli(verbose, args): - click.echo("Verbosity: %s" % verbose) - click.echo("Args: %s" % "|".join(args)) + click.echo("Verbosity: {}".format(verbose)) + click.echo("Args: {}".format("|".join(args))) result = runner.invoke(cli, ["-foo", "-vvvvx", "--muhaha", "x", "y", "-x"]) assert not result.exception diff --git a/tests/test_context.py b/tests/test_context.py index 4d131e7..b3a20c6 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -90,8 +90,8 @@ def test_get_context_objects_missing(runner): assert result.exception is not None assert isinstance(result.exception, RuntimeError) assert ( - "Managed to invoke callback without a context object " - "of type 'Foo' existing" in str(result.exception) + "Managed to invoke callback without a context object of type" + " 'Foo' existing" in str(result.exception) ) @@ -129,7 +129,7 @@ def test_global_context_object(runner): def test_context_meta(runner): - LANG_KEY = __name__ + ".lang" + LANG_KEY = "{}.lang".format(__name__) def set_language(value): click.get_current_context().meta[LANG_KEY] = value diff --git a/tests/test_defaults.py b/tests/test_defaults.py index 7b1d7e5..ce44903 100644 --- a/tests/test_defaults.py +++ b/tests/test_defaults.py @@ -6,7 +6,7 @@ def test_basic_defaults(runner): @click.option("--foo", default=42, type=click.FLOAT) def cli(foo): assert type(foo) is float - click.echo("FOO:[%s]" % foo) + click.echo("FOO:[{}]".format(foo)) result = runner.invoke(cli, []) assert not result.exception @@ -23,10 +23,7 @@ def test_multiple_defaults(runner): result = runner.invoke(cli, []) assert not result.exception - assert result.output.splitlines() == [ - "23.0", - "42.0", - ] + assert result.output.splitlines() == ["23.0", "42.0"] def test_nargs_plus_multiple(runner): @@ -36,11 +33,8 @@ def test_nargs_plus_multiple(runner): ) def cli(arg): for item in arg: - click.echo("<%d|%d>" % item) + click.echo("<{0[0]:d}|{0[1]:d}>".format(item)) result = runner.invoke(cli, []) assert not result.exception - assert result.output.splitlines() == [ - "<1|2>", - "<3|4>", - ] + assert result.output.splitlines() == ["<1|2>", "<3|4>"] diff --git a/tests/test_formatting.py b/tests/test_formatting.py index 30ab288..4fabbb2 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -151,15 +151,15 @@ def test_formatting_usage_error(runner): @click.command() @click.argument("arg") def cmd(arg): - click.echo("arg:" + arg) + click.echo("arg:{}".format(arg)) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd [OPTIONS] ARG", - 'Try "cmd --help" for help.', + "Try 'cmd --help' for help.", "", - 'Error: Missing argument "ARG".', + "Error: Missing argument 'ARG'.", ] @@ -178,9 +178,9 @@ def test_formatting_usage_error_metavar_missing_arg(runner): assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd [OPTIONS] metavar", - 'Try "cmd --help" for help.', + "Try 'cmd --help' for help.", "", - 'Error: Missing argument "metavar".', + "Error: Missing argument 'metavar'.", ] @@ -194,9 +194,9 @@ def test_formatting_usage_error_metavar_bad_arg(runner): assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd [OPTIONS] metavar", - 'Try "cmd --help" for help.', + "Try 'cmd --help' for help.", "", - 'Error: Invalid value for "metavar": 3.14 is not a valid integer', + "Error: Invalid value for 'metavar': 3.14 is not a valid integer", ] @@ -208,15 +208,15 @@ def test_formatting_usage_error_nested(runner): @cmd.command() @click.argument("bar") def foo(bar): - click.echo("foo:" + bar) + click.echo("foo:{}".format(bar)) result = runner.invoke(cmd, ["foo"]) assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd foo [OPTIONS] BAR", - 'Try "cmd foo --help" for help.', + "Try 'cmd foo --help' for help.", "", - 'Error: Missing argument "BAR".', + "Error: Missing argument 'BAR'.", ] @@ -224,14 +224,14 @@ def test_formatting_usage_error_no_help(runner): @click.command(add_help_option=False) @click.argument("arg") def cmd(arg): - click.echo("arg:" + arg) + click.echo("arg:{}".format(arg)) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd [OPTIONS] ARG", "", - 'Error: Missing argument "ARG".', + "Error: Missing argument 'ARG'.", ] @@ -239,15 +239,15 @@ def test_formatting_usage_custom_help(runner): @click.command(context_settings=dict(help_option_names=["--man"])) @click.argument("arg") def cmd(arg): - click.echo("arg:" + arg) + click.echo("arg:{}".format(arg)) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ "Usage: cmd [OPTIONS] ARG", - 'Try "cmd --man" for help.', + "Try 'cmd --man' for help.", "", - 'Error: Missing argument "ARG".', + "Error: Missing argument 'ARG'.", ] diff --git a/tests/test_options.py b/tests/test_options.py index 3974803..4baa374 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -47,21 +47,18 @@ def test_nargs_tup_composite_mult(runner): @click.option("--item", type=(str, int), multiple=True) def copy(item): for item in item: - click.echo("name=%s id=%d" % item) + click.echo("name={0[0]} id={0[1]:d}".format(item)) result = runner.invoke(copy, ["--item", "peter", "1", "--item", "max", "2"]) assert not result.exception - assert result.output.splitlines() == [ - "name=peter id=1", - "name=max id=2", - ] + assert result.output.splitlines() == ["name=peter id=1", "name=max id=2"] def test_counting(runner): @click.command() @click.option("-v", count=True, help="Verbosity", type=click.IntRange(0, 3)) def cli(v): - click.echo("verbosity=%d" % v) + click.echo("verbosity={:d}".format(v)) result = runner.invoke(cli, ["-vvv"]) assert not result.exception @@ -70,7 +67,7 @@ def test_counting(runner): result = runner.invoke(cli, ["-vvvv"]) assert result.exception assert ( - 'Invalid value for "-v": 4 is not in the valid range of 0 to 3.' + "Invalid value for '-v': 4 is not in the valid range of 0 to 3." in result.output ) @@ -105,14 +102,14 @@ def test_multiple_required(runner): result = runner.invoke(cli, []) assert result.exception - assert 'Error: Missing option "-m" / "--message".' in result.output + assert "Error: Missing option '-m' / '--message'." in result.output def test_empty_envvar(runner): @click.command() @click.option("--mypath", type=click.Path(exists=True), envvar="MYPATH") def cli(mypath): - click.echo("mypath: %s" % mypath) + click.echo("mypath: {}".format(mypath)) result = runner.invoke(cli, [], env={"MYPATH": ""}) assert result.exit_code == 0 @@ -149,7 +146,7 @@ def test_multiple_envvar(runner): cmd, [], auto_envvar_prefix="TEST", - env={"TEST_ARG": "foo%sbar" % os.path.pathsep}, + env={"TEST_ARG": "foo{}bar".format(os.path.pathsep)}, ) assert not result.exception assert result.output == "foo|bar\n" @@ -306,7 +303,7 @@ def test_custom_validation(runner): click.echo(foo) result = runner.invoke(cmd, ["--foo", "-1"]) - assert 'Invalid value for "--foo": Value needs to be positive' in result.output + assert "Invalid value for '--foo': Value needs to be positive" in result.output result = runner.invoke(cmd, ["--foo", "42"]) assert result.output == "42\n" @@ -359,7 +356,7 @@ def test_missing_choice(runner): result = runner.invoke(cmd) assert result.exit_code == 2 error, separator, choices = result.output.partition("Choose from") - assert 'Error: Missing option "--foo". ' in error + assert "Error: Missing option '--foo'. " in error assert "Choose from" in separator assert "foo" in choices assert "bar" in choices diff --git a/tests/test_testing.py b/tests/test_testing.py index f2d2d9a..22a285d 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -65,7 +65,7 @@ def test_prompts(): @click.command() @click.option("--foo", prompt=True) def test(foo): - click.echo("foo=%s" % foo) + click.echo("foo={}".format(foo)) runner = CliRunner() result = runner.invoke(test, input="wau wau\n") @@ -75,7 +75,7 @@ def test_prompts(): @click.command() @click.option("--foo", prompt=True, hide_input=True) def test(foo): - click.echo("foo=%s" % foo) + click.echo("foo={}".format(foo)) runner = CliRunner() result = runner.invoke(test, input="wau wau\n") @@ -131,7 +131,7 @@ def test_with_color(): assert not result.exception result = runner.invoke(cli, color=True) - assert result.output == click.style("hello world", fg="blue") + "\n" + assert result.output == "{}\n".format(click.style("hello world", fg="blue")) assert not result.exception @@ -219,7 +219,7 @@ def test_exit_code_and_output_from_sys_exit(): def test_env(): @click.command() def cli_env(): - click.echo("ENV=%s" % os.environ["TEST_CLICK_ENV"]) + click.echo("ENV={}".format(os.environ["TEST_CLICK_ENV"])) runner = CliRunner() diff --git a/tests/test_utils.py b/tests/test_utils.py index 5247224..d86f59b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -203,21 +203,21 @@ def test_echo_color_flag(monkeypatch, capfd): click.echo(styled_text, color=False) out, err = capfd.readouterr() - assert out == text + "\n" + assert out == "{}\n".format(text) click.echo(styled_text, color=True) out, err = capfd.readouterr() - assert out == styled_text + "\n" + assert out == "{}\n".format(styled_text) isatty = True click.echo(styled_text) out, err = capfd.readouterr() - assert out == styled_text + "\n" + assert out == "{}\n".format(styled_text) isatty = False click.echo(styled_text) out, err = capfd.readouterr() - assert out == text + "\n" + assert out == "{}\n".format(text) @pytest.mark.skipif(WIN, reason="Test too complex to make work windows.") |
