From 1ce4bd9c55c2d888665dc9c05fc9df931f3ded80 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 23 Feb 2023 14:38:54 +0100 Subject: [PATCH] Remove release_type as requirement for Version Require it in functions that actually use it instead --- services.py | 15 +++++++-------- test/test_version_class.py | 36 ++++++++++++++++++------------------ version.py | 17 ++++++++--------- version_repository.py | 4 ++-- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/services.py b/services.py index 36c2ff1..212f016 100644 --- a/services.py +++ b/services.py @@ -5,7 +5,7 @@ from version import Version class InitReleaseService(): - def __init__(self, version_repo: VersionRepository): + def __init__(self, version_repo: VersionRepository): if version_repo is None: raise Exception('VersionRepo was not created. Did you run create_release_version()?') self.version_repo = version_repo @@ -16,25 +16,24 @@ class InitReleaseService(): else: return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit() - def get_version(self, release_type): - return self.version_repo.get_version(release_type) + def get_version(self): + return self.version_repo.get_version() def create_release_version(self, commit_string = None): release_type = self.__calculate_release_type(commit_string) - version = self.get_version(release_type).create_release_version() + version = self.get_version().create_release_version(release_type) return version - def create_bump_version(self): - version = self.get_version(ReleaseType.BUMP).create_bump_version() + def create_bump_version(self): + version = self.get_version().create_bump_version() return version - class PrepareReleaseService(): def __init__(self, version_repo: VersionRepository): self.version_repo = version_repo - + def run_tests(self): # maybe auto? pass diff --git a/test/test_version_class.py b/test/test_version_class.py index 24c9d33..4f1ac6b 100644 --- a/test/test_version_class.py +++ b/test/test_version_class.py @@ -22,33 +22,33 @@ from version_repository import VersionRepository from release_type import ReleaseType def test_version(): - version = Version([1, 2, 3], ReleaseType.SNAPSHOT) + version = Version([1, 2, 3]) - version.increment() + version.increment(ReleaseType.SNAPSHOT) assert version.get_version_string() == "1.2.3-SNAPSHOT" assert version.version_list == [1, 2, 3] assert version.is_snapshot - version = Version([1, 2, 3], ReleaseType.BUMP) - version.increment() + version = Version([1, 2, 3]) + version.increment(ReleaseType.BUMP) assert version.get_version_string() == "1.2.4-SNAPSHOT" assert version.version_list == [1, 2, 4] assert version.is_snapshot - version = Version([1, 2, 3], ReleaseType.PATCH) - version.increment() + version = Version([1, 2, 3]) + version.increment(ReleaseType.PATCH) assert version.get_version_string() == "1.2.4" assert version.version_list == [1, 2, 4] assert not version.is_snapshot - version = Version([1, 2, 3], ReleaseType.MINOR) - version.increment() + version = Version([1, 2, 3]) + version.increment(ReleaseType.MINOR) assert version.get_version_string() == "1.3.0" assert version.version_list == [1, 3, 0] assert not version.is_snapshot - version = Version([1, 2, 3], ReleaseType.MAJOR) - version.increment() + version = Version([1, 2, 3]) + version.increment(ReleaseType.MAJOR) assert version.get_version_string() == "2.0.0" assert version.version_list == [2, 0, 0] assert not version.is_snapshot @@ -65,8 +65,8 @@ def test_gradle(tmp_path): # test repo = VersionRepository(f) - version = repo.get_version(ReleaseType.SNAPSHOT) - version = version.create_release_version() + version = repo.get_version() + version = version.create_release_version(ReleaseType.SNAPSHOT) repo.write_file(version.get_version_string()) # check @@ -83,8 +83,8 @@ def test_json(tmp_path): # test repo = VersionRepository(f) - version = repo.get_version(ReleaseType.SNAPSHOT) - version = version.create_release_version() + version = repo.get_version() + version = version.create_release_version(ReleaseType.SNAPSHOT) repo.write_file(version.get_version_string()) # check @@ -101,8 +101,8 @@ def test_clojure(tmp_path): # test repo = VersionRepository(f) - version = repo.get_version(ReleaseType.SNAPSHOT) - version = version.create_release_version() + version = repo.get_version() + version = version.create_release_version(ReleaseType.SNAPSHOT) repo.write_file(version.get_version_string()) # check @@ -119,8 +119,8 @@ def test_python(tmp_path): # test repo = VersionRepository(f) - version = repo.get_version(ReleaseType.SNAPSHOT) - version = version.create_release_version() + version = repo.get_version() + version = version.create_release_version(ReleaseType.SNAPSHOT) repo.write_file(version.get_version_string()) # check diff --git a/version.py b/version.py index 7dea4f7..3cfca62 100644 --- a/version.py +++ b/version.py @@ -3,15 +3,14 @@ from file_handlers import FileHandler class Version(): - def __init__(self, version_list: list, release_type: ReleaseType): + def __init__(self, version_list: list): self.version_list = version_list - self.release_type = release_type self.version_string = None self.is_snapshot = None - def increment(self): + def increment(self, release_type: ReleaseType): self.is_snapshot = False - match self.release_type: + match release_type: case ReleaseType.BUMP: self.is_snapshot = True self.version_list[ReleaseType.PATCH.value] += 1 @@ -35,14 +34,14 @@ class Version(): self.version_string += "-SNAPSHOT" return self.version_string - def create_release_version(self): - release_version = Version(self.version_list.copy(), self.release_type) + def create_release_version(self, release_type: ReleaseType): + release_version = Version(self.version_list.copy()) release_version.is_snapshot = self.is_snapshot - release_version.increment() + release_version.increment(release_type) return release_version def create_bump_version(self): - bump_version = Version(self.version_list.copy(), ReleaseType.BUMP) + bump_version = Version(self.version_list.copy()) bump_version.is_snapshot = self.is_snapshot - bump_version.increment() + bump_version.increment(ReleaseType.BUMP) return bump_version diff --git a/version_repository.py b/version_repository.py index b135b79..2c3ec63 100644 --- a/version_repository.py +++ b/version_repository.py @@ -21,11 +21,11 @@ class VersionRepository(): version_list, is_snapshot = self.file_handler.parse() return version_list, is_snapshot - def get_version(self, release_type): + def get_version(self): self.file_handler = self.load_file() version_list, is_snapshot = self.parse_file() - version = Version(version_list, release_type) + version = Version(version_list) version.is_snapshot = is_snapshot return version