From dd2c799da35740b0b87716902d8386983b5d326d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 29 Jan 2024 08:01:29 +0100 Subject: [PATCH] Reformat with black 24.1.1 Black 24.1.0 changed some formatting styles. --- pontos/github/api/branch.py | 204 +++++++++--------- pontos/github/script/load.py | 5 +- pontos/github/scripts/team-repositories.py | 6 +- pontos/release/create.py | 16 +- pontos/release/show.py | 8 +- pontos/release/sign.py | 17 +- pontos/testing/__init__.py | 9 +- pontos/version/commands/_cmake.py | 10 +- tests/changelog/test_conventional_commits.py | 9 +- tests/git/test_git.py | 7 +- tests/github/script/test_load.py | 73 ++++--- tests/github/test_cmds.py | 7 +- tests/release/test_show.py | 9 +- tests/test_helper.py | 26 ++- tests/version/commands/test_go.py | 115 +++++++---- tests/version/commands/test_java.py | 36 ++-- tests/version/commands/test_javascript.py | 127 +++++++----- tests/version/commands/test_python.py | 205 +++++++++++-------- tests/version/test_main.py | 142 ++++++++----- tests/version/test_project.py | 7 +- 20 files changed, 605 insertions(+), 433 deletions(-) diff --git a/pontos/github/api/branch.py b/pontos/github/api/branch.py index 64c7c1c3b..4e80a31f4 100644 --- a/pontos/github/api/branch.py +++ b/pontos/github/api/branch.py @@ -55,18 +55,18 @@ def update_from_applied_settings( if required_linear_history is not None: kwargs["required_linear_history"] = required_linear_history elif branch_protection.required_linear_history: - kwargs[ - "required_linear_history" - ] = branch_protection.required_linear_history.enabled + kwargs["required_linear_history"] = ( + branch_protection.required_linear_history.enabled + ) else: kwargs["required_linear_history"] = None if allow_force_pushes is not None: kwargs["allow_force_pushes"] = allow_force_pushes elif branch_protection.allow_force_pushes: - kwargs[ - "allow_force_pushes" - ] = branch_protection.allow_force_pushes.enabled + kwargs["allow_force_pushes"] = ( + branch_protection.allow_force_pushes.enabled + ) else: kwargs["allow_force_pushes"] = None @@ -78,13 +78,13 @@ def update_from_applied_settings( kwargs["allow_deletions"] = None if required_conversation_resolution is not None: - kwargs[ - "required_conversation_resolution" - ] = required_conversation_resolution + kwargs["required_conversation_resolution"] = ( + required_conversation_resolution + ) elif branch_protection.required_conversation_resolution: - kwargs[ - "required_conversation_resolution" - ] = branch_protection.required_conversation_resolution.enabled + kwargs["required_conversation_resolution"] = ( + branch_protection.required_conversation_resolution.enabled + ) else: kwargs["required_conversation_resolution"] = None @@ -105,25 +105,25 @@ def update_from_applied_settings( if allow_fork_syncing is not None: kwargs["allow_fork_syncing"] = allow_fork_syncing elif branch_protection.allow_fork_syncing: - kwargs[ - "allow_fork_syncing" - ] = branch_protection.allow_fork_syncing.enabled + kwargs["allow_fork_syncing"] = ( + branch_protection.allow_fork_syncing.enabled + ) else: kwargs["allow_fork_syncing"] = None if required_signatures is not None: kwargs["required_signatures"] = required_signatures elif branch_protection.required_signatures: - kwargs[ - "required_signatures" - ] = branch_protection.required_signatures.enabled + kwargs["required_signatures"] = ( + branch_protection.required_signatures.enabled + ) else: kwargs["required_signatures"] = None existing_required_status_checks = branch_protection.required_status_checks if existing_required_status_checks: - kwargs[ - "require_branches_to_be_up_to_date" - ] = existing_required_status_checks.strict + kwargs["require_branches_to_be_up_to_date"] = ( + existing_required_status_checks.strict + ) if existing_required_status_checks.checks is not None: kwargs["required_status_checks"] = [ (c.context, c.app_id) @@ -132,9 +132,9 @@ def update_from_applied_settings( if required_status_checks is not None: kwargs["required_status_checks"] = required_status_checks if require_branches_to_be_up_to_date: - kwargs[ - "require_branches_to_be_up_to_date" - ] = require_branches_to_be_up_to_date + kwargs["require_branches_to_be_up_to_date"] = ( + require_branches_to_be_up_to_date + ) required_pull_request_reviews = ( branch_protection.required_pull_request_reviews @@ -163,18 +163,18 @@ def update_from_applied_settings( else: kwargs["dismissal_restrictions_apps"] = [] - kwargs[ - "dismiss_stale_reviews" - ] = required_pull_request_reviews.dismiss_stale_reviews - kwargs[ - "require_code_owner_reviews" - ] = required_pull_request_reviews.require_code_owner_reviews - kwargs[ - "required_approving_review_count" - ] = required_pull_request_reviews.required_approving_review_count - kwargs[ - "require_last_push_approval" - ] = required_pull_request_reviews.require_last_push_approval + kwargs["dismiss_stale_reviews"] = ( + required_pull_request_reviews.dismiss_stale_reviews + ) + kwargs["require_code_owner_reviews"] = ( + required_pull_request_reviews.require_code_owner_reviews + ) + kwargs["required_approving_review_count"] = ( + required_pull_request_reviews.required_approving_review_count + ) + kwargs["require_last_push_approval"] = ( + required_pull_request_reviews.require_last_push_approval + ) bypass_pull_request_allowances = ( required_pull_request_reviews.bypass_pull_request_allowances @@ -249,9 +249,9 @@ def update_from_applied_settings( if require_code_owner_reviews is not None: kwargs["require_code_owner_reviews"] = require_code_owner_reviews if required_approving_review_count is not None: - kwargs[ - "required_approving_review_count" - ] = required_approving_review_count + kwargs["required_approving_review_count"] = ( + required_approving_review_count + ) if require_last_push_approval is not None: kwargs["require_last_push_approval"] = require_last_push_approval @@ -477,9 +477,9 @@ async def update_protection_rules( if block_creations is not None: data["block_creations"] = block_creations if required_conversation_resolution is not None: - data[ - "required_conversation_resolution" - ] = required_conversation_resolution + data["required_conversation_resolution"] = ( + required_conversation_resolution + ) if lock_branch is not None: data["lock_branch"] = lock_branch if allow_fork_syncing is not None: @@ -529,42 +529,42 @@ async def update_protection_rules( required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} ) - required_pull_request_reviews[ - "dismiss_stale_reviews" - ] = dismiss_stale_reviews - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["dismiss_stale_reviews"] = ( + dismiss_stale_reviews + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if require_code_owner_reviews is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} ) - required_pull_request_reviews[ - "require_code_owner_reviews" - ] = require_code_owner_reviews - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["require_code_owner_reviews"] = ( + require_code_owner_reviews + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if required_approving_review_count is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} ) - required_pull_request_reviews[ - "required_approving_review_count" - ] = required_approving_review_count - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["required_approving_review_count"] = ( + required_approving_review_count + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if require_last_push_approval is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} ) - required_pull_request_reviews[ - "require_last_push_approval" - ] = require_last_push_approval - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["require_last_push_approval"] = ( + require_last_push_approval + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if dismissal_restrictions_users is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -573,12 +573,12 @@ async def update_protection_rules( "dismissal_restrictions", {} ) dismissal_restrictions["users"] = list(dismissal_restrictions_users) - required_pull_request_reviews[ - "dismissal_restrictions" - ] = dismissal_restrictions - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["dismissal_restrictions"] = ( + dismissal_restrictions + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if dismissal_restrictions_teams is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -587,12 +587,12 @@ async def update_protection_rules( "dismissal_restrictions", {} ) dismissal_restrictions["teams"] = list(dismissal_restrictions_teams) - required_pull_request_reviews[ - "dismissal_restrictions" - ] = dismissal_restrictions - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["dismissal_restrictions"] = ( + dismissal_restrictions + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if dismissal_restrictions_apps is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -601,12 +601,12 @@ async def update_protection_rules( "dismissal_restrictions", {} ) dismissal_restrictions["apps"] = list(dismissal_restrictions_apps) - required_pull_request_reviews[ - "dismissal_restrictions" - ] = dismissal_restrictions - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["dismissal_restrictions"] = ( + dismissal_restrictions + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if bypass_pull_request_allowances_users is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -617,12 +617,12 @@ async def update_protection_rules( bypass_pull_request_allowances["users"] = list( bypass_pull_request_allowances_users ) - required_pull_request_reviews[ - "bypass_pull_request_allowances" - ] = bypass_pull_request_allowances - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["bypass_pull_request_allowances"] = ( + bypass_pull_request_allowances + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if bypass_pull_request_allowances_teams is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -633,12 +633,12 @@ async def update_protection_rules( bypass_pull_request_allowances["teams"] = list( bypass_pull_request_allowances_teams ) - required_pull_request_reviews[ - "bypass_pull_request_allowances" - ] = bypass_pull_request_allowances - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["bypass_pull_request_allowances"] = ( + bypass_pull_request_allowances + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if bypass_pull_request_allowances_apps is not None: required_pull_request_reviews = ( data.get("required_pull_request_reviews") or {} @@ -649,12 +649,12 @@ async def update_protection_rules( bypass_pull_request_allowances["apps"] = list( bypass_pull_request_allowances_apps ) - required_pull_request_reviews[ - "bypass_pull_request_allowances" - ] = bypass_pull_request_allowances - data[ - "required_pull_request_reviews" - ] = required_pull_request_reviews + required_pull_request_reviews["bypass_pull_request_allowances"] = ( + bypass_pull_request_allowances + ) + data["required_pull_request_reviews"] = ( + required_pull_request_reviews + ) if required_signatures is not None: data["required_signatures"] = required_signatures diff --git a/pontos/github/script/load.py b/pontos/github/script/load.py index c1d87a294..a4155ef96 100644 --- a/pontos/github/script/load.py +++ b/pontos/github/script/load.py @@ -49,8 +49,9 @@ def load_script( if path.suffix == ".py": module_name = path.stem - with add_sys_path(path.parent.absolute()), ensure_unload_module( - module_name + with ( + add_sys_path(path.parent.absolute()), + ensure_unload_module(module_name), ): yield importlib.import_module(module_name) else: diff --git a/pontos/github/scripts/team-repositories.py b/pontos/github/scripts/team-repositories.py index cb04524f3..554856708 100644 --- a/pontos/github/scripts/team-repositories.py +++ b/pontos/github/scripts/team-repositories.py @@ -81,9 +81,9 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int: done, pending = await asyncio.wait( tasks, - return_when=asyncio.FIRST_EXCEPTION - if args.failfast - else asyncio.ALL_COMPLETED, + return_when=( + asyncio.FIRST_EXCEPTION if args.failfast else asyncio.ALL_COMPLETED + ), ) pending: Set[asyncio.Task] diff --git a/pontos/release/create.py b/pontos/release/create.py index a3493cad4..0f5683f07 100644 --- a/pontos/release/create.py +++ b/pontos/release/create.py @@ -94,9 +94,11 @@ def _create_changelog( ) return changelog_builder.create_changelog( - last_version=last_release_version.parsed_version - if last_release_version - else None, + last_version=( + last_release_version.parsed_version + if last_release_version + else None + ), next_version=release_version, ) @@ -193,9 +195,11 @@ async def async_run( # type: ignore[override] last_release_version = get_last_release_version( parse_version=versioning_scheme.parse_version, git_tag_prefix=self.git_tag_prefix, - tag_name=f"{self.git_tag_prefix}{release_series}.*" - if release_series - else None, + tag_name=( + f"{self.git_tag_prefix}{release_series}.*" + if release_series + else None + ), # include changes from pre-releases in release changelog for # non pre-release changes ignore_pre_releases=release_type diff --git a/pontos/release/show.py b/pontos/release/show.py index 0715dfbf0..68acdbdac 100644 --- a/pontos/release/show.py +++ b/pontos/release/show.py @@ -56,9 +56,11 @@ def run( # type: ignore[override] last_release_version = get_last_release_version( parse_version=versioning_scheme.parse_version, git_tag_prefix=git_tag_prefix, - tag_name=f"{git_tag_prefix}{release_series}.*" - if release_series - else None, + tag_name=( + f"{git_tag_prefix}{release_series}.*" + if release_series + else None + ), ) except PontosError as e: last_release_version = None diff --git a/pontos/release/sign.py b/pontos/release/sign.py index 25a152f38..0a542a661 100644 --- a/pontos/release/sign.py +++ b/pontos/release/sign.py @@ -232,9 +232,11 @@ async def async_run( # type: ignore[override] else get_last_release_version( versioning_scheme.parse_version, git_tag_prefix=git_tag_prefix, - tag_name=f"{git_tag_prefix}{release_series}.*" - if release_series - else None, + tag_name=( + f"{git_tag_prefix}{release_series}.*" + if release_series + else None + ), ) ) except PontosError as e: @@ -291,7 +293,10 @@ async def async_run( # type: ignore[override] ) # pylint: disable=line-too-long - async for name, download_cm in github.releases.download_release_assets( # noqa: E501 + async for ( + name, + download_cm, + ) in github.releases.download_release_assets( # noqa: E501 repo, git_version, ): @@ -350,7 +355,9 @@ async def async_run( # type: ignore[override] try: # pylint: disable=line-too-long - async for uploaded_file in github.releases.upload_release_assets( # noqa: E501 + async for ( + uploaded_file + ) in github.releases.upload_release_assets( # noqa: E501 repo, git_version, upload_files ): self.terminal.ok(f"Uploaded: {uploaded_file}") diff --git a/pontos/testing/__init__.py b/pontos/testing/__init__.py index 49cf20c29..398de367c 100644 --- a/pontos/testing/__init__.py +++ b/pontos/testing/__init__.py @@ -205,9 +205,12 @@ def temp_python_module( """ - with temp_directory( - add_to_sys_path=True, change_into=change_into - ) as tmp_dir, ensure_unload_module(name): + with ( + temp_directory( + add_to_sys_path=True, change_into=change_into + ) as tmp_dir, + ensure_unload_module(name), + ): test_file = tmp_dir / f"{name}.py" test_file.write_text(content, encoding="utf8") yield test_file diff --git a/pontos/version/commands/_cmake.py b/pontos/version/commands/_cmake.py index 154940383..2f1acc262 100644 --- a/pontos/version/commands/_cmake.py +++ b/pontos/version/commands/_cmake.py @@ -114,12 +114,10 @@ def update_version(self, new_version: Version) -> str: self._current_version = str(new_version) if self._project_dev_version_line_number: - self._cmake_content_lines[ - self._project_dev_version_line_number - ] = self._cmake_content_lines[ - self._project_dev_version_line_number - ].replace( - str(int(not develop)), str(int(develop)) + self._cmake_content_lines[self._project_dev_version_line_number] = ( + self._cmake_content_lines[ + self._project_dev_version_line_number + ].replace(str(int(not develop)), str(int(develop))) ) self._project_dev_version = str(int(develop)) diff --git a/tests/changelog/test_conventional_commits.py b/tests/changelog/test_conventional_commits.py index 6988af410..ba9ef2353 100644 --- a/tests/changelog/test_conventional_commits.py +++ b/tests/changelog/test_conventional_commits.py @@ -321,9 +321,12 @@ def test_changelog_builder_no_conventional_commits( ) def test_changelog_builder_config_file_not_exists(self): - with temp_directory() as temp_dir, self.assertRaisesRegex( - ChangelogBuilderError, - r"Changelog Config file '.*\.toml' does not exist\.", + with ( + temp_directory() as temp_dir, + self.assertRaisesRegex( + ChangelogBuilderError, + r"Changelog Config file '.*\.toml' does not exist\.", + ), ): ChangelogBuilder( space="foo", diff --git a/tests/git/test_git.py b/tests/git/test_git.py index e20037e07..0c50be63c 100644 --- a/tests/git/test_git.py +++ b/tests/git/test_git.py @@ -1044,9 +1044,10 @@ def test_git_status(self): next(it) def test_git_error(self): - with temp_directory(change_into=True), self.assertRaises( - GitError - ) as cm: + with ( + temp_directory(change_into=True), + self.assertRaises(GitError) as cm, + ): Git().log() self.assertEqual(cm.exception.returncode, 128) diff --git a/tests/github/script/test_load.py b/tests/github/script/test_load.py index 7ad1b0c67..3c167206a 100644 --- a/tests/github/script/test_load.py +++ b/tests/github/script/test_load.py @@ -20,17 +20,21 @@ class LoadScriptTestCase(unittest.TestCase): def test_load_script(self): - with temp_file( - "def foo():\n\treturn 1", name="foo.py" - ) as f, load_script(f) as module: + with ( + temp_file("def foo():\n\treturn 1", name="foo.py") as f, + load_script(f) as module, + ): self.assertIsNotNone(module) self.assertIsNotNone(module.foo) self.assertEqual(module.foo(), 1) def test_load_script_module(self): - with temp_python_module( - "def foo():\n\treturn 1", name="github-foo-script" - ), load_script("github-foo-script") as module: + with ( + temp_python_module( + "def foo():\n\treturn 1", name="github-foo-script" + ), + load_script("github-foo-script") as module, + ): self.assertIsNotNone(module) self.assertIsNotNone(module.foo) self.assertEqual(module.foo(), 1) @@ -45,21 +49,27 @@ def test_load_script_failure(self): class RunAddArgumentsFunction(unittest.TestCase): def test_add_arguments_function(self): - with temp_file( - "def add_script_arguments(parser):\n\t" - "parser.add_argument('--foo')", - name="foo.py", - ) as f, load_script(f) as module: + with ( + temp_file( + "def add_script_arguments(parser):\n\t" + "parser.add_argument('--foo')", + name="foo.py", + ) as f, + load_script(f) as module, + ): parser = ArgumentParser() run_add_arguments_function(module, parser) args = parser.parse_args(["--foo", "123"]) self.assertEqual(args.foo, "123") def test_no_add_arguments_function(self): - with temp_file( - "def foo():\n\tpass", - name="foo.py", - ) as f, load_script(f) as module: + with ( + temp_file( + "def foo():\n\tpass", + name="foo.py", + ) as f, + load_script(f) as module, + ): parser = ArgumentParser() run_add_arguments_function(module, parser) with self.assertRaises(SystemExit), redirect_stderr(io.StringIO()): @@ -68,26 +78,35 @@ def test_no_add_arguments_function(self): class RunGithubScriptFunctionTestCase(IsolatedAsyncioTestCase): def test_run_async_github_script_function(self): - with temp_file( - "async def github_script(api, args):\n\treturn 1", - name="foo.py", - ) as f, load_script(f) as module: + with ( + temp_file( + "async def github_script(api, args):\n\treturn 1", + name="foo.py", + ) as f, + load_script(f) as module, + ): self.assertEqual( run_github_script_function(module, "123", 123, {}), 1 ) def test_sync_github_script_function_not_supported(self): - with temp_file( - "def github_script(api, args):\n\treturn 1", - name="foo.py", - ) as f, load_script(f) as module: + with ( + temp_file( + "def github_script(api, args):\n\treturn 1", + name="foo.py", + ) as f, + load_script(f) as module, + ): with self.assertRaises(GitHubScriptError): run_github_script_function(module, "123", 123, {}) def test_no_github_script_function(self): - with temp_file( - "def foo():\n\tpass", - name="foo.py", - ) as f, load_script(f) as module: + with ( + temp_file( + "def foo():\n\tpass", + name="foo.py", + ) as f, + load_script(f) as module, + ): with self.assertRaises(GitHubScriptError): run_github_script_function(module, "123", 123, {}) diff --git a/tests/github/test_cmds.py b/tests/github/test_cmds.py index 3039f3146..203416711 100644 --- a/tests/github/test_cmds.py +++ b/tests/github/test_cmds.py @@ -39,9 +39,10 @@ async def test_file_status(self, api_mock): ], } - with temp_file(name="some.file") as test_file, test_file.open( - "w", encoding="utf8" - ) as output: + with ( + temp_file(name="some.file") as test_file, + test_file.open("w", encoding="utf8") as output, + ): args = Namespace( repo="foo/bar", pull_request=8, diff --git a/tests/release/test_show.py b/tests/release/test_show.py index 0e81c847a..99c1b0e0d 100644 --- a/tests/release/test_show.py +++ b/tests/release/test_show.py @@ -331,8 +331,13 @@ def test_initial_release(self): terminal.print.assert_called_once_with(expected) - with temp_file(name="output") as output_file, patch.dict( - "os.environ", {"GITHUB_OUTPUT": f"{output_file}"}, clear=True + with ( + temp_file(name="output") as output_file, + patch.dict( + "os.environ", + {"GITHUB_OUTPUT": f"{output_file}"}, + clear=True, + ), ): return_val = show_cmd.run( versioning_scheme=PEP440VersioningScheme, diff --git a/tests/test_helper.py b/tests/test_helper.py index 0f57b72e6..ba6a3e99c 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -503,8 +503,9 @@ def test_add_sys_path(self): # pylint: disable=import-error,import-outside-toplevel,unused-import import mymodule # noqa: F811,F401 - with temp_file("", name="mymodule.py") as module_path, add_sys_path( - module_path.parent + with ( + temp_file("", name="mymodule.py") as module_path, + add_sys_path(module_path.parent), ): # pylint: disable=import-error,import-outside-toplevel,unused-import import mymodule # noqa: F811,F401 @@ -514,9 +515,10 @@ def test_add_sys_path(self): class EnsureUnloadModuleTestCase(unittest.TestCase): def test_ensure_unload_module(self): - with temp_python_module( - "def foo():\n pass", name="bar" - ), ensure_unload_module("bar"): + with ( + temp_python_module("def foo():\n pass", name="bar"), + ensure_unload_module("bar"), + ): # pylint: disable=import-error,import-outside-toplevel,unused-import import bar # noqa: F401,F811 @@ -526,9 +528,12 @@ def test_ensure_unload_module(self): def test_ensure_unload_module_exception(self): with self.assertRaisesRegex(ValueError, "Ipsum"): - with temp_python_module( - "def func():\n raise ValueError('Ipsum')", name="bar" - ), ensure_unload_module("bar"): + with ( + temp_python_module( + "def func():\n raise ValueError('Ipsum')", name="bar" + ), + ensure_unload_module("bar"), + ): # pylint: disable=import-error,import-outside-toplevel,unused-import import bar @@ -544,8 +549,9 @@ def test_add_sys_path_exception(self): import mymodule # noqa: F811,F401 try: - with temp_file("", name="mymodule.py") as module_path, add_sys_path( - module_path.parent + with ( + temp_file("", name="mymodule.py") as module_path, + add_sys_path(module_path.parent), ): # pylint: disable=import-error,import-outside-toplevel,unused-import import mymodule # noqa: F811,F401 diff --git a/tests/version/commands/test_go.py b/tests/version/commands/test_go.py index c1b44e2c4..a76085a22 100644 --- a/tests/version/commands/test_go.py +++ b/tests/version/commands/test_go.py @@ -50,12 +50,15 @@ def test_getting_version(self): def test_no_version_found(self): exp_err_msg = "No version found in the version.go file." - with temp_file( - name="go.mod", - change_into=True, - ), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_file( + name="go.mod", + change_into=True, + ), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): version_file_path = Path(VERSION_FILE_PATH) version_file_path.touch() @@ -65,21 +68,27 @@ def test_no_version_file(self): exp_err_msg = ( "No version.go file found. This file is required for pontos" ) - with temp_file( - name="go.mod", - change_into=True, - ), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_file( + name="go.mod", + change_into=True, + ), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): GoVersionCommand(SemanticVersioningScheme).get_current_version() def test_invalid_version(self): - with temp_file( - name="go.mod", - change_into=True, - ), self.assertRaisesRegex( - VersionError, "abc is not valid SemVer string" + with ( + temp_file( + name="go.mod", + change_into=True, + ), + self.assertRaisesRegex( + VersionError, "abc is not valid SemVer string" + ), ): version_file_path = Path(VERSION_FILE_PATH) version_file_path.write_text( @@ -90,46 +99,62 @@ def test_invalid_version(self): class VerifyGoVersionCommandTestCase(unittest.TestCase): def test_verify_version(self): - with temp_file( - name="go.mod", - change_into=True, - ), patch.object( - GoVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("21.0.1") + with ( + temp_file( + name="go.mod", + change_into=True, + ), + patch.object( + GoVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "21.0.1" + ) + ), ), ): cmd = GoVersionCommand(SemanticVersioningScheme) cmd.verify_version(SemanticVersioningScheme.parse_version("21.0.1")) def test_verify_branch_not_equal(self): - with temp_file( - name="go.mod", - change_into=True, - ), patch.object( - GoVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("21.0.1") + with ( + temp_file( + name="go.mod", + change_into=True, + ), + patch.object( + GoVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "21.0.1" + ) + ), + ), + self.assertRaisesRegex( + VersionError, + "Provided version 21.2.0 does not match the current version " + "21.0.1.", ), - ), self.assertRaisesRegex( - VersionError, - "Provided version 21.2.0 does not match the current version " - "21.0.1.", ): cmd = GoVersionCommand(SemanticVersioningScheme) cmd.verify_version(SemanticVersioningScheme.parse_version("21.2.0")) def test_verify_current(self): - with temp_file( - name="go.mod", - change_into=True, - ), patch.object( - GoVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("21.0.1") + with ( + temp_file( + name="go.mod", + change_into=True, + ), + patch.object( + GoVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "21.0.1" + ) + ), ), ): cmd = GoVersionCommand(SemanticVersioningScheme) diff --git a/tests/version/commands/test_java.py b/tests/version/commands/test_java.py index ce82a9c09..4bd871193 100644 --- a/tests/version/commands/test_java.py +++ b/tests/version/commands/test_java.py @@ -128,9 +128,12 @@ def test_getting_version(self): def test_getting_version_no_files_configured(self): exp_err_msg = "no version found" - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): version_file_path = Path("upgradeVersion.json") version_file_path.write_text( @@ -147,9 +150,12 @@ def test_getting_version_without_version_config(self): r"No /tmp/.*/upgradeVersion\.json config file found\. " r"This file is required for pontos" ) - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): JavaVersionCommand(SemanticVersioningScheme).get_current_version() @@ -191,9 +197,12 @@ def test_verify_version_does_not_match(self): + r"in '/tmp/.*/upgradeVersion\.json'" ) - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): version_file_path = Path("upgradeVersion.json") version_file_path.write_text( @@ -350,9 +359,12 @@ def test_update_version_upgrade_config_with_wrong_line_number(self): "lineNo:4 " "content:'\n'" ) - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, - exp_err_msg, + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + VersionError, + exp_err_msg, + ), ): version_file_path = Path("upgradeVersion.json") version_file_path.write_text( diff --git a/tests/version/commands/test_javascript.py b/tests/version/commands/test_javascript.py index 4c4abd93b..4ebd7b567 100644 --- a/tests/version/commands/test_javascript.py +++ b/tests/version/commands/test_javascript.py @@ -26,25 +26,28 @@ def test_get_current_version(self): ) def test_no_project_file(self): - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, ".* file not found." + with ( + temp_directory(change_into=True), + self.assertRaisesRegex(VersionError, ".* file not found."), ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.get_current_version() def test_no_package_version(self): content = '{"name": "foo"}' - with temp_file( - content, name="package.json", change_into=True - ), self.assertRaisesRegex(VersionError, "Version field missing in"): + with ( + temp_file(content, name="package.json", change_into=True), + self.assertRaisesRegex(VersionError, "Version field missing in"), + ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.get_current_version() def test_no_valid_json_in_package_version(self): content = "{" - with temp_file( - content, name="package.json", change_into=True - ), self.assertRaisesRegex(VersionError, "No valid JSON found."): + with ( + temp_file(content, name="package.json", change_into=True), + self.assertRaisesRegex(VersionError, "No valid JSON found."), + ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.get_current_version() @@ -291,15 +294,18 @@ def test_forced_update(self): class VerifyJavaScriptVersionCommandTestCase(unittest.TestCase): def test_versions_not_equal(self): - with patch.object( - JavaScriptVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("1.2.3") + with ( + patch.object( + JavaScriptVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version("1.2.3") + ), + ), + self.assertRaisesRegex( + VersionError, + "Provided version .* does not match the current version .*", ), - ), self.assertRaisesRegex( - VersionError, - "Provided version .* does not match the current version .*", ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.verify_version(SemanticVersioningScheme.parse_version("22.4.0")) @@ -316,46 +322,60 @@ def test_verify_success(self): cmd.verify_version(SemanticVersioningScheme.parse_version("22.4.0")) def test_verify_js_mismatch(self): - with patch.object( - JavaScriptVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("22.4.0") + with ( + patch.object( + JavaScriptVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "22.4.0" + ) + ), ), - ), patch.object( - JavaScriptVersionCommand, - "_get_current_file_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("22.5.0") + patch.object( + JavaScriptVersionCommand, + "_get_current_file_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "22.5.0" + ) + ), + ), + self.assertRaisesRegex( + VersionError, + "Provided version 22.4.0 does not match the current version 22.5.0 " + "in src/version.js.", ), - ), self.assertRaisesRegex( - VersionError, - "Provided version 22.4.0 does not match the current version 22.5.0 " - "in src/version.js.", ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.verify_version(SemanticVersioningScheme.parse_version("22.4.0")) def test_verify_ts_mismatch(self): - with patch.object( - JavaScriptVersionCommand, - "get_current_version", - MagicMock( - return_value=SemanticVersioningScheme.parse_version("22.4.0") + with ( + patch.object( + JavaScriptVersionCommand, + "get_current_version", + MagicMock( + return_value=SemanticVersioningScheme.parse_version( + "22.4.0" + ) + ), ), - ), patch.object( - JavaScriptVersionCommand, - "_get_current_file_version", - MagicMock( - side_effect=[ - SemanticVersioningScheme.parse_version("22.4.0"), - SemanticVersioningScheme.parse_version("22.5.0"), - ] + patch.object( + JavaScriptVersionCommand, + "_get_current_file_version", + MagicMock( + side_effect=[ + SemanticVersioningScheme.parse_version("22.4.0"), + SemanticVersioningScheme.parse_version("22.5.0"), + ] + ), + ), + self.assertRaisesRegex( + VersionError, + "Provided version 22.4.0 does not match the current version 22.5.0 " + "in src/version.ts.", ), - ), self.assertRaisesRegex( - VersionError, - "Provided version 22.4.0 does not match the current version 22.5.0 " - "in src/version.ts.", ): cmd = JavaScriptVersionCommand(SemanticVersioningScheme) cmd.verify_version(SemanticVersioningScheme.parse_version("22.4.0")) @@ -407,12 +427,13 @@ def test_verify_current_js_mismatch(self): content = '{"name":"foo", "version":"1.2.3"}' js_content = 'const VERSION = "1.2.4";' - with temp_directory( - change_into=True - ) as temp_dir, self.assertRaisesRegex( - VersionError, - "The version 1.2.4 in src/version.js doesn't match the current " - "version 1.2.3.", + with ( + temp_directory(change_into=True) as temp_dir, + self.assertRaisesRegex( + VersionError, + "The version 1.2.4 in src/version.js doesn't match the current " + "version 1.2.3.", + ), ): package_json = temp_dir / "package.json" package_json.write_text(content, encoding="utf8") diff --git a/tests/version/commands/test_python.py b/tests/version/commands/test_python.py index d11bbea2b..7fad06cc0 100644 --- a/tests/version/commands/test_python.py +++ b/tests/version/commands/test_python.py @@ -22,23 +22,28 @@ class GetCurrentPythonVersionCommandTestCase(unittest.TestCase): def test_missing_tool_pontos_version_section(self): - with temp_file( - "[tool.pontos]", name="pyproject.toml", change_into=True - ), self.assertRaisesRegex( - VersionError, r"^\[tool\.pontos\.version\] section missing in .*\.$" + with ( + temp_file("[tool.pontos]", name="pyproject.toml", change_into=True), + self.assertRaisesRegex( + VersionError, + r"^\[tool\.pontos\.version\] section missing in .*\.$", + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.get_current_version() def test_missing_version_module_file_key(self): - with temp_file( - '[tool.pontos.version]\nname="foo"', - name="pyproject.toml", - change_into=True, - ), self.assertRaisesRegex( - VersionError, - r"^version-module-file key not set in \[tool\.pontos\.version\] " - r"section .*\.$", + with ( + temp_file( + '[tool.pontos.version]\nname="foo"', + name="pyproject.toml", + change_into=True, + ), + self.assertRaisesRegex( + VersionError, + r"^version-module-file key not set in \[tool\.pontos\.version\] " + r"section .*\.$", + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.get_current_version() @@ -56,19 +61,26 @@ def test_version_file_path(self): ) def test_pyproject_toml_file_not_exists(self): - with temp_directory(change_into=True), self.assertRaisesRegex( - VersionError, "pyproject.toml file not found." + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + VersionError, "pyproject.toml file not found." + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.get_current_version() def test_no_version_module(self): - with temp_file( - '[tool.pontos.version]\nversion-module-file = "foo.py"', - name="pyproject.toml", - change_into=True, - ), self.assertRaisesRegex( - VersionError, r"Could not load version from 'foo'\. .* not found." + with ( + temp_file( + '[tool.pontos.version]\nversion-module-file = "foo.py"', + name="pyproject.toml", + change_into=True, + ), + self.assertRaisesRegex( + VersionError, + r"Could not load version from 'foo'\. .* not found.", + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.get_current_version() @@ -139,22 +151,24 @@ def test_update_version_file(self): self.assertEqual(version_line, '__version__ = "22.2"') def test_empty_pyproject_toml(self): - with temp_file( - "", name="pyproject.toml", change_into=True - ), self.assertRaisesRegex( - VersionError, - r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.", + with ( + temp_file("", name="pyproject.toml", change_into=True), + self.assertRaisesRegex( + VersionError, + r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.", + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) new_version = PEP440VersioningScheme.parse_version("22.1.2") cmd.update_version(new_version) def test_empty_tool_section(self): - with temp_file( - "[tool]", name="pyproject.toml", change_into=True - ), self.assertRaisesRegex( - VersionError, - r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.", + with ( + temp_file("[tool]", name="pyproject.toml", change_into=True), + self.assertRaisesRegex( + VersionError, + r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.", + ), ): cmd = PythonVersionCommand(PEP440VersioningScheme) new_version = PEP440VersioningScheme.parse_version("22.1.2") @@ -284,19 +298,23 @@ def test_forced_updated(self): class VerifyVersionTestCase(unittest.TestCase): def test_current_version_not_equal_pyproject_toml_version(self): fake_version_py = Path("foo.py") - with patch.object( - PythonVersionCommand, - "get_current_version", - MagicMock( - return_value=PEP440VersioningScheme.parse_version("1.2.3") + with ( + patch.object( + PythonVersionCommand, + "get_current_version", + MagicMock( + return_value=PEP440VersioningScheme.parse_version("1.2.3") + ), + ), + patch.object( + PythonVersionCommand, + "version_file_path", + new=PropertyMock(return_value=fake_version_py), + ), + self.assertRaisesRegex( + VersionError, + "The version .* in .* doesn't match the current version .*.", ), - ), patch.object( - PythonVersionCommand, - "version_file_path", - new=PropertyMock(return_value=fake_version_py), - ), self.assertRaisesRegex( - VersionError, - "The version .* in .* doesn't match the current version .*.", ): cmd = PythonVersionCommand(PEP440VersioningScheme) version = PEP440VersioningScheme.parse_version("1.2.3") @@ -309,18 +327,20 @@ def test_current_version(self): '[tool.pontos.version]\nversion-module-file = "foo.py"' ) - with temp_file( - content, name="pyproject.toml", change_into=True - ), patch.object( - PythonVersionCommand, - "get_current_version", - MagicMock( - return_value=PEP440VersioningScheme.parse_version("1.2.3") + with ( + temp_file(content, name="pyproject.toml", change_into=True), + patch.object( + PythonVersionCommand, + "get_current_version", + MagicMock( + return_value=PEP440VersioningScheme.parse_version("1.2.3") + ), + ), + patch.object( + PythonVersionCommand, + "version_file_path", + new=PropertyMock(return_value=fake_version_py), ), - ), patch.object( - PythonVersionCommand, - "version_file_path", - new=PropertyMock(return_value=fake_version_py), ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.verify_version("current") @@ -332,21 +352,24 @@ def test_current_failure(self): '[tool.pontos.version]\nversion-module-file = "foo.py"' ) - with temp_file( - content, name="pyproject.toml", change_into=True - ), patch.object( - PythonVersionCommand, - "get_current_version", - MagicMock( - return_value=PEP440VersioningScheme.parse_version("1.2.3") + with ( + temp_file(content, name="pyproject.toml", change_into=True), + patch.object( + PythonVersionCommand, + "get_current_version", + MagicMock( + return_value=PEP440VersioningScheme.parse_version("1.2.3") + ), + ), + patch.object( + PythonVersionCommand, + "version_file_path", + new=PropertyMock(return_value=fake_version_py), + ), + self.assertRaisesRegex( + VersionError, + "The version .* in .* doesn't match the current version .*.", ), - ), patch.object( - PythonVersionCommand, - "version_file_path", - new=PropertyMock(return_value=fake_version_py), - ), self.assertRaisesRegex( - VersionError, - "The version .* in .* doesn't match the current version .*.", ): cmd = PythonVersionCommand(PEP440VersioningScheme) cmd.verify_version("current") @@ -358,18 +381,20 @@ def test_provided_version_mismatch(self): '[tool.pontos.version]\nversion-module-file = "foo.py"' ) - with temp_file( - content, name="pyproject.toml", change_into=True - ), patch.object( - PythonVersionCommand, - "get_current_version", - MagicMock( - return_value=PEP440VersioningScheme.parse_version("1.2.3") + with ( + temp_file(content, name="pyproject.toml", change_into=True), + patch.object( + PythonVersionCommand, + "get_current_version", + MagicMock( + return_value=PEP440VersioningScheme.parse_version("1.2.3") + ), + ), + patch.object( + PythonVersionCommand, + "version_file_path", + new=PropertyMock(return_value=fake_version_py), ), - ), patch.object( - PythonVersionCommand, - "version_file_path", - new=PropertyMock(return_value=fake_version_py), ): with self.assertRaisesRegex( VersionError, @@ -386,18 +411,20 @@ def test_verify_success(self): '[tool.pontos.version]\nversion-module-file = "foo.py"' ) - with temp_file( - content, name="pyproject.toml", change_into=True - ), patch.object( - PythonVersionCommand, - "get_current_version", - MagicMock( - return_value=PEP440VersioningScheme.parse_version("1.2.3") + with ( + temp_file(content, name="pyproject.toml", change_into=True), + patch.object( + PythonVersionCommand, + "get_current_version", + MagicMock( + return_value=PEP440VersioningScheme.parse_version("1.2.3") + ), + ), + patch.object( + PythonVersionCommand, + "version_file_path", + new=PropertyMock(return_value=fake_version_py), ), - ), patch.object( - PythonVersionCommand, - "version_file_path", - new=PropertyMock(return_value=fake_version_py), ): cmd = PythonVersionCommand(PEP440VersioningScheme) version = PEP440VersioningScheme.parse_version("1.2.3") diff --git a/tests/version/test_main.py b/tests/version/test_main.py index 8b7ecb00f..756abe95c 100644 --- a/tests/version/test_main.py +++ b/tests/version/test_main.py @@ -18,17 +18,21 @@ def test_no_command(self): main([]) def test_no_project(self): - with temp_directory(change_into=True), self.assertRaises( - SystemExit - ) as cm, redirect_stderr(StringIO()): + with ( + temp_directory(change_into=True), + self.assertRaises(SystemExit) as cm, + redirect_stderr(StringIO()), + ): main(["show"]) self.assertEqual(cm.exception.code, VersionExitCode.NO_PROJECT) def test_update_success(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -43,9 +47,11 @@ def test_update_success(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) def test_update_failure(self): - with temp_directory(change_into=True) as temp_dir, redirect_stderr( - StringIO() - ), self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stderr(StringIO()), + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( "{}", @@ -56,9 +62,11 @@ def test_update_failure(self): self.assertEqual(cm.exception.code, VersionExitCode.UPDATE_ERROR) def test_update_already_up_to_date(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -71,9 +79,11 @@ def test_update_already_up_to_date(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) def test_show(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -86,9 +96,11 @@ def test_show(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) def test_show_error(self): - with temp_directory(change_into=True) as temp_dir, redirect_stderr( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stderr(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "abc"}', @@ -103,9 +115,11 @@ def test_show_error(self): ) def test_verify_failure(self): - with temp_directory(change_into=True) as temp_dir, redirect_stderr( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stderr(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -122,9 +136,10 @@ def test_verify_failure(self): self.assertEqual(cm.exception.code, VersionExitCode.VERIFY_ERROR) def test_verify_success(self): - with temp_directory(change_into=True) as temp_dir, self.assertRaises( - SystemExit - ) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -135,9 +150,10 @@ def test_verify_success(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) def test_verify_current(self): - with temp_directory(change_into=True) as temp_dir, self.assertRaises( - SystemExit - ) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -148,9 +164,11 @@ def test_verify_current(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) def test_next_invalid_current(self): - with redirect_stderr(StringIO()), temp_directory( - change_into=True - ) as temp_dir, self.assertRaises(SystemExit) as cm: + with ( + redirect_stderr(StringIO()), + temp_directory(change_into=True) as temp_dir, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.tt"}', @@ -163,9 +181,11 @@ def test_next_invalid_current(self): ) def test_next_dev(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -177,9 +197,11 @@ def test_next_dev(self): self.assertEqual(out.getvalue(), "1.2.4.dev1\n") def test_next_patch(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -191,9 +213,11 @@ def test_next_patch(self): self.assertEqual(out.getvalue(), "1.2.4\n") def test_next_minor(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -205,9 +229,11 @@ def test_next_minor(self): self.assertEqual(out.getvalue(), "1.3.0\n") def test_next_major(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -219,9 +245,11 @@ def test_next_major(self): self.assertEqual(out.getvalue(), "2.0.0\n") def test_next_alpha(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -233,9 +261,11 @@ def test_next_alpha(self): self.assertEqual(out.getvalue(), "1.2.4-alpha1\n") def test_next_beta(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -247,9 +277,11 @@ def test_next_beta(self): self.assertEqual(out.getvalue(), "1.2.4-beta1\n") def test_next_rc(self): - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', @@ -262,9 +294,11 @@ def test_next_rc(self): def test_next_calendar(self): today = datetime.today() - with temp_directory(change_into=True) as temp_dir, redirect_stdout( - StringIO() - ) as out, self.assertRaises(SystemExit) as cm: + with ( + temp_directory(change_into=True) as temp_dir, + redirect_stdout(StringIO()) as out, + self.assertRaises(SystemExit) as cm, + ): version_file = temp_dir / "package.json" version_file.write_text( '{"name": "foo", "version": "1.2.3"}', diff --git a/tests/version/test_project.py b/tests/version/test_project.py index 54c17c76e..4d68bfa92 100644 --- a/tests/version/test_project.py +++ b/tests/version/test_project.py @@ -12,8 +12,11 @@ class ProjectTestCase(unittest.TestCase): def test_no_project_found(self): - with temp_directory(change_into=True), self.assertRaisesRegex( - ProjectError, "No project settings file found" + with ( + temp_directory(change_into=True), + self.assertRaisesRegex( + ProjectError, "No project settings file found" + ), ): Project(PEP440VersioningScheme)