diff --git a/pontos/version/main.py b/pontos/version/main.py index 446cc5d55..2b545a454 100644 --- a/pontos/version/main.py +++ b/pontos/version/main.py @@ -79,27 +79,21 @@ def main(args: Optional[List[str]] = None) -> NoReturn: print(str(e), file=sys.stderr) sys.exit(VersionExitCode.CURRENT_VERSION_ERROR) - try: - if parsed_args.type == "dev": - print(calculator.next_dev_version(current_version)) - elif parsed_args.type == "calendar": - print(calculator.next_calendar_version(current_version)) - elif parsed_args.type == "alpha": - print(calculator.next_alpha_version(current_version)) - elif parsed_args.type == "beta": - print(calculator.next_beta_version(current_version)) - elif parsed_args.type == "rc": - print( - calculator.next_release_candidate_version(current_version) - ) - elif parsed_args.type == "patch": - print(calculator.next_patch_version(current_version)) - elif parsed_args.type == "minor": - print(calculator.next_minor_version(current_version)) - elif parsed_args.type == "major": - print(calculator.next_major_version(current_version)) - except PontosError as e: - print(str(e), file=sys.stderr) - sys.exit(VersionExitCode.NEXT_VERSION_ERROR) + if parsed_args.type == "dev": + print(calculator.next_dev_version(current_version)) + elif parsed_args.type == "calendar": + print(calculator.next_calendar_version(current_version)) + elif parsed_args.type == "alpha": + print(calculator.next_alpha_version(current_version)) + elif parsed_args.type == "beta": + print(calculator.next_beta_version(current_version)) + elif parsed_args.type == "rc": + print(calculator.next_release_candidate_version(current_version)) + elif parsed_args.type == "patch": + print(calculator.next_patch_version(current_version)) + elif parsed_args.type == "minor": + print(calculator.next_minor_version(current_version)) + elif parsed_args.type == "major": + print(calculator.next_major_version(current_version)) sys.exit(VersionExitCode.SUCCESS) diff --git a/tests/version/test_main.py b/tests/version/test_main.py index 1ab097006..9e4b18b3b 100644 --- a/tests/version/test_main.py +++ b/tests/version/test_main.py @@ -159,6 +159,21 @@ def test_verify_current(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) + def test_next_invalid_current(self): + 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.tt"}', + encoding="utf8", + ) + main(["next", "dev", "--versioning-scheme", "pep440"]) + + self.assertEqual( + cm.exception.code, VersionExitCode.CURRENT_VERSION_ERROR + ) + def test_next_dev(self): with temp_directory(change_into=True) as temp_dir, redirect_stdout( StringIO() @@ -229,6 +244,34 @@ def test_next_alpha(self): self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) 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: + version_file = temp_dir / "package.json" + version_file.write_text( + '{"name": "foo", "version": "1.2.3"}', + encoding="utf8", + ) + main(["next", "beta", "--versioning-scheme", "semver"]) + + self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) + 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: + version_file = temp_dir / "package.json" + version_file.write_text( + '{"name": "foo", "version": "1.2.3"}', + encoding="utf8", + ) + main(["next", "rc", "--versioning-scheme", "semver"]) + + self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS) + self.assertEqual(out.getvalue(), "1.2.4-rc1\n") + def test_next_calendar(self): today = datetime.today() with temp_directory(change_into=True) as temp_dir, redirect_stdout(