Compare commits

...

4 commits

Author SHA1 Message Date
e9301dedd1 Readd tests for python, clojure and json 2023-02-21 10:17:16 +01:00
bb17017583 readd release type argument 2023-02-21 10:08:04 +01:00
ea45671bea Fix version and gradle test 2023-02-21 10:07:30 +01:00
1dc5a1e9e8 WIP Fix returns and function calls 2023-02-21 09:55:03 +01:00
3 changed files with 62 additions and 6 deletions

View file

@ -22,7 +22,7 @@ from version_repository import VersionRepository
from release_type import ReleaseType
def test_version():
version = Version([1, 2, 3])
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
version.increment(ReleaseType.SNAPSHOT)
assert version.get_version_string() == "1.2.3-SNAPSHOT"
@ -62,8 +62,63 @@ def test_gradle(tmp_path):
# test
version_repo = VersionRepository.get(f)
version = Version.create_release_version(ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string)
version_list = version_repo.version_list
version = Version.create_release_version(version_list, ReleaseType.SNAPSHOT)
version_repo.write_file(version.get_version_string())
# check
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
def test_json(tmp_path):
# init
file_name = 'config.json'
with open(f'test/resources/{file_name}', 'r') as gradle_file:
contents = gradle_file.read()
f = tmp_path / file_name
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())
# check
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
def test_clojure(tmp_path):
# init
file_name = 'config.clj'
with open(f'test/resources/{file_name}', 'r') as gradle_file:
contents = gradle_file.read()
f = tmp_path / file_name
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())
# check
assert '1.1.3-SNAPSHOT' in f.read_text()
def test_python(tmp_path):
# init
file_name = 'config.py'
with open(f'test/resources/{file_name}', 'r') as gradle_file:
contents = gradle_file.read()
f = tmp_path / file_name
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())
# check
assert '3.1.3-SNAPSHOT' in f.read_text()

View file

@ -3,8 +3,9 @@ from file_handlers import FileHandler
class Version():
def __init__(self, version_list: list):
def __init__(self, version_list: list, release_type: ReleaseType):
self.version_list = version_list
self.release_type = release_type
self.version_string = None
self.is_snapshot = None

View file

@ -10,7 +10,7 @@ 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:
@ -28,7 +28,7 @@ class VersionRepository():
def get(cls, file):
inst = cls(file)
file_handler= inst.load_file(file)
file_handler = inst.load_file()
version_list, is_snapshot = inst.parse_file(file_handler)
inst.version_list = version_list