2023-02-09 11:02:31 +00:00
|
|
|
from devops_test import Version, ReleaseLevel
|
2023-02-09 12:33:56 +00:00
|
|
|
from pathlib import Path
|
2023-02-09 11:02:31 +00:00
|
|
|
|
|
|
|
def test_version():
|
|
|
|
version = Version([1, 2, 3], False)
|
|
|
|
|
|
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
|
|
assert version.get() == "1.2.3-SNAPSHOT"
|
|
|
|
assert version.version == [1, 2, 3]
|
|
|
|
assert version.is_snapshot
|
|
|
|
|
|
|
|
version.increment(ReleaseLevel.PATCH)
|
|
|
|
assert version.get() == "1.2.4"
|
|
|
|
assert version.version == [1, 2, 4]
|
|
|
|
assert not version.is_snapshot
|
|
|
|
|
|
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
|
|
assert version.get() == "1.2.4-SNAPSHOT"
|
|
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
|
|
assert version.get() == "1.2.4-SNAPSHOT"
|
|
|
|
|
|
|
|
version.increment(ReleaseLevel.MINOR)
|
|
|
|
assert version.get() == "1.3.0"
|
|
|
|
|
|
|
|
version.increment(ReleaseLevel.MAJOR)
|
2023-02-09 12:20:42 +00:00
|
|
|
assert version.get() == "2.0.0"
|
|
|
|
|
|
|
|
|
2023-02-09 12:33:56 +00:00
|
|
|
def test_gradle(tmp_path):
|
|
|
|
# init
|
|
|
|
file_name = 'config.gradle'
|
|
|
|
with open(f'test/{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()
|
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()
|
|
|
|
|
|
|
|
def test_json(tmp_path):
|
|
|
|
# init
|
|
|
|
file_name = 'config.json'
|
|
|
|
with open(f'test/{file_name}', 'r') as gradle_file:
|
|
|
|
contents = gradle_file.read()
|
2023-02-09 12:20:42 +00:00
|
|
|
|
2023-02-09 12:33:56 +00:00
|
|
|
f = tmp_path / file_name
|
|
|
|
f.write_text(contents)
|
2023-02-09 12:20:42 +00:00
|
|
|
|
2023-02-09 12:33:56 +00:00
|
|
|
# test
|
|
|
|
version = Version.from_file(f)
|
2023-02-09 12:20:42 +00:00
|
|
|
version.increment(ReleaseLevel.SNAPSHOT)
|
|
|
|
version.to_file()
|
2023-02-09 12:33:56 +00:00
|
|
|
|
|
|
|
# check
|
2023-02-09 12:56:45 +00:00
|
|
|
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
|
|
|
|
2023-02-09 13:32:55 +00:00
|
|
|
def test_clojure(tmp_path):
|
2023-02-09 12:56:45 +00:00
|
|
|
# init
|
|
|
|
file_name = 'config.clj'
|
|
|
|
with open(f'test/{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
|
2023-02-09 13:32:55 +00:00
|
|
|
assert '1.1.3-SNAPSHOT' in f.read_text()
|
|
|
|
|
|
|
|
def test_python(tmp_path):
|
|
|
|
# init
|
|
|
|
file_name = 'config.py'
|
|
|
|
with open(f'test/{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()
|