def test_next_prerelease_invalid(): version = Version("1.1.1") with pytest.raises(TypeError): version.next_alpha("stuff") with pytest.raises(TypeError): version.next_beta("stuff") with pytest.raises(TypeError): version.next_release_candidate("stuff")
def ask_version() -> Text: """Allow the user to confirm the version number.""" def is_valid_version_number(v: Text) -> bool: return v in {"major", "minor", "micro", "alpha", "rc" } or is_valid_version(v) current_version = Version(get_current_version()) next_micro_version = str(current_version.next_micro()) next_alpha_version = str(current_version.next_alpha()) version = questionary.text( f"What is the version number you want to release " f"('major', 'minor', 'micro', 'alpha', 'rc' or valid version number " f"e.g. '{next_micro_version}' or '{next_alpha_version}')?", validate=is_valid_version_number, ).ask() if version in PRERELEASE_FLAVORS and not current_version.pre: # at this stage it's hard to guess the kind of version bump the # releaser wants, so we ask them if version == "alpha": choices = [ str(current_version.next_alpha("minor")), str(current_version.next_alpha("micro")), str(current_version.next_alpha("major")), ] else: choices = [ str(current_version.next_release_candidate("minor")), str(current_version.next_release_candidate("micro")), str(current_version.next_release_candidate("major")), ] version = questionary.select( f"Which {version} do you want to release?", choices=choices, ).ask() if version: return version else: print("Aborting.") sys.exit(1)
def test_next_alpha(version_string, version_bump, expected): version = Version(version_string) next_version = version.next_alpha(version_bump) assert isinstance(next_version, Version) assert next_version > version assert str(next_version) == expected