terraformDummyRepo/test/test_version_class.py

124 lines
No EOL
3.6 KiB
Python

from pathlib import Path
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
# now we can import the module in the parent
# directory.
from version import Version
from version_repository import VersionRepository
from release_type import ReleaseType
def test_version():
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
version.increment(ReleaseType.SNAPSHOT)
assert version.get_version_string() == "1.2.3-SNAPSHOT"
assert version.version_list == [1, 2, 3]
assert version.is_snapshot
version.increment(ReleaseType.BUMP)
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]
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)
assert version.get_version_string() == "1.3.0"
version.increment(ReleaseType.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_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()