dda-devops-build/test/test_version_class.py
2023-02-20 16:37:49 +01:00

51 lines
1.6 KiB
Python

from version import Version
from version_repository import VersionRepository
from release_type import ReleaseType
from pathlib import Path
def test_version():
version = Version([1, 2, 3], False)
version.increment(ReleaseLevel.SNAPSHOT)
assert version.get_version_string() == "1.2.3-SNAPSHOT"
assert version.version == [1, 2, 3]
assert version.is_snapshot
version.increment(ReleaseLevel.BUMP)
assert version.get_version_string() == "1.2.4-SNAPSHOT"
assert version.version == [1, 2, 4]
assert not version.is_snapshot
version.increment(ReleaseLevel.PATCH)
assert version.get_version_string() == "1.2.5"
assert version.version == [1, 2, 4]
assert not version.is_snapshot
version.increment(ReleaseLevel.SNAPSHOT)
assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseLevel.SNAPSHOT)
assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseLevel.MINOR)
assert version.get_version_string() == "1.3.0"
version.increment(ReleaseLevel.MAJOR)
assert version.get_version_string() == "2.0.0"
def test_gradle(tmp_path):
# init
file_name = 'config.gradle'
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 = Version.create_release_version(ReleaseLevel.SNAPSHOT)
version_repo.write_file(version.get_version_string)
# check
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()