Skip to content

Commit

Permalink
Remove try block, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Mar 14, 2023
1 parent f89097a commit 99a92b0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
38 changes: 16 additions & 22 deletions pontos/version/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
43 changes: 43 additions & 0 deletions tests/version/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 99a92b0

Please sign in to comment.