summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/aliases/setup.py2
-rw-r--r--examples/bashcompletion/bashcompletion.py3
-rw-r--r--examples/bashcompletion/setup.py2
-rw-r--r--examples/complex/setup.py2
-rw-r--r--examples/imagepipe/imagepipe.py2
-rw-r--r--examples/imagepipe/setup.py2
-rw-r--r--examples/inout/setup.py2
-rw-r--r--examples/naval/setup.py2
-rw-r--r--examples/repo/setup.py2
-rw-r--r--examples/validation/setup.py2
-rw-r--r--setup.cfg5
-rw-r--r--src/click/_bashcomplete.py42
-rw-r--r--src/click/_compat.py1
-rw-r--r--src/click/core.py18
-rw-r--r--src/click/decorators.py12
-rw-r--r--src/click/exceptions.py2
-rw-r--r--src/click/globals.py2
-rw-r--r--src/click/termui.py2
-rw-r--r--src/click/testing.py2
-rw-r--r--src/click/types.py8
-rw-r--r--src/click/utils.py2
-rw-r--r--tests/test_arguments.py7
-rw-r--r--tests/test_basic.py2
-rw-r--r--tests/test_commands.py5
-rw-r--r--tests/test_options.py16
-rw-r--r--tests/test_termui.py39
-rw-r--r--tests/test_utils.py5
27 files changed, 91 insertions, 100 deletions
diff --git a/examples/aliases/setup.py b/examples/aliases/setup.py
index 2ea791e..a3d04e7 100644
--- a/examples/aliases/setup.py
+++ b/examples/aliases/setup.py
@@ -5,7 +5,7 @@ setup(
version="1.0",
py_modules=["aliases"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
aliases=aliases:cli
diff --git a/examples/bashcompletion/bashcompletion.py b/examples/bashcompletion/bashcompletion.py
index c437069..636cf64 100644
--- a/examples/bashcompletion/bashcompletion.py
+++ b/examples/bashcompletion/bashcompletion.py
@@ -31,7 +31,8 @@ def list_users(ctx, args, incomplete):
# You can generate completions with descriptions by returning
# tuples in the form (completion, description).
users = [("bob", "butcher"), ("alice", "baker"), ("jerry", "candlestick maker")]
- # Ths will allow completion matches based on matches within the description string too!
+ # Ths will allow completion matches based on matches within the
+ # description string too!
return [user for user in users if incomplete in user[0] or incomplete in user[1]]
diff --git a/examples/bashcompletion/setup.py b/examples/bashcompletion/setup.py
index 31e3cfa..f9a2c29 100644
--- a/examples/bashcompletion/setup.py
+++ b/examples/bashcompletion/setup.py
@@ -5,7 +5,7 @@ setup(
version="1.0",
py_modules=["bashcompletion"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
bashcompletion=bashcompletion:cli
diff --git a/examples/complex/setup.py b/examples/complex/setup.py
index f776e5e..afe9728 100644
--- a/examples/complex/setup.py
+++ b/examples/complex/setup.py
@@ -5,7 +5,7 @@ setup(
version="1.0",
packages=["complex", "complex.commands"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
complex=complex.cli:cli
diff --git a/examples/imagepipe/imagepipe.py b/examples/imagepipe/imagepipe.py
index 9249116..2cde2f6 100644
--- a/examples/imagepipe/imagepipe.py
+++ b/examples/imagepipe/imagepipe.py
@@ -235,7 +235,7 @@ def smoothen_cmd(images, iterations):
'Smoothening "%s" %d time%s'
% (image.filename, iterations, iterations != 1 and "s" or "",)
)
- for x in xrange(iterations):
+ for _ in range(iterations):
image = copy_filename(image.filter(ImageFilter.BLUR), image)
yield image
diff --git a/examples/imagepipe/setup.py b/examples/imagepipe/setup.py
index 80d5c85..c42b5ff 100644
--- a/examples/imagepipe/setup.py
+++ b/examples/imagepipe/setup.py
@@ -5,7 +5,7 @@ setup(
version="1.0",
py_modules=["imagepipe"],
include_package_data=True,
- install_requires=["click", "pillow",],
+ install_requires=["click", "pillow"],
entry_points="""
[console_scripts]
imagepipe=imagepipe:cli
diff --git a/examples/inout/setup.py b/examples/inout/setup.py
index 2f4e5a3..ff673e3 100644
--- a/examples/inout/setup.py
+++ b/examples/inout/setup.py
@@ -5,7 +5,7 @@ setup(
version="0.1",
py_modules=["inout"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
inout=inout:cli
diff --git a/examples/naval/setup.py b/examples/naval/setup.py
index a3d93bb..37b39f5 100644
--- a/examples/naval/setup.py
+++ b/examples/naval/setup.py
@@ -5,7 +5,7 @@ setup(
version="2.0",
py_modules=["naval"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
naval=naval:cli
diff --git a/examples/repo/setup.py b/examples/repo/setup.py
index e0aa5b0..3028020 100644
--- a/examples/repo/setup.py
+++ b/examples/repo/setup.py
@@ -5,7 +5,7 @@ setup(
version="0.1",
py_modules=["repo"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
repo=repo:cli
diff --git a/examples/validation/setup.py b/examples/validation/setup.py
index 80f2bf0..b7698f6 100644
--- a/examples/validation/setup.py
+++ b/examples/validation/setup.py
@@ -5,7 +5,7 @@ setup(
version="1.0",
py_modules=["validation"],
include_package_data=True,
- install_requires=["click",],
+ install_requires=["click"],
entry_points="""
[console_scripts]
validation=validation:cli
diff --git a/setup.cfg b/setup.cfg
index 4335cbf..c2d41cc 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -25,8 +25,9 @@ source =
# E = pycodestyle errors
# F = flake8 pyflakes
# W = pycodestyle warnings
-# B9 = bugbear opinions
-select = B, E, F, W, B9
+# B9 = bugbear opinions,
+# ISC = implicit str concat
+select = B, E, F, W, B9, ISC
ignore =
# slice notation whitespace, invalid
E203
diff --git a/src/click/_bashcomplete.py b/src/click/_bashcomplete.py
index bbd45a0..815eb02 100644
--- a/src/click/_bashcomplete.py
+++ b/src/click/_bashcomplete.py
@@ -30,7 +30,8 @@ COMPLETION_SCRIPT_BASH = """
local COMPLETION_OPTIONS=""
local BASH_VERSION_ARR=(${BASH_VERSION//./ })
# Only BASH version 4.4 and later have the nosort option.
- if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
+ if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] \
+&& [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
COMPLETION_OPTIONS="-o nosort"
fi
@@ -75,9 +76,12 @@ COMPLETION_SCRIPT_ZSH = """
compdef %(complete_func)s %(script_names)s
"""
-COMPLETION_SCRIPT_FISH = """
-complete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)"
-"""
+COMPLETION_SCRIPT_FISH = (
+ "complete --no-files --command %(script_names)s --arguments"
+ ' "(env %(autocomplete_var)s=complete_fish'
+ " COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t)"
+ ' %(script_names)s)"'
+)
_completion_scripts = {
"bash": COMPLETION_SCRIPT_BASH,
@@ -102,8 +106,9 @@ def get_completion_script(prog_name, complete_var, shell):
def resolve_ctx(cli, prog_name, args):
- """
- Parse into a hierarchy of contexts. Contexts are connected through the parent variable.
+ """Parse into a hierarchy of contexts. Contexts are connected
+ through the parent variable.
+
:param cli: command definition
:param prog_name: the program that is running
:param args: full list of args
@@ -146,7 +151,8 @@ def resolve_ctx(cli, prog_name, args):
def start_of_option(param_str):
"""
:param param_str: param_str to check
- :return: whether or not this is the start of an option declaration (i.e. starts "-" or "--")
+ :return: whether or not this is the start of an option declaration
+ (i.e. starts "-" or "--")
"""
return param_str and param_str[:1] == "-"
@@ -155,9 +161,10 @@ def is_incomplete_option(all_args, cmd_param):
"""
:param all_args: the full original list of args supplied
:param cmd_param: the current command paramter
- :return: whether or not the last option declaration (i.e. starts "-" or "--") is incomplete and
- corresponds to this cmd_param. In other words whether this cmd_param option can still accept
- values
+ :return: whether or not the last option declaration (i.e. starts
+ "-" or "--") is incomplete and corresponds to this cmd_param. In
+ other words whether this cmd_param option can still accept
+ values
"""
if not isinstance(cmd_param, Option):
return False
@@ -177,10 +184,12 @@ def is_incomplete_option(all_args, cmd_param):
def is_incomplete_argument(current_params, cmd_param):
"""
- :param current_params: the current params and values for this argument as already entered
+ :param current_params: the current params and values for this
+ argument as already entered
:param cmd_param: the current command parameter
- :return: whether or not the last argument is incomplete and corresponds to this cmd_param. In
- other words whether or not the this cmd_param argument can still accept values
+ :return: whether or not the last argument is incomplete and
+ corresponds to this cmd_param. In other words whether or not the
+ this cmd_param argument can still accept values
"""
if not isinstance(cmd_param, Argument):
return False
@@ -245,7 +254,8 @@ def add_subcommand_completions(ctx, incomplete, completions_out):
]
)
- # Walk up the context list and add any other completion possibilities from chained commands
+ # Walk up the context list and add any other completion
+ # possibilities from chained commands
while ctx.parent is not None:
ctx = ctx.parent
if isinstance(ctx.command, MultiCommand) and ctx.command.chain:
@@ -275,8 +285,8 @@ def get_choices(cli, prog_name, args, incomplete):
has_double_dash = "--" in all_args
- # In newer versions of bash long opts with '='s are partitioned, but it's easier to parse
- # without the '='
+ # In newer versions of bash long opts with '='s are partitioned, but
+ # it's easier to parse without the '='
if start_of_option(incomplete) and WORDBREAK in incomplete:
partition_incomplete = incomplete.partition(WORDBREAK)
all_args.append(partition_incomplete[0])
diff --git a/src/click/_compat.py b/src/click/_compat.py
index 6431fc2..5caa593 100644
--- a/src/click/_compat.py
+++ b/src/click/_compat.py
@@ -1,3 +1,4 @@
+# flake8: noqa
import codecs
import io
import os
diff --git a/src/click/core.py b/src/click/core.py
index ea46e86..937d747 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -42,9 +42,7 @@ SUBCOMMAND_METAVAR = "COMMAND [ARGS]..."
SUBCOMMANDS_METAVAR = "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..."
DEPRECATED_HELP_NOTICE = " (DEPRECATED)"
-DEPRECATED_INVOKE_NOTICE = (
- "DeprecationWarning: " + "The command %(name)s is deprecated."
-)
+DEPRECATED_INVOKE_NOTICE = "DeprecationWarning: The command %(name)s is deprecated."
def _maybe_show_deprecated_notice(cmd):
@@ -578,7 +576,7 @@ class Context(object):
"""
return self.command.get_help(self)
- def invoke(*args, **kwargs):
+ def invoke(*args, **kwargs): # noqa: B902
"""Invokes a command callback in exactly the way it expects. There
are two ways to invoke this method:
@@ -618,7 +616,7 @@ class Context(object):
with ctx:
return callback(*args, **kwargs)
- def forward(*args, **kwargs):
+ def forward(*args, **kwargs): # noqa: B902
"""Similar to :meth:`invoke` but fills in default keyword
arguments from the current context if the other command expects
it. This cannot invoke callbacks directly, only other commands.
@@ -985,7 +983,9 @@ class Command(BaseCommand):
return formatter.getvalue().rstrip("\n")
def get_short_help_str(self, limit=45):
- """Gets short help for the command or makes it by shortening the long help string."""
+ """Gets short help for the command or makes it by shortening the
+ long help string.
+ """
return (
self.short_help
or self.help
@@ -1362,6 +1362,7 @@ class Group(MultiCommand):
immediately registers the created command with this instance by
calling into :meth:`add_command`.
"""
+ from .decorators import command
def decorator(f):
cmd = command(*args, **kwargs)(f)
@@ -1376,6 +1377,7 @@ class Group(MultiCommand):
immediately registers the created command with this instance by
calling into :meth:`add_command`.
"""
+ from .decorators import group
def decorator(f):
cmd = group(*args, **kwargs)(f)
@@ -2037,7 +2039,3 @@ class Argument(Parameter):
def add_to_parser(self, parser, ctx):
parser.add_argument(dest=self.name, nargs=self.nargs, obj=self)
-
-
-# Circular dependency between decorators and core
-from .decorators import command, group
diff --git a/src/click/decorators.py b/src/click/decorators.py
index 5f556e2..7e10adb 100644
--- a/src/click/decorators.py
+++ b/src/click/decorators.py
@@ -4,6 +4,10 @@ from functools import update_wrapper
from ._compat import iteritems
from ._unicodefun import _check_for_unicode_literals
+from .core import Argument
+from .core import Command
+from .core import Group
+from .core import Option
from .globals import get_current_context
from .utils import echo
@@ -283,13 +287,13 @@ def version_option(version=None, *param_decls, **attrs):
else:
for dist in pkg_resources.working_set:
scripts = dist.get_entry_map().get("console_scripts") or {}
- for script_name, entry_point in iteritems(scripts):
+ for _, entry_point in iteritems(scripts):
if entry_point.module_name == module:
ver = dist.version
break
if ver is None:
raise RuntimeError("Could not determine version")
- echo(message % {"prog": prog, "version": ver,}, color=ctx.color)
+ echo(message % {"prog": prog, "version": ver}, color=ctx.color)
ctx.exit()
attrs.setdefault("is_flag", True)
@@ -327,7 +331,3 @@ def help_option(*param_decls, **attrs):
return option(*(param_decls or ("--help",)), **attrs)(f)
return decorator
-
-
-# Circular dependencies between core and decorators
-from .core import Command, Group, Argument, Option
diff --git a/src/click/exceptions.py b/src/click/exceptions.py
index a06400b..2e2199b 100644
--- a/src/click/exceptions.py
+++ b/src/click/exceptions.py
@@ -248,5 +248,7 @@ class Exit(RuntimeError):
:param code: the status code to exit with.
"""
+ __slots__ = ("exit_code",)
+
def __init__(self, code=0):
self.exit_code = code
diff --git a/src/click/globals.py b/src/click/globals.py
index a0157fc..1649f9a 100644
--- a/src/click/globals.py
+++ b/src/click/globals.py
@@ -19,7 +19,7 @@ def get_current_context(silent=False):
:exc:`RuntimeError`.
"""
try:
- return getattr(_local, "stack")[-1]
+ return _local.stack[-1]
except (AttributeError, IndexError):
if not silent:
raise RuntimeError("There is no active click context.")
diff --git a/src/click/termui.py b/src/click/termui.py
index eb1baa8..d5239e7 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -156,7 +156,7 @@ def prompt(
try:
result = value_proc(value)
except UsageError as e:
- echo("Error: %s" % e.message, err=err)
+ echo("Error: %s" % e.message, err=err) # noqa: B306
continue
if not confirmation_prompt:
return result
diff --git a/src/click/testing.py b/src/click/testing.py
index c50418f..6ad06fb 100644
--- a/src/click/testing.py
+++ b/src/click/testing.py
@@ -382,5 +382,5 @@ class CliRunner(object):
os.chdir(cwd)
try:
shutil.rmtree(t)
- except (OSError, IOError):
+ except (OSError, IOError): # noqa: B014
pass
diff --git a/src/click/types.py b/src/click/types.py
index 1d3d5b3..0987190 100644
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -261,7 +261,7 @@ class IntParamType(ParamType):
def convert(self, value, param, ctx):
try:
return int(value)
- except (ValueError, UnicodeError):
+ except ValueError:
self.fail("%s is not a valid integer" % value, param, ctx)
def __repr__(self):
@@ -329,7 +329,7 @@ class FloatParamType(ParamType):
def convert(self, value, param, ctx):
try:
return float(value)
- except (UnicodeError, ValueError):
+ except ValueError:
self.fail("%s is not a valid floating point value" % value, param, ctx)
def __repr__(self):
@@ -418,7 +418,7 @@ class UUIDParameterType(ParamType):
if PY2 and isinstance(value, text_type):
value = value.encode("ascii")
return uuid.UUID(value)
- except (UnicodeError, ValueError):
+ except ValueError:
self.fail("%s is not a valid UUID value" % value, param, ctx)
def __repr__(self):
@@ -502,7 +502,7 @@ class File(ParamType):
else:
ctx.call_on_close(safecall(f.flush))
return f
- except (IOError, OSError) as e:
+ except (IOError, OSError) as e: # noqa: B014
self.fail(
"Could not open file: %s: %s"
% (filename_to_ui(value), get_streerror(e),),
diff --git a/src/click/utils.py b/src/click/utils.py
index 210bbe4..4e97d84 100644
--- a/src/click/utils.py
+++ b/src/click/utils.py
@@ -126,7 +126,7 @@ class LazyFile(object):
rv, self.should_close = open_stream(
self.name, self.mode, self.encoding, self.errors, atomic=self.atomic
)
- except (IOError, OSError) as e:
+ except (IOError, OSError) as e: # noqa: E402
from .exceptions import FileError
raise FileError(self.name, hint=get_streerror(e))
diff --git a/tests/test_arguments.py b/tests/test_arguments.py
index 7b214ad..85ba212 100644
--- a/tests/test_arguments.py
+++ b/tests/test_arguments.py
@@ -25,18 +25,13 @@ def test_nargs_star(runner):
def test_nargs_default(runner):
- try:
+ with pytest.raises(TypeError, match="nargs=-1"):
@click.command()
@click.argument("src", nargs=-1, default=42)
def copy(src):
pass
- except TypeError as e:
- assert "nargs=-1" in str(e)
- else:
- assert False
-
def test_nargs_tup(runner):
@click.command()
diff --git a/tests/test_basic.py b/tests/test_basic.py
index 82c7e5a..59566cb 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -49,7 +49,7 @@ def test_return_values():
with cli.make_context("foo", []) as ctx:
rv = cli.invoke(ctx)
- assert rv is 42
+ assert rv == 42
def test_basic_group(runner):
diff --git a/tests/test_commands.py b/tests/test_commands.py
index d53b724..bcb30bd 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -62,7 +62,8 @@ def test_auto_shorthelp(runner):
assert (
re.search(
r"Commands:\n\s+"
- r"long\s+This is a long text that is too long to show as short help\.\.\.\n\s+"
+ r"long\s+This is a long text that is too long to show as short help"
+ r"\.\.\.\n\s+"
r"short\s+This is a short text\.\n\s+"
r"special-chars\s+Login and store the token in ~/.netrc\.\s*",
result.output,
@@ -294,7 +295,7 @@ def test_deprecated_in_help_messages(runner):
def test_deprecated_in_invocation(runner):
@click.command(deprecated=True)
def deprecated_cmd():
- debug()
+ pass
result = runner.invoke(deprecated_cmd)
assert "DeprecationWarning:" in result.output
diff --git a/tests/test_options.py b/tests/test_options.py
index bdf1b95..0cdb064 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -25,32 +25,22 @@ def test_prefixes(runner):
def test_invalid_option(runner):
- try:
+ with pytest.raises(TypeError, match="name was passed"):
@click.command()
@click.option("foo")
def cli(foo):
pass
- except TypeError as e:
- assert "No options defined but a name was passed (foo)." in str(e)
- else:
- assert False, "Expected a type error because of an invalid option."
-
def test_invalid_nargs(runner):
- try:
+ with pytest.raises(TypeError, match="nargs < 0"):
@click.command()
@click.option("--foo", nargs=-1)
def cli(foo):
pass
- except TypeError as e:
- assert "Options cannot have nargs < 0" in str(e)
- else:
- assert False, "Expected a type error because of an invalid option."
-
def test_nargs_tup_composite_mult(runner):
@click.command()
@@ -426,7 +416,7 @@ def test_option_help_preserve_paragraphs(runner):
"--config",
type=click.Path(),
help="""Configuration file to use.
-
+
If not given, the environment variable CONFIG_FILE is consulted
and used if set. If neither are given, a default configuration
file is loaded.""",
diff --git a/tests/test_termui.py b/tests/test_termui.py
index d6451ca..c1cbd28 100644
--- a/tests/test_termui.py
+++ b/tests/test_termui.py
@@ -33,7 +33,7 @@ def test_progressbar_strip_regression(runner, monkeypatch):
@click.command()
def cli():
with _create_progress(label=label) as progress:
- for thing in progress:
+ for _ in progress:
fake_clock.advance_time()
monkeypatch.setattr(time, "time", fake_clock.time)
@@ -65,7 +65,7 @@ def test_progressbar_length_hint(runner, monkeypatch):
@click.command()
def cli():
with click.progressbar(Hinted(10), label="test") as progress:
- for thing in progress:
+ for _ in progress:
fake_clock.advance_time()
monkeypatch.setattr(time, "time", fake_clock.time)
@@ -81,7 +81,7 @@ def test_progressbar_hidden(runner, monkeypatch):
@click.command()
def cli():
with _create_progress(label=label) as progress:
- for thing in progress:
+ for _ in progress:
fake_clock.advance_time()
monkeypatch.setattr(time, "time", fake_clock.time)
@@ -183,22 +183,14 @@ def test_progressbar_format_progress_line_with_show_func(runner, test_item):
def test_progressbar_init_exceptions(runner):
- try:
+ with pytest.raises(TypeError, match="iterable or length is required"):
click.progressbar()
- except TypeError as e:
- assert str(e) == "iterable or length is required"
- else:
- assert False, "Expected an exception because unspecified arguments"
def test_progressbar_iter_outside_with_exceptions(runner):
- try:
+ with pytest.raises(RuntimeError, match="with block"):
progress = click.progressbar(length=2)
iter(progress)
- except RuntimeError as e:
- assert str(e) == "You need to use progress bars in a with block."
- else:
- assert False, "Expected an exception because of abort-related inputs."
def test_progressbar_is_iterator(runner, monkeypatch):
@@ -247,7 +239,7 @@ def test_choices_list_in_prompt(runner, monkeypatch):
@pytest.mark.parametrize(
- "file_kwargs", [{"mode": "rt"}, {"mode": "rb"}, {"lazy": True},]
+ "file_kwargs", [{"mode": "rt"}, {"mode": "rb"}, {"lazy": True}]
)
def test_file_prompt_default_format(runner, file_kwargs):
@click.command()
@@ -318,16 +310,17 @@ def test_getchar_special_key_windows(runner, monkeypatch, special_key_char, key_
assert click.getchar() == special_key_char + key_char
-@pytest.mark.parametrize("key_char", [u"\x03", u"\x1a"])
+@pytest.mark.parametrize(
+ ("key_char", "exc"),
+ [
+ (u"\x03", KeyboardInterrupt),
+ (u"\x1a", EOFError),
+ ],
+)
@pytest.mark.skipif(not WIN, reason="Tests user-input using the msvcrt module.")
-def test_getchar_windows_exceptions(runner, monkeypatch, key_char):
+def test_getchar_windows_exceptions(runner, monkeypatch, key_char, exc):
monkeypatch.setattr(click._termui_impl.msvcrt, "getwch", lambda: key_char)
monkeypatch.setattr(click.termui, "_getchar", None)
- try:
+
+ with pytest.raises(exc):
click.getchar()
- except KeyboardInterrupt:
- assert key_char == u"\x03"
- except EOFError:
- assert key_char == u"\x1a"
- else:
- assert False, "Expected an exception because of abort-specific inputs."
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 832571a..5247224 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -6,7 +6,6 @@ import pytest
import click._termui_impl
import click.utils
-from click._compat import PY2
from click._compat import WIN
@@ -84,7 +83,7 @@ def test_styling(styles, ref):
assert click.unstyle(ref) == "x y"
-@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y"),])
+@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y")])
def test_unstyle_other_ansi(text, expect):
assert click.unstyle(text) == expect
@@ -340,7 +339,7 @@ def test_open_file_ignore_no_encoding(runner):
@pytest.mark.skipif(WIN, reason="os.chmod() is not fully supported on Windows.")
-@pytest.mark.parametrize("permissions", [0o400, 0o444, 0o600, 0o644,])
+@pytest.mark.parametrize("permissions", [0o400, 0o444, 0o600, 0o644])
def test_open_file_atomic_permissions_existing_file(runner, permissions):
with runner.isolated_filesystem():
with open("existing.txt", "w") as f: