Add basic tests for version increment
This commit is contained in:
parent
1995a7b200
commit
4a34763fb2
2 changed files with 40 additions and 8 deletions
|
@ -4,8 +4,7 @@ import re
|
|||
|
||||
def init_project():
|
||||
# validate_values()
|
||||
version = Version('build.gradle')
|
||||
version.parse()
|
||||
version = Version.from_file('build.gradle')
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version.write()
|
||||
|
||||
|
@ -23,11 +22,17 @@ class ReleaseLevel(Enum):
|
|||
|
||||
class Version():
|
||||
|
||||
def __init__(self, config_file_path):
|
||||
self.version = []
|
||||
self.is_snapshot = False
|
||||
self.config_file_path = config_file_path
|
||||
self.config_file_type = config_file_path.split('.')[-1]
|
||||
def __init__(self, version, is_snapshot):
|
||||
self.version = version
|
||||
self.is_snapshot = is_snapshot
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, config_file_path):
|
||||
ret_cls = cls(None, False)
|
||||
ret_cls.config_file_path = config_file_path
|
||||
ret_cls.config_file_type = config_file_path.split('.')[-1]
|
||||
ret_cls.parse()
|
||||
return ret_cls
|
||||
|
||||
def parse(self):
|
||||
match self.config_file_type:
|
||||
|
@ -35,6 +40,8 @@ class Version():
|
|||
self.__parse_json()
|
||||
case 'gradle':
|
||||
self.__parse_gradle()
|
||||
case _:
|
||||
raise Exception(f'The file type "{self.config_file_type}" is not implemented')
|
||||
|
||||
def __parse_json(self):
|
||||
with open(self.config_file_path, 'r') as json_file:
|
||||
|
@ -51,7 +58,7 @@ class Version():
|
|||
if version_line is None:
|
||||
raise Exception("Version not found in gradle file")
|
||||
version_line = version_line.group()
|
||||
version_string = re.search('[0-9]*\.[0-9]*\.[0-9]*(-SNAPSHOT)?', version_line)
|
||||
version_string = re.search('[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line)
|
||||
if version_string is None:
|
||||
raise Exception("Version not found in gradle file")
|
||||
|
||||
|
|
25
test/test_version.py
Normal file
25
test/test_version.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from devops_test import Version, ReleaseLevel
|
||||
|
||||
def test_version():
|
||||
version = Version([1, 2, 3], False)
|
||||
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.3-SNAPSHOT"
|
||||
assert version.version == [1, 2, 3]
|
||||
assert version.is_snapshot
|
||||
|
||||
version.increment(ReleaseLevel.PATCH)
|
||||
assert version.get() == "1.2.4"
|
||||
assert version.version == [1, 2, 4]
|
||||
assert not version.is_snapshot
|
||||
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.4-SNAPSHOT"
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.4-SNAPSHOT"
|
||||
|
||||
version.increment(ReleaseLevel.MINOR)
|
||||
assert version.get() == "1.3.0"
|
||||
|
||||
version.increment(ReleaseLevel.MAJOR)
|
||||
assert version.get() == "2.0.0"
|
Loading…
Reference in a new issue