terraformDummyRepo/test/test_version_class.py

70 lines
2 KiB
Python
Raw Normal View History

2023-02-20 15:45:36 +00:00
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.
2023-02-20 15:37:49 +00:00
from version import Version
from version_repository import VersionRepository
2023-02-20 15:45:36 +00:00
from release_type import ReleaseType
2023-02-09 11:02:31 +00:00
def test_version():
2023-02-20 16:05:30 +00:00
version = Version([1, 2, 3])
2023-02-09 11:02:31 +00:00
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.SNAPSHOT)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.2.3-SNAPSHOT"
2023-02-20 15:53:53 +00:00
assert version.version_list == [1, 2, 3]
2023-02-09 11:02:31 +00:00
assert version.is_snapshot
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.BUMP)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.2.4-SNAPSHOT"
2023-02-20 15:53:53 +00:00
assert version.version_list == [1, 2, 4]
2023-02-20 15:37:49 +00:00
assert not version.is_snapshot
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.PATCH)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.2.5"
2023-02-20 15:53:53 +00:00
assert version.version_list == [1, 2, 5]
2023-02-09 11:02:31 +00:00
assert not version.is_snapshot
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.SNAPSHOT)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.2.5-SNAPSHOT"
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.SNAPSHOT)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.2.5-SNAPSHOT"
2023-02-09 11:02:31 +00:00
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.MINOR)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "1.3.0"
2023-02-09 11:02:31 +00:00
2023-02-20 15:53:53 +00:00
version.increment(ReleaseType.MAJOR)
2023-02-20 15:37:49 +00:00
assert version.get_version_string() == "2.0.0"
2023-02-09 12:20:42 +00:00
2023-02-09 12:33:56 +00:00
def test_gradle(tmp_path):
# init
file_name = 'config.gradle'
2023-02-09 16:09:42 +00:00
with open(f'test/resources/{file_name}', 'r') as gradle_file:
2023-02-09 12:33:56 +00:00
contents = gradle_file.read()
f = tmp_path / file_name
f.write_text(contents)
# test
2023-02-20 15:37:49 +00:00
version_repo = VersionRepository.get(f)
2023-02-20 15:53:53 +00:00
version = Version.create_release_version(ReleaseType.SNAPSHOT)
2023-02-20 15:37:49 +00:00
version_repo.write_file(version.get_version_string)
2023-02-09 12:20:42 +00:00
2023-02-09 12:33:56 +00:00
# check
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()