Implement tests for file handling
This commit is contained in:
parent
ca3db5efe9
commit
86c66dc7f7
3 changed files with 34 additions and 9 deletions
|
@ -6,11 +6,11 @@ class FileHandler(ABC):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file_path(cls, file_path):
|
def from_file_path(cls, file_path):
|
||||||
config_file_type = file_path.split('.')[-1]
|
config_file_type = file_path.suffix
|
||||||
match config_file_type:
|
match config_file_type:
|
||||||
case 'json':
|
case '.json':
|
||||||
file_handler = JsonFileHandler()
|
file_handler = JsonFileHandler()
|
||||||
case 'gradle':
|
case '.gradle':
|
||||||
file_handler = GradleFileHandler()
|
file_handler = GradleFileHandler()
|
||||||
case _:
|
case _:
|
||||||
raise Exception(f'The file type "{config_file_type}" is not implemented')
|
raise Exception(f'The file type "{config_file_type}" is not implemented')
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
version = "12.4.678"
|
version = "12.4.678"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from devops_test import Version, ReleaseLevel
|
from devops_test import Version, ReleaseLevel
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
def test_version():
|
def test_version():
|
||||||
version = Version([1, 2, 3], False)
|
version = Version([1, 2, 3], False)
|
||||||
|
@ -25,12 +26,36 @@ def test_version():
|
||||||
assert version.get() == "2.0.0"
|
assert version.get() == "2.0.0"
|
||||||
|
|
||||||
|
|
||||||
def test_gradle():
|
def test_gradle(tmp_path):
|
||||||
# validate_values()
|
# init
|
||||||
version = Version.from_file('build.gradle')
|
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.increment(ReleaseLevel.SNAPSHOT)
|
||||||
version.to_file()
|
version.to_file()
|
||||||
print(version.get())
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
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()
|
Loading…
Reference in a new issue