WIP Tests

This commit is contained in:
erik 2023-02-20 16:37:49 +01:00
parent 3d3b26b70e
commit e790bc6eee

View file

@ -1,29 +1,36 @@
from devops_test import Version, ReleaseLevel from version import Version
from version_repository import VersionRepository
from release_type import ReleaseType
from pathlib import Path from pathlib import Path
def test_version(): def test_version():
version = Version([1, 2, 3], False) version = Version([1, 2, 3], False)
version.increment(ReleaseLevel.SNAPSHOT) version.increment(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.3-SNAPSHOT" assert version.get_version_string() == "1.2.3-SNAPSHOT"
assert version.version == [1, 2, 3] assert version.version == [1, 2, 3]
assert version.is_snapshot 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) version.increment(ReleaseLevel.PATCH)
assert version.get() == "1.2.4" assert version.get_version_string() == "1.2.5"
assert version.version == [1, 2, 4] assert version.version == [1, 2, 4]
assert not version.is_snapshot assert not version.is_snapshot
version.increment(ReleaseLevel.SNAPSHOT) version.increment(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.4-SNAPSHOT" assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseLevel.SNAPSHOT) version.increment(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.4-SNAPSHOT" assert version.get_version_string() == "1.2.5-SNAPSHOT"
version.increment(ReleaseLevel.MINOR) version.increment(ReleaseLevel.MINOR)
assert version.get() == "1.3.0" assert version.get_version_string() == "1.3.0"
version.increment(ReleaseLevel.MAJOR) version.increment(ReleaseLevel.MAJOR)
assert version.get() == "2.0.0" assert version.get_version_string() == "2.0.0"
def test_gradle(tmp_path): def test_gradle(tmp_path):
@ -36,60 +43,9 @@ def test_gradle(tmp_path):
f.write_text(contents) f.write_text(contents)
# test # test
version = Version.from_file(f) version_repo = VersionRepository.get(f)
version.increment(ReleaseLevel.SNAPSHOT) version = Version.create_release_version(ReleaseLevel.SNAPSHOT)
version.to_file() version_repo.write_file(version.get_version_string)
# check # check
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text() 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 = Version.from_file(f)
version.increment(ReleaseLevel.SNAPSHOT)
version.to_file()
# 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 = Version.from_file(f)
version.increment(ReleaseLevel.SNAPSHOT)
version.to_file()
# 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 = Version.from_file(f)
version.increment(ReleaseLevel.SNAPSHOT)
version.to_file()
# check
assert '3.1.3-SNAPSHOT' in f.read_text()