Fix bugs and tests
This commit is contained in:
parent
6883435248
commit
94b993ccf5
3 changed files with 45 additions and 41 deletions
|
@ -24,31 +24,34 @@ from release_type import ReleaseType
|
||||||
def test_version():
|
def test_version():
|
||||||
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
|
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
|
||||||
|
|
||||||
version.increment(ReleaseType.SNAPSHOT)
|
version.increment()
|
||||||
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
||||||
assert version.version_list == [1, 2, 3]
|
assert version.version_list == [1, 2, 3]
|
||||||
assert version.is_snapshot
|
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.get_version_string() == "1.2.4-SNAPSHOT"
|
||||||
assert version.version_list == [1, 2, 4]
|
assert version.version_list == [1, 2, 4]
|
||||||
assert version.is_snapshot
|
assert version.is_snapshot
|
||||||
|
|
||||||
version.increment(ReleaseType.PATCH)
|
version = Version([1, 2, 3], ReleaseType.PATCH)
|
||||||
assert version.get_version_string() == "1.2.5"
|
version.increment()
|
||||||
assert version.version_list == [1, 2, 5]
|
assert version.get_version_string() == "1.2.4"
|
||||||
|
assert version.version_list == [1, 2, 4]
|
||||||
assert not version.is_snapshot
|
assert not version.is_snapshot
|
||||||
|
|
||||||
version.increment(ReleaseType.SNAPSHOT)
|
version = Version([1, 2, 3], ReleaseType.MINOR)
|
||||||
assert version.get_version_string() == "1.2.5-SNAPSHOT"
|
version.increment()
|
||||||
version.increment(ReleaseType.SNAPSHOT)
|
|
||||||
assert version.get_version_string() == "1.2.5-SNAPSHOT"
|
|
||||||
|
|
||||||
version.increment(ReleaseType.MINOR)
|
|
||||||
assert version.get_version_string() == "1.3.0"
|
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.get_version_string() == "2.0.0"
|
||||||
|
assert version.version_list == [2, 0, 0]
|
||||||
|
assert not version.is_snapshot
|
||||||
|
|
||||||
|
|
||||||
def test_gradle(tmp_path):
|
def test_gradle(tmp_path):
|
||||||
|
@ -61,10 +64,10 @@ def test_gradle(tmp_path):
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
version_repo = VersionRepository.get(f)
|
repo = VersionRepository(f)
|
||||||
version_list = version_repo.version_list
|
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||||
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
|
version.create_release_version()
|
||||||
version_repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
|
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
|
||||||
|
@ -79,10 +82,10 @@ def test_json(tmp_path):
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
version_repo = VersionRepository.get(f)
|
repo = VersionRepository(f)
|
||||||
version_list = version_repo.version_list
|
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||||
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
|
version.create_release_version()
|
||||||
version_repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
||||||
|
@ -97,10 +100,10 @@ def test_clojure(tmp_path):
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
version_repo = VersionRepository.get(f)
|
repo = VersionRepository(f)
|
||||||
version_list = version_repo.version_list
|
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||||
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
|
version.create_release_version()
|
||||||
version_repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
assert '1.1.3-SNAPSHOT' in f.read_text()
|
assert '1.1.3-SNAPSHOT' in f.read_text()
|
||||||
|
@ -115,10 +118,10 @@ def test_python(tmp_path):
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
version_repo = VersionRepository.get(f)
|
repo = VersionRepository(f)
|
||||||
version_list = version_repo.version_list
|
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||||
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
|
version.create_release_version()
|
||||||
version_repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
assert '3.1.3-SNAPSHOT' in f.read_text()
|
assert '3.1.3-SNAPSHOT' in f.read_text()
|
|
@ -7,7 +7,7 @@ class Version():
|
||||||
self.version_list = version_list
|
self.version_list = version_list
|
||||||
self.release_type = release_type
|
self.release_type = release_type
|
||||||
self.version_string = None
|
self.version_string = None
|
||||||
self.is_snapshot = is_snapshot
|
self.is_snapshot = None
|
||||||
|
|
||||||
def increment(self):
|
def increment(self):
|
||||||
self.is_snapshot = False
|
self.is_snapshot = False
|
||||||
|
@ -26,7 +26,7 @@ class Version():
|
||||||
self.version_list[ReleaseType.PATCH.value] = 0
|
self.version_list[ReleaseType.PATCH.value] = 0
|
||||||
self.version_list[ReleaseType.MINOR.value] = 0
|
self.version_list[ReleaseType.MINOR.value] = 0
|
||||||
self.version_list[ReleaseType.MAJOR.value] += 1
|
self.version_list[ReleaseType.MAJOR.value] += 1
|
||||||
case None
|
case None:
|
||||||
raise Exception("Release Type was not set!")
|
raise Exception("Release Type was not set!")
|
||||||
|
|
||||||
def get_version_string(self) -> str:
|
def get_version_string(self) -> str:
|
||||||
|
@ -39,7 +39,7 @@ class Version():
|
||||||
if self.release_type == ReleaseType.PATCH:
|
if self.release_type == ReleaseType.PATCH:
|
||||||
self.is_snapshot = False
|
self.is_snapshot = False
|
||||||
else:
|
else:
|
||||||
self.increment(release_type)
|
self.increment()
|
||||||
|
|
||||||
def create_bump_version(self):
|
def create_bump_version(self):
|
||||||
self.increment(ReleaseType.BUMP)
|
self.increment(ReleaseType.BUMP)
|
||||||
|
|
|
@ -9,23 +9,24 @@ class VersionRepository():
|
||||||
|
|
||||||
def load_file(self):
|
def load_file(self):
|
||||||
self.file_handler = FileHandler.from_file_path(self.file)
|
self.file_handler = FileHandler.from_file_path(self.file)
|
||||||
return file_handler
|
return self.file_handler
|
||||||
|
|
||||||
def write_file(self, version_string):
|
def write_file(self, version_string):
|
||||||
if self.file_handler is None:
|
if self.file_handler is None:
|
||||||
raise Exception('Version was not created by load_file method.')
|
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:
|
else:
|
||||||
self.file_handler.write(version_string)
|
self.file_handler.write(version_string)
|
||||||
|
|
||||||
def parse_file(self, file_handler):
|
def parse_file(self):
|
||||||
version_list, is_snapshot = file_handler.parse()
|
version_list, is_snapshot = self.file_handler.parse()
|
||||||
return version_list, is_snapshot
|
return version_list, is_snapshot
|
||||||
|
|
||||||
def get_version(self, release_type):
|
def get_version(self, release_type):
|
||||||
|
|
||||||
self.file_handler = self.load_file(self.file)
|
self.file_handler = self.load_file()
|
||||||
version_list, is_snapshot = self.parse_file(file_handler)
|
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)
|
|
||||||
|
|
Loading…
Reference in a new issue