diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a1580cd1..3a7a295b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,23 +9,23 @@ repos: args: [--fix=lf] - id: debug-statements - id: check-added-large-files - - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.0 hooks: - - id: pyupgrade - args: [--py39-plus] + - id: ruff + args: + - --fix + exclude: | + (?x)^( + |tests/.* + )$ - repo: https://github.com/psf/black rev: 24.8.0 hooks: - id: black args: - - --exclude=/(tests)/ + - --exclude=/tests/ - --line-length=120 - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: ["--profile", "black", "--filter-files"] - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: @@ -33,19 +33,6 @@ repos: args: - --ignore-words-list=nin,astroid - --skip=poetry.lock - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - exclude: | - (?x)^( - .*/testdata/.* - |.*/testpath/.* - |tests/tools/pylint/test_no_init_found/.* - |tests/test_message\.py - )$ - args: - - --max-line-length=120 - repo: https://github.com/regebro/pyroma rev: "4.2" hooks: diff --git a/docs/conf.py b/docs/conf.py index 68ccbdd4..dccdc882 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -121,7 +121,7 @@ html_title = "prospector documentation" # A shorter title for the navigation bar. Default is the same as html_title. -html_short_title = "prospector-%s" % version +html_short_title = f"prospector-{version}" # The name of an image file (relative to this directory) to place at the top # of the sidebar. diff --git a/prospector/autodetect.py b/prospector/autodetect.py index 29473e26..750bb4f1 100644 --- a/prospector/autodetect.py +++ b/prospector/autodetect.py @@ -1,3 +1,4 @@ +import contextlib import os import re import warnings @@ -58,7 +59,7 @@ def find_from_path(path: Path) -> set[str]: names |= find_from_imports(contents) except encoding.CouldNotHandleEncoding as err: # TODO: this output will break output formats such as JSON - warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning) + warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning, stacklevel=0) if len(names) == len(POSSIBLE_LIBRARIES): # don't continue on recursing, there's no point! @@ -86,10 +87,8 @@ def autodetect_libraries(path: Union[str, Path]) -> set[str]: libraries: set[str] = set() - try: + with contextlib.suppress(RequirementsNotFound): libraries = find_from_requirements(path) - except RequirementsNotFound: - pass if len(libraries) < len(POSSIBLE_LIBRARIES): libraries = find_from_path(Path(path)) diff --git a/prospector/config/__init__.py b/prospector/config/__init__.py index 9d12905b..f47386ab 100644 --- a/prospector/config/__init__.py +++ b/prospector/config/__init__.py @@ -13,6 +13,8 @@ except ImportError: import sre_constants # pylint: disable=deprecated-module +import contextlib + from prospector import tools from prospector.autodetect import autodetect_libraries from prospector.compat import is_relative_to @@ -174,7 +176,7 @@ def _get_profile( # Use the strictness profile only if no profile has been given if config.strictness is not None and config.strictness: - cmdline_implicit.append("strictness_%s" % config.strictness) + cmdline_implicit.append(f"strictness_{config.strictness}") strictness = config.strictness # the profile path is @@ -196,8 +198,14 @@ def _get_profile( profile = ProspectorProfile.load(profile_name, profile_path, forced_inherits=forced_inherits) except CannotParseProfile as cpe: sys.stderr.write( - "Failed to run:\nCould not parse profile %s as it is not valid YAML\n%s\n" - % (cpe.filepath, cpe.get_parse_message()) + "\n".join( + [ + "Failed to run:", + f"Could not parse profile {cpe.filepath} as it is not valid YAML", + f"{cpe.get_parse_message()}", + "", + ] + ) ) sys.exit(1) except ProfileNotFound as nfe: @@ -273,10 +281,8 @@ def _determine_ignores( # ignore-patterns: # uses: django continue - try: + with contextlib.suppress(sre_constants.error): ignores.append(re.compile(pattern)) - except sre_constants.error: - pass # Convert ignore paths into patterns boundary = r"(^|/|\\)%s(/|\\|$)" @@ -318,7 +324,7 @@ def tool_options(self, tool_name: str) -> dict[str, str]: return tool.get("options", {}) def external_config_location(self, tool_name: str) -> Optional[Path]: - return getattr(self.config, "%s_config_file" % tool_name, None) + return getattr(self.config, f"{tool_name}_config_file", None) @property def die_on_tool_error(self) -> bool: diff --git a/prospector/config/configuration.py b/prospector/config/configuration.py index 9b0de966..fe588ec3 100644 --- a/prospector/config/configuration.py +++ b/prospector/config/configuration.py @@ -186,9 +186,10 @@ def build_command_line_source( }, "output_format": { "flags": ["-o", "--output-format"], - "help": "The output format. Valid values are: %s. This will output to stdout by default, " - "however a target file can be used instead by adding :path-to-output-file, eg, -o json:output.json" - % (", ".join(sorted(FORMATTERS.keys())),), + "help": "The output format. Valid values are: {}. This will output to stdout by default, " + "however a target file can be used instead by adding :path-to-output-file, eg, -o json:output.json".format( + ", ".join(sorted(FORMATTERS.keys())) + ), }, "absolute_paths": { "help": "Whether to output absolute paths when referencing files " @@ -199,9 +200,8 @@ def build_command_line_source( "flags": ["-t", "--tool"], "help": "A list of tools to run. This lets you set exactly which " "tools to run. To add extra tools to the defaults, see " - "--with-tool. Possible values are: %s. By " - "default, the following tools will be run: %s" - % ( + "--with-tool. Possible values are: {}. By " + "default, the following tools will be run: {}".format( ", ".join(sorted(TOOLS.keys())), ", ".join(sorted(DEFAULT_TOOLS)), ), @@ -210,14 +210,14 @@ def build_command_line_source( "flags": ["-w", "--with-tool"], "help": "A list of tools to run in addition to the default tools. " "To specify all tools explicitly, use the --tool argument. " - "Possible values are %s." % (", ".join(sorted(TOOLS.keys()))), + "Possible values are {}.".format(", ".join(sorted(TOOLS.keys()))), }, "without_tools": { "flags": ["-W", "--without-tool"], "help": "A list of tools that should not be run. Useful to turn off " "only a single tool from the defaults. " "To specify all tools explicitly, use the --tool argument. " - "Possible values are %s." % (", ".join(sorted(TOOLS.keys()))), + "Possible values are {}.".format(", ".join(sorted(TOOLS.keys()))), }, "profiles": { "flags": ["-P", "--profile"], diff --git a/prospector/exceptions.py b/prospector/exceptions.py index 52d56943..524f4ea0 100644 --- a/prospector/exceptions.py +++ b/prospector/exceptions.py @@ -27,10 +27,7 @@ def __init__(self, path: Path): class PermissionMissing(Exception): def __init__(self, path: Path): docs_url = "https://prospector.landscape.io/en/master/profiles.html#ignoring-paths-and-patterns" - if os.path.isdir(path): - what = f"directory {path}" - else: - what = f"the file {path}" + what = f"directory {path}" if os.path.isdir(path) else f"the file {path}" error_msg = ( f"The current user {os.getlogin()} does not have permission to open " f"{what}. Either fix permissions or tell prospector to skip it " diff --git a/prospector/formatters/base_summary.py b/prospector/formatters/base_summary.py index 540ccd28..bc6cd708 100644 --- a/prospector/formatters/base_summary.py +++ b/prospector/formatters/base_summary.py @@ -9,7 +9,7 @@ class SummaryFormatter(Formatter): summary_labels = ( ("started", "Started", None), ("completed", "Finished", None), - ("time_taken", "Time Taken", lambda x: "%s seconds" % x), + ("time_taken", "Time Taken", lambda x: f"{x} seconds"), ("formatter", "Formatter", None), ("profiles", "Profiles", None), ("strictness", "Strictness", None), diff --git a/prospector/formatters/emacs.py b/prospector/formatters/emacs.py index e2b88b89..8b941b1e 100644 --- a/prospector/formatters/emacs.py +++ b/prospector/formatters/emacs.py @@ -13,15 +13,14 @@ def render_message(self, message: Message) -> str: message.location.line, (message.location.character or 0) + 1, ), - " L%s:%s %s: %s - %s" - % ( + " L{}:{} {}: {} - {}".format( message.location.line or "-", message.location.character if message.location.line else "-", message.location.function, message.source, message.code, ), - " %s" % message.message, + f" {message.message}", ] return "\n".join(output) diff --git a/prospector/formatters/grouped.py b/prospector/formatters/grouped.py index 7d876826..751a560b 100644 --- a/prospector/formatters/grouped.py +++ b/prospector/formatters/grouped.py @@ -24,16 +24,15 @@ def render_messages(self) -> str: output.append(str(filename)) for line in sorted(groups[filename].keys(), key=lambda x: 0 if x is None else int(x)): - output.append(" Line: %s" % line) + output.append(f" Line: {line}") for message in groups[filename][line]: output.append( - " %s: %s / %s%s" - % ( + " {}: {} / {}{}".format( message.source, message.code, message.message, - (" (col %s)" % message.location.character) if message.location.character else "", + (f" (col {message.location.character})") if message.location.character else "", ) ) diff --git a/prospector/formatters/pylint.py b/prospector/formatters/pylint.py index 8593dbc6..c7ebe836 100644 --- a/prospector/formatters/pylint.py +++ b/prospector/formatters/pylint.py @@ -21,7 +21,7 @@ def render(self, summary: bool = True, messages: bool = True, profile: bool = Fa module_name = self._make_path(message.location.path).replace(os.path.sep, ".") module_name = re.sub(r"(\.__init__)?\.py$", "", module_name) - header = "************* Module %s" % module_name + header = f"************* Module {module_name}" output.append(header) # ={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} diff --git a/prospector/formatters/text.py b/prospector/formatters/text.py index 525765e7..1357e07b 100644 --- a/prospector/formatters/text.py +++ b/prospector/formatters/text.py @@ -15,11 +15,10 @@ def render_message(self, message: Message) -> str: if message.location.module: output.append(f"{message.location.module} ({self._make_path(message.location.path)}):") else: - output.append("%s:" % self._make_path(message.location.path)) + output.append(f"{self._make_path(message.location.path)}:") output.append( - " L%s:%s %s: %s - %s" - % ( + " L{}:{} {}: {} - {}".format( message.location.line or "-", message.location.character if message.location.character else "-", message.location.function, @@ -28,7 +27,7 @@ def render_message(self, message: Message) -> str: ) ) - output.append(" %s" % message.message) + output.append(f" {message.message}") return "\n".join(output) diff --git a/prospector/formatters/vscode.py b/prospector/formatters/vscode.py index e7df5108..d99d0ce6 100644 --- a/prospector/formatters/vscode.py +++ b/prospector/formatters/vscode.py @@ -20,7 +20,7 @@ def render(self, summary: bool = True, messages: bool = True, profile: bool = Fa module_name = self._make_path(message.location.path).replace(os.path.sep, ".") module_name = re.sub(r"(\.__init__)?\.py$", "", module_name) - header = "************* Module %s" % module_name + header = f"************* Module {module_name}" output.append(header) template = "%(line)s,%(character)s,%(code)s,%(code)s:%(source)s %(message)s" diff --git a/prospector/formatters/xunit.py b/prospector/formatters/xunit.py index 7671c156..3724b0c4 100644 --- a/prospector/formatters/xunit.py +++ b/prospector/formatters/xunit.py @@ -16,7 +16,7 @@ def render(self, summary: bool = True, messages: bool = True, profile: bool = Fa testsuite_el = xml_doc.createElement("testsuite") testsuite_el.setAttribute("errors", str(self.summary["message_count"])) testsuite_el.setAttribute("failures", "0") - testsuite_el.setAttribute("name", "prospector-%s" % "-".join(self.summary["tools"])) + testsuite_el.setAttribute("name", "prospector-{}".format("-".join(self.summary["tools"]))) testsuite_el.setAttribute("tests", str(self.summary["message_count"])) testsuite_el.setAttribute("time", str(self.summary["time_taken"])) xml_doc.appendChild(testsuite_el) @@ -38,7 +38,7 @@ def render(self, summary: bool = True, messages: bool = True, profile: bool = Fa failure_el = xml_doc.createElement("error") failure_el.setAttribute("message", message.message.strip()) - failure_el.setAttribute("type", "%s Error" % message.source) + failure_el.setAttribute("type", f"{message.source} Error") template = "%(path)s:%(line)s: [%(code)s(%(source)s), %(function)s] %(message)s" cdata = template % { "path": self._make_path(message.location.path), diff --git a/prospector/pathutils.py b/prospector/pathutils.py index 4d75a0a0..d21cdc50 100644 --- a/prospector/pathutils.py +++ b/prospector/pathutils.py @@ -12,11 +12,7 @@ def is_python_module(path: Path) -> bool: def is_virtualenv(path: Path) -> bool: - if os.name == "nt": - # Windows! - clues = ("Scripts", "lib", "include") - else: - clues = ("bin", "lib", "include") + clues = ("Scripts", "lib", "include") if os.name == "nt" else ("bin", "lib", "include") try: # just get the name, iterdir returns absolute paths by default @@ -37,8 +33,4 @@ def is_virtualenv(path: Path) -> bool: # if we do have all three directories, make sure that it's not # just a coincidence by doing some heuristics on the rest of # the directory - if len(dircontents) > 7: - # if there are more than 7 things it's probably not a virtualenvironment - return False - - return True + return len(dircontents) <= 7 diff --git a/prospector/postfilter.py b/prospector/postfilter.py index c398ba59..78ee07f7 100644 --- a/prospector/postfilter.py +++ b/prospector/postfilter.py @@ -42,15 +42,16 @@ def filter_messages(filepaths: List[Path], messages: List[Message]) -> List[Mess continue # some lines are skipped entirely by messages - if relative_message_path in lines_to_ignore: - if message.location.line in lines_to_ignore[relative_message_path]: - continue + if relative_message_path in lines_to_ignore and message.location.line in lines_to_ignore[relative_message_path]: + continue # and some lines have only certain messages explicitly ignored - if relative_message_path in messages_to_ignore: - if message.location.line in messages_to_ignore[relative_message_path]: - if message.code in messages_to_ignore[relative_message_path][message.location.line]: - continue + if ( + relative_message_path in messages_to_ignore + and message.location.line in messages_to_ignore[relative_message_path] + and message.code in messages_to_ignore[relative_message_path][message.location.line] + ): + continue # otherwise this message was not filtered filtered.append(message) diff --git a/prospector/profiles/exceptions.py b/prospector/profiles/exceptions.py index 84564875..093ea8bc 100644 --- a/prospector/profiles/exceptions.py +++ b/prospector/profiles/exceptions.py @@ -18,11 +18,11 @@ def __init__(self, filepath: str, parse_error: Exception) -> None: self.parse_error = parse_error def get_parse_message(self) -> str: - return "{}\n on line {} : char {}".format( - self.parse_error.problem, # type: ignore[attr-defined] - self.parse_error.problem_mark.line, # type: ignore[attr-defined] - self.parse_error.problem_mark.column, # type: ignore[attr-defined] + return ( + f"{self.parse_error.problem}\n" + f" on line {self.parse_error.problem_mark.line}: " + f"char {self.parse_error.problem_mark.column}" ) def __repr__(self) -> str: - return "Could not parse profile found at %s - it is not valid YAML" % self.filepath + return f"Could not parse profile found at {self.filepath} - it is not valid YAML" diff --git a/prospector/profiles/profile.py b/prospector/profiles/profile.py index 7ffe3831..5c489e48 100644 --- a/prospector/profiles/profile.py +++ b/prospector/profiles/profile.py @@ -263,7 +263,7 @@ def _determine_strictness(profile_dict: dict[str, Any], inherits: list[str]) -> strictness = profile_dict.get("strictness") if strictness is None: return None, False - return ("strictness_%s" % strictness), True + return (f"strictness_{strictness}"), True def _determine_pep8(profile_dict: dict[str, Any]) -> tuple[Optional[str], bool]: diff --git a/prospector/run.py b/prospector/run.py index 45f32140..31b0f385 100644 --- a/prospector/run.py +++ b/prospector/run.py @@ -68,7 +68,7 @@ def execute(self) -> None: message=msg, ) messages.append(message) - warnings.warn(msg, category=DeprecationWarning) + warnings.warn(msg, category=DeprecationWarning, stacklevel=0) # Run the tools for tool in self.config.get_tools(found_files): @@ -122,14 +122,14 @@ def execute(self) -> None: summary["completed"] = datetime.now() delta = summary["completed"] - summary["started"] - summary["time_taken"] = "%0.2f" % delta.total_seconds() + summary["time_taken"] = f"{delta.total_seconds():0.2f}" external_config = [] for tool_name, configured_by in self.config.configured_by.items(): if configured_by is not None: external_config.append((tool_name, configured_by)) if len(external_config) > 0: - summary["external_config"] = ", ".join(["%s: %s" % info for info in external_config]) + summary["external_config"] = ", ".join(["{}: {}".format(*info) for info in external_config]) self.summary = summary self.messages = self.messages + messages diff --git a/prospector/suppression.py b/prospector/suppression.py index 018f5e82..bc196889 100644 --- a/prospector/suppression.py +++ b/prospector/suppression.py @@ -102,7 +102,7 @@ def get_suppressions( file_contents = encoding.read_py_file(filepath).split("\n") except encoding.CouldNotHandleEncoding as err: # TODO: this output will break output formats such as JSON - warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning) + warnings.warn(f"{err.path}: {err.__cause__}", ImportWarning, stacklevel=2) continue ignore_file, ignore_lines = get_noqa_suppressions(file_contents) diff --git a/prospector/tools/profile_validator/__init__.py b/prospector/tools/profile_validator/__init__.py index a92e225d..eb1bf5b5 100644 --- a/prospector/tools/profile_validator/__init__.py +++ b/prospector/tools/profile_validator/__init__.py @@ -166,7 +166,7 @@ def add_message(code: str, message: str, setting: str) -> None: if not isinstance(parsed[key], (tuple, list)): add_message(CONFIG_SETTING_SHOULD_BE_LIST, f'"{key}" should be a list', key) - for key in parsed.keys(): + for key in parsed: if key not in ProfileValidationTool.ALL_SETTINGS and key not in _tool_names(): add_message( CONFIG_UNKNOWN_SETTING, diff --git a/prospector/tools/pycodestyle/__init__.py b/prospector/tools/pycodestyle/__init__.py index 973bbf72..20a77da3 100644 --- a/prospector/tools/pycodestyle/__init__.py +++ b/prospector/tools/pycodestyle/__init__.py @@ -139,7 +139,7 @@ def configure( if "max-line-length" in prospector_config.tool_options("pycodestyle"): self.checker.options.max_line_length = prospector_config.tool_options("pycodestyle")["max-line-length"] else: - configured_by = "Configuration found at %s" % external_config + configured_by = f"Configuration found at {external_config}" # if we have a command line --max-line-length argument, that # overrules everything diff --git a/prospector/tools/pylint/__init__.py b/prospector/tools/pylint/__init__.py index 21f02a5a..9d270160 100644 --- a/prospector/tools/pylint/__init__.py +++ b/prospector/tools/pylint/__init__.py @@ -55,7 +55,7 @@ def _prospector_configure(self, prospector_config: "ProspectorConfig", linter: P errors.append(self._error_message(profile_path, f"Could not load plugin {plugin}")) for msg_id in prospector_config.get_disabled_messages("pylint"): - try: + try: # noqa: SIM105 linter.disable(msg_id) except UnknownMessageError: # If the msg_id doesn't exist in PyLint any more, @@ -89,9 +89,8 @@ def _prospector_configure(self, prospector_config: "ProspectorConfig", linter: P if not hasattr(checker, "options"): continue for option in checker.options: - if max_line_length is not None: - if option[0] == "max-line-length": - checker.set_option("max-line-length", max_line_length) + if max_line_length is not None and option[0] == "max-line-length": + checker.set_option("max-line-length", max_line_length) return errors def _error_message(self, filepath: Union[str, Path], message: str) -> Message: @@ -236,7 +235,7 @@ def _combine_w0614(self, messages: list[Message]) -> list[Message]: assert match_ is not None names.append(match_.group(1)) - msgtxt = "Unused imports from wildcard import: %s" % ", ".join(names) + msgtxt = "Unused imports from wildcard import: {}".format(", ".join(names)) combined_message = Message("pylint", "unused-wildcard-import", location, msgtxt) out.append(combined_message) diff --git a/prospector/tools/pylint/collector.py b/prospector/tools/pylint/collector.py index 12a778f0..be49713b 100644 --- a/prospector/tools/pylint/collector.py +++ b/prospector/tools/pylint/collector.py @@ -2,7 +2,8 @@ from typing import List from pylint.exceptions import UnknownMessageError -from pylint.message import Message as PylintMessage, MessageDefinitionStore +from pylint.message import Message as PylintMessage +from pylint.message import MessageDefinitionStore from pylint.reporters import BaseReporter from prospector.message import Location, Message diff --git a/prospector/tools/pyright/__init__.py b/prospector/tools/pyright/__init__.py index 5e930bf8..89896d01 100644 --- a/prospector/tools/pyright/__init__.py +++ b/prospector/tools/pyright/__init__.py @@ -59,7 +59,7 @@ def configure( # pylint: disable=useless-return ) -> Optional[tuple[str, Optional[Iterable[Message]]]]: options = prospector_config.tool_options("pyright") - for option_key in options.keys(): + for option_key in options: if option_key not in VALID_OPTIONS: url = "https://github.com/PyCQA/prospector/blob/master/prospector/tools/pyright/__init__.py" raise BadToolConfig( diff --git a/prospector/tools/vulture/__init__.py b/prospector/tools/vulture/__init__.py index f4de8c3d..77cd06bc 100644 --- a/prospector/tools/vulture/__init__.py +++ b/prospector/tools/vulture/__init__.py @@ -64,10 +64,7 @@ def get_messages(self) -> list[Message]: filename = item.file except AttributeError: filename = item.filename - if hasattr(item, "lineno"): - lineno = item.lineno # for older versions of vulture - else: - lineno = item.first_lineno + lineno = item.lineno if hasattr(item, "lineno") else item.first_lineno loc = Location(filename, None, None, lineno, -1) message_text = template % item message = Message("vulture", code, loc, message_text) diff --git a/pyproject.toml b/pyproject.toml index 21e34678..3230a51a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,9 +92,23 @@ exclude = ''' )/ ''' -[tool.isort] -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true -line_length = 120 +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +fixable = ["ALL"] +extend-select = [ + "UP", # pyupgrade + "F", # Pyflakes + "E", "W", # Pycodestyle + "I", # isort + "S", # flake8-bandit + "SIM", # flake8-simplify + "B", # flake8-bugbear + # pydocstyle + "D203", "D213", "D214", "D215", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D413", "D416", "D417", +] +ignore= [ + "E501", # Line too long (black will handle this) + "S101", # Use of assert detected +] diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 68cb1753..fa012e28 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -16,7 +16,7 @@ def test_relative_ignores(): with patch_execution("-P", "profile_relative_ignores.yml", set_cwd=workdir): config = ProspectorConfig() files = FileFinder(*config.paths, exclusion_filters=[config.make_exclusion_filter()]) - assert 2 == len(files.python_modules) + assert len(files.python_modules) == 2 def test_determine_ignores_all_str(): diff --git a/tests/formatters/test_formatter_types.py b/tests/formatters/test_formatter_types.py index 99ca77c3..b80e6936 100644 --- a/tests/formatters/test_formatter_types.py +++ b/tests/formatters/test_formatter_types.py @@ -28,7 +28,7 @@ def _simple_summary() -> dict: def test_formatter_types(_simple_summary, _simple_profile): - for formatter_name, formatter in FORMATTERS.items(): + for _formatter_name, formatter in FORMATTERS.items(): formatter_instance = formatter(_simple_summary, [], _simple_profile) assert isinstance(formatter_instance.render(True, True, False), str) @@ -37,7 +37,7 @@ def test_formatters_render(_simple_summary, _simple_profile): """ Basic test to ensure that formatters can at least render messages without erroring """ - for formatter_name, formatter in FORMATTERS.items(): + for _formatter_name, formatter in FORMATTERS.items(): messages = [ Message( "testtool", diff --git a/tests/profiles/test_profile.py b/tests/profiles/test_profile.py index a428fbdb..66358851 100644 --- a/tests/profiles/test_profile.py +++ b/tests/profiles/test_profile.py @@ -50,7 +50,7 @@ def test_old_inherits_from_new(self): assert "E266" not in profile.pycodestyle["disable"] - assert 120 == profile.pycodestyle["options"]["max-line-length"] + assert profile.pycodestyle["options"]["max-line-length"] == 120 def test_new_inherits_from_old(self): """ @@ -65,7 +65,7 @@ def test_new_inherits_from_old(self): assert "E266" not in profile.pycodestyle["disable"] - assert 140 == profile.pycodestyle["options"]["max-line-length"] + assert profile.pycodestyle["options"]["max-line-length"] == 140 def test_legacy_names_equivalent(self): """ diff --git a/tests/tools/mypy/test_mypy_tool.py b/tests/tools/mypy/test_mypy_tool.py index a7332e7f..325ef014 100644 --- a/tests/tools/mypy/test_mypy_tool.py +++ b/tests/tools/mypy/test_mypy_tool.py @@ -10,7 +10,7 @@ try: from prospector.tools.mypy import format_message except ImportError: - raise SkipTest + raise SkipTest # noqa: B904 class TestMypyTool(TestCase): diff --git a/tests/tools/pycodestyle/test_pycodestyle_tool.py b/tests/tools/pycodestyle/test_pycodestyle_tool.py index a601ef74..377bdb55 100644 --- a/tests/tools/pycodestyle/test_pycodestyle_tool.py +++ b/tests/tools/pycodestyle/test_pycodestyle_tool.py @@ -39,10 +39,10 @@ def test_find_pep8_section_in_config(self): workdir = Path(__file__).parent / "testsettings/pep8" configured_by, _ = self._configure("testsettings/pep8/testfile.py", workdir=workdir) expected_config_path = str(workdir / "setup.cfg") - self.assertEqual(configured_by, "Configuration found at %s" % expected_config_path) + self.assertEqual(configured_by, f"Configuration found at {expected_config_path}") def test_find_pycodestyle_section_in_config(self): workdir = Path(__file__).parent / "testsettings/pycodestyle" configured_by, _ = self._configure("testsettings/pycodestyle/testfile.py", workdir=workdir) expected_config_path = str(workdir / "setup.cfg") - self.assertEqual(configured_by, "Configuration found at %s" % expected_config_path) + self.assertEqual(configured_by, f"Configuration found at {expected_config_path}") diff --git a/tests/tools/pyright/test_pyright_tool.py b/tests/tools/pyright/test_pyright_tool.py index 2131521f..d319b26c 100644 --- a/tests/tools/pyright/test_pyright_tool.py +++ b/tests/tools/pyright/test_pyright_tool.py @@ -11,7 +11,7 @@ try: from prospector.tools.pyright import format_messages except ImportError: - raise SkipTest + raise SkipTest # noqa: B904 class TestPyrightTool(TestCase):