Adapt tests for helper class
This commit is contained in:
parent
e4996dfb20
commit
21bafab882
2 changed files with 27 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
import os
|
||||
import test_helper as th
|
||||
from helper import Helper
|
||||
|
||||
# getting the name of the directory
|
||||
# where the this file is present.
|
||||
|
@ -24,6 +24,7 @@ from mock_infrastructure_api import MockGitApi
|
|||
|
||||
def test_version_repository(tmp_path):
|
||||
# init
|
||||
th = Helper()
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
sut = VersionRepository(th.TEST_FILE_PATH)
|
||||
version = sut.get_version()
|
||||
|
@ -34,6 +35,7 @@ def test_version_repository(tmp_path):
|
|||
|
||||
def test_release_repository(tmp_path):
|
||||
# init
|
||||
th = Helper()
|
||||
th.copy_files( th.TEST_FILE_PATH, tmp_path)
|
||||
version_repo = VersionRepository(th.TEST_FILE_PATH)
|
||||
release_type_repo = ReleaseTypeRepository(MockGitApi('MINOR test'))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from pathlib import Path
|
||||
import pytest as pt
|
||||
from helper import Helper
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
@ -27,18 +28,15 @@ def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
|
||||
def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||
# init
|
||||
file_name = 'config.json'
|
||||
with open(f'test/resources/{file_name}', 'r') as json_file:
|
||||
contents = json_file.read()
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
th = Helper()
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
|
||||
# change the context of the script execution to tmp_path
|
||||
change_test_dir(tmp_path, monkeypatch)
|
||||
|
||||
git_api = GitApi()
|
||||
git_api.init()
|
||||
git_api.add_file(file_name)
|
||||
git_api.add_file(th.TEST_FILE_NAME)
|
||||
git_api.commit("MINOR release")
|
||||
|
||||
# test
|
||||
|
@ -48,75 +46,63 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
# file handler tests
|
||||
def test_gradle(tmp_path):
|
||||
# init
|
||||
file_name = 'config.gradle'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
th = Helper('config.gradle')
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
|
||||
assert 'version = "12.4.678-SNAPSHOT"' in th.TEST_FILE_PATH.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)
|
||||
th = Helper('config.json')
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
||||
assert '"version": "123.123.456-SNAPSHOT"' in th.TEST_FILE_PATH.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)
|
||||
th = Helper('config.clj')
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '1.1.3-SNAPSHOT' in f.read_text()
|
||||
assert '1.1.3-SNAPSHOT' in th.TEST_FILE_PATH.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)
|
||||
th = Helper('config.py')
|
||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '3.1.3-SNAPSHOT' in f.read_text()
|
||||
assert '3.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text()
|
Loading…
Reference in a new issue