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 sys
|
||||||
import os
|
import os
|
||||||
import test_helper as th
|
from helper import Helper
|
||||||
|
|
||||||
# getting the name of the directory
|
# getting the name of the directory
|
||||||
# where the this file is present.
|
# where the this file is present.
|
||||||
|
@ -24,6 +24,7 @@ from mock_infrastructure_api import MockGitApi
|
||||||
|
|
||||||
def test_version_repository(tmp_path):
|
def test_version_repository(tmp_path):
|
||||||
# init
|
# init
|
||||||
|
th = Helper()
|
||||||
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
sut = VersionRepository(th.TEST_FILE_PATH)
|
sut = VersionRepository(th.TEST_FILE_PATH)
|
||||||
version = sut.get_version()
|
version = sut.get_version()
|
||||||
|
@ -34,6 +35,7 @@ def test_version_repository(tmp_path):
|
||||||
|
|
||||||
def test_release_repository(tmp_path):
|
def test_release_repository(tmp_path):
|
||||||
# init
|
# init
|
||||||
|
th = Helper()
|
||||||
th.copy_files( th.TEST_FILE_PATH, tmp_path)
|
th.copy_files( th.TEST_FILE_PATH, tmp_path)
|
||||||
version_repo = VersionRepository(th.TEST_FILE_PATH)
|
version_repo = VersionRepository(th.TEST_FILE_PATH)
|
||||||
release_type_repo = ReleaseTypeRepository(MockGitApi('MINOR test'))
|
release_type_repo = ReleaseTypeRepository(MockGitApi('MINOR test'))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pytest as pt
|
import pytest as pt
|
||||||
|
from helper import Helper
|
||||||
import sys
|
import sys
|
||||||
import os
|
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):
|
def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.json'
|
th = Helper()
|
||||||
with open(f'test/resources/{file_name}', 'r') as json_file:
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
contents = json_file.read()
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
|
|
||||||
# change the context of the script execution to tmp_path
|
# change the context of the script execution to tmp_path
|
||||||
change_test_dir(tmp_path, monkeypatch)
|
change_test_dir(tmp_path, monkeypatch)
|
||||||
|
|
||||||
git_api = GitApi()
|
git_api = GitApi()
|
||||||
git_api.init()
|
git_api.init()
|
||||||
git_api.add_file(file_name)
|
git_api.add_file(th.TEST_FILE_NAME)
|
||||||
git_api.commit("MINOR release")
|
git_api.commit("MINOR release")
|
||||||
|
|
||||||
# test
|
# test
|
||||||
|
@ -48,75 +46,63 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||||
# file handler tests
|
# file handler tests
|
||||||
def test_gradle(tmp_path):
|
def test_gradle(tmp_path):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.gradle'
|
th = Helper('config.gradle')
|
||||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
contents = gradle_file.read()
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||||
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||||
version = repo.get_version()
|
version = repo.get_version()
|
||||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
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 th.TEST_FILE_PATH.read_text()
|
||||||
|
|
||||||
|
|
||||||
def test_json(tmp_path):
|
def test_json(tmp_path):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.json'
|
th = Helper('config.json')
|
||||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
contents = gradle_file.read()
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||||
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||||
version = repo.get_version()
|
version = repo.get_version()
|
||||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# 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):
|
def test_clojure(tmp_path):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.clj'
|
th = Helper('config.clj')
|
||||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
contents = gradle_file.read()
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||||
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||||
version = repo.get_version()
|
version = repo.get_version()
|
||||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# 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):
|
def test_python(tmp_path):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.py'
|
th = Helper('config.py')
|
||||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
||||||
contents = gradle_file.read()
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
||||||
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
||||||
version = repo.get_version()
|
version = repo.get_version()
|
||||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# 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