From 3745592173d660544d938ec11a1522f8aec0f623 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Nov 2022 00:59:00 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- install-poetry.py | 11 ++++----- tests/test_install_poetry.py | 44 +++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/install-poetry.py b/install-poetry.py index 0d2e0e3..4e1215a 100644 --- a/install-poetry.py +++ b/install-poetry.py @@ -902,10 +902,8 @@ def main(): "--stderr", dest="stderr", action="store_true", - help=( - "Log installation errors to stderr instead of a log file." - ), - default=False + help=("Log installation errors to stderr instead of a log file."), + default=False, ) args = parser.parse_args() @@ -921,7 +919,9 @@ def main(): git=args.git, ) - disable_log_file = args.stderr or string_to_bool(os.getenv("POETRY_LOG_STDERR", "0")) + disable_log_file = args.stderr or string_to_bool( + os.getenv("POETRY_LOG_STDERR", "0") + ) if not disable_log_file and string_to_bool(os.getenv("CI", "0")): installer._write( @@ -929,7 +929,6 @@ def main(): ) disable_log_file = True - if args.uninstall or string_to_bool(os.getenv("POETRY_UNINSTALL", "0")): return installer.uninstall() diff --git a/tests/test_install_poetry.py b/tests/test_install_poetry.py index b5deaee..15c4e78 100644 --- a/tests/test_install_poetry.py +++ b/tests/test_install_poetry.py @@ -1,9 +1,11 @@ -from unittest.mock import MagicMock, patch +import importlib import re import typing -import importlib import unittest +from unittest.mock import MagicMock +from unittest.mock import patch + module = importlib.import_module("install-poetry") @@ -65,7 +67,7 @@ class InstallPoetryTestCase(unittest.TestCase): force=False, accept_all=True, path=None, - git=None + git=None, ) self.__installer.uninstall.assert_not_called() @@ -79,8 +81,12 @@ class InstallPoetryTestCase(unittest.TestCase): return_code = module.main() - self.__assert_no_matching_message("error", re.compile("a fake poetry installation error")) - self.__assert_any_matching_message("error", re.compile(f"See {self.__tmp_file} for error logs")) + self.__assert_no_matching_message( + "error", re.compile("a fake poetry installation error") + ) + self.__assert_any_matching_message( + "error", re.compile(f"See {self.__tmp_file} for error logs") + ) self.assertEqual(return_code, 1) self.__mock_path_cls(self.__tmp_file).write_text.assert_called_once() @@ -94,7 +100,9 @@ class InstallPoetryTestCase(unittest.TestCase): return_code = module.main() self.__assert_no_matching_message("info", re.compile("CI environment detected")) - self.__assert_any_matching_message("error", re.compile("a fake poetry installation error")) + self.__assert_any_matching_message( + "error", re.compile("a fake poetry installation error") + ) self.assertEqual(return_code, 1) self.__mock_path_cls.assert_not_called() @@ -108,7 +116,9 @@ class InstallPoetryTestCase(unittest.TestCase): return_code = module.main() self.__assert_no_matching_message("info", re.compile("CI environment detected")) - self.__assert_any_matching_message("error", re.compile("a fake poetry installation error")) + self.__assert_any_matching_message( + "error", re.compile("a fake poetry installation error") + ) self.assertEqual(return_code, 1) self.__mock_path_cls.assert_not_called() @@ -121,8 +131,12 @@ class InstallPoetryTestCase(unittest.TestCase): return_code = module.main() - self.__assert_any_matching_message("info", re.compile("CI environment detected")) - self.__assert_any_matching_message("error", re.compile("a fake poetry installation error")) + self.__assert_any_matching_message( + "info", re.compile("CI environment detected") + ) + self.__assert_any_matching_message( + "error", re.compile("a fake poetry installation error") + ) self.assertEqual(return_code, 1) self.__mock_path_cls.assert_not_called() @@ -131,7 +145,9 @@ class InstallPoetryTestCase(unittest.TestCase): self.__messages.append((severity, message)) return f"{severity}:{message}" - def __getenv(self, key: str, default: typing.Optional[str] = None) -> typing.Optional[str]: + def __getenv( + self, key: str, default: typing.Optional[str] = None + ) -> typing.Optional[str]: return self.__env.get(key, default) def __mkstemp(self, suffix="suffix", prefix="prefix", dir=None, text=None): @@ -145,4 +161,10 @@ class InstallPoetryTestCase(unittest.TestCase): self.assertEqual(self.__count_matching_message(severity, pattern), 0) def __count_matching_message(self, severity: str, pattern: re.Pattern): - return len([message for message in self.__messages if severity == message[0] and pattern.search(message[1])]) + return len( + [ + message + for message in self.__messages + if severity == message[0] and pattern.search(message[1]) + ] + )