Compare commits

...

9 commits

Author SHA1 Message Date
156d336314 Fix logical error 2023-02-20 17:07:14 +01:00
f96733f8b5 Fix version instance 2023-02-20 17:05:30 +01:00
b06728c553 Fix return val and hardcoded None 2023-02-20 17:04:50 +01:00
d539c73318 Fix test method and attribute calls 2023-02-20 16:53:53 +01:00
1743dce46d Add missing imports and cleanup 2023-02-20 16:50:12 +01:00
80c0799d1a Add proper imports 2023-02-20 16:45:36 +01:00
e790bc6eee WIP Tests 2023-02-20 16:37:49 +01:00
3d3b26b70e Refactor release type 2023-02-20 16:37:30 +01:00
54c3917ec2 Clean up 2023-02-20 16:37:01 +01:00
4 changed files with 56 additions and 94 deletions

7
release_type.py Normal file
View file

@ -0,0 +1,7 @@
from enum import Enum
class ReleaseType(Enum):
MAJOR = 0
MINOR = 1
PATCH = 2
SNAPSHOT = 3
BUMP = None

View file

@ -1,29 +1,54 @@
from devops_test import Version, ReleaseLevel
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], False)
version = Version([1, 2, 3])
version.increment(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.3-SNAPSHOT"
assert version.version == [1, 2, 3]
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(ReleaseLevel.PATCH)
assert version.get() == "1.2.4"
assert version.version == [1, 2, 4]
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(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.4-SNAPSHOT"
version.increment(ReleaseLevel.SNAPSHOT)
assert version.get() == "1.2.4-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(ReleaseLevel.MINOR)
assert version.get() == "1.3.0"
version.increment(ReleaseType.MINOR)
assert version.get_version_string() == "1.3.0"
version.increment(ReleaseLevel.MAJOR)
assert version.get() == "2.0.0"
version.increment(ReleaseType.MAJOR)
assert version.get_version_string() == "2.0.0"
def test_gradle(tmp_path):
@ -36,60 +61,9 @@ def test_gradle(tmp_path):
f.write_text(contents)
# test
version = Version.from_file(f)
version.increment(ReleaseLevel.SNAPSHOT)
version.to_file()
version_repo = VersionRepository.get(f)
version = Version.create_release_version(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 = 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()

View file

@ -1,30 +1,10 @@
from enum import Enum
from release_type import ReleaseType
from file_handlers import FileHandler
def init_project():
# validate_values()
version = Version.from_file('build.gradle')
version.increment(ReleaseType.SNAPSHOT)
version.to_file()
print(version.get())
def prepare_release():
pass
def release_in_git():
pass
class ReleaseType(Enum):
MAJOR = 0
MINOR = 1
PATCH = 2
SNAPSHOT = 3
BUMP = None
class Version():
def __init__(self, version_list, release_type):
self.version_list = None
def __init__(self, version_list: list):
self.version_list = version_list
self.version_string = None
self.is_snapshot = None
@ -50,6 +30,7 @@ class Version():
self.version_string = ".".join([str(x) for x in self.version_list])
if self.is_snapshot:
self.version_string += "-SNAPSHOT"
return self.version_string
@classmethod
def create_release_version(cls, version_list, release_type):

View file

@ -25,7 +25,7 @@ class VersionRepository():
return version_list, is_snapshot
@classmethod
def get(cls, file) -> VersionRepository:
def get(cls, file):
inst = cls(file)
file_handler= inst.load_file(file)