Fix bugs and tests

This commit is contained in:
erik 2023-02-21 16:14:47 +01:00
parent 6883435248
commit 94b993ccf5
3 changed files with 45 additions and 41 deletions

View file

@ -24,31 +24,34 @@ from release_type import ReleaseType
def test_version():
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
version.increment(ReleaseType.SNAPSHOT)
version.increment()
assert version.get_version_string() == "1.2.3-SNAPSHOT"
assert version.version_list == [1, 2, 3]
assert version.is_snapshot
version.increment(ReleaseType.BUMP)
version = Version([1, 2, 3], ReleaseType.BUMP)
version.increment()
assert version.get_version_string() == "1.2.4-SNAPSHOT"
assert version.version_list == [1, 2, 4]
assert version.is_snapshot
version.increment(ReleaseType.PATCH)
assert version.get_version_string() == "1.2.5"
assert version.version_list == [1, 2, 5]
version = Version([1, 2, 3], ReleaseType.PATCH)
version.increment()
assert version.get_version_string() == "1.2.4"
assert version.version_list == [1, 2, 4]
assert not version.is_snapshot
version.increment(ReleaseType.SNAPSHOT)
assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseType.SNAPSHOT)
assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseType.MINOR)
version = Version([1, 2, 3], ReleaseType.MINOR)
version.increment()
assert version.get_version_string() == "1.3.0"
assert version.version_list == [1, 3, 0]
assert not version.is_snapshot
version.increment(ReleaseType.MAJOR)
version = Version([1, 2, 3], ReleaseType.MAJOR)
version.increment()
assert version.get_version_string() == "2.0.0"
assert version.version_list == [2, 0, 0]
assert not version.is_snapshot
def test_gradle(tmp_path):
@ -61,10 +64,10 @@ def test_gradle(tmp_path):
f.write_text(contents)
# test
version_repo = VersionRepository.get(f)
version_list = version_repo.version_list
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string())
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version()
repo.write_file(version.get_version_string())
# check
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
@ -79,10 +82,10 @@ def test_json(tmp_path):
f.write_text(contents)
# test
version_repo = VersionRepository.get(f)
version_list = version_repo.version_list
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string())
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version()
repo.write_file(version.get_version_string())
# check
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
@ -97,10 +100,10 @@ def test_clojure(tmp_path):
f.write_text(contents)
# test
version_repo = VersionRepository.get(f)
version_list = version_repo.version_list
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string())
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version()
repo.write_file(version.get_version_string())
# check
assert '1.1.3-SNAPSHOT' in f.read_text()
@ -115,10 +118,10 @@ def test_python(tmp_path):
f.write_text(contents)
# test
version_repo = VersionRepository.get(f)
version_list = version_repo.version_list
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string())
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version.create_release_version()
repo.write_file(version.get_version_string())
# check
assert '3.1.3-SNAPSHOT' in f.read_text()

View file

@ -7,7 +7,7 @@ class Version():
self.version_list = version_list
self.release_type = release_type
self.version_string = None
self.is_snapshot = is_snapshot
self.is_snapshot = None
def increment(self):
self.is_snapshot = False
@ -26,7 +26,7 @@ class Version():
self.version_list[ReleaseType.PATCH.value] = 0
self.version_list[ReleaseType.MINOR.value] = 0
self.version_list[ReleaseType.MAJOR.value] += 1
case None
case None:
raise Exception("Release Type was not set!")
def get_version_string(self) -> str:
@ -39,7 +39,7 @@ class Version():
if self.release_type == ReleaseType.PATCH:
self.is_snapshot = False
else:
self.increment(release_type)
self.increment()
def create_bump_version(self):
self.increment(ReleaseType.BUMP)

View file

@ -9,23 +9,24 @@ class VersionRepository():
def load_file(self):
self.file_handler = FileHandler.from_file_path(self.file)
return file_handler
return self.file_handler
def write_file(self, version_string):
if self.file_handler is None:
raise Exception('Version was not created by load_file method.')
if self.version_list is None or self.is_snapshot is None:
raise Exception('Version or is_snapshot attribute not set.')
else:
self.file_handler.write(version_string)
def parse_file(self, file_handler):
version_list, is_snapshot = file_handler.parse()
def parse_file(self):
version_list, is_snapshot = self.file_handler.parse()
return version_list, is_snapshot
def get_version(self, release_type):
self.file_handler = self.load_file(self.file)
version_list, is_snapshot = self.parse_file(file_handler)
self.file_handler = self.load_file()
version_list, is_snapshot = self.parse_file()
version = Version(version_list, release_type)
version.is_snapshot = is_snapshot
return version
return Version(version_list, release_type)