Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ def load_toml(settings, subcommand):
config = tomllib.load(f)
return config

if not config:
kci_err(
f"No config file found, please use `kci-dev config` to create a config file"
)
raise click.Abort()
# config and results subcommand work without a config file
if subcommand != "config" and subcommand != "results":
if not config:
kci_err(
f"No config file found, please use `kci-dev config` to create a config file"
)
raise click.Abort()

return config

Expand Down
6 changes: 3 additions & 3 deletions kcidev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
@click.pass_context
def cli(ctx, settings, instance):
subcommand = ctx.invoked_subcommand
if subcommand != "results":
ctx.obj = {"CFG": load_toml(settings, subcommand)}
ctx.obj["SETTINGS"] = settings
ctx.obj = {"CFG": load_toml(settings, subcommand)}
ctx.obj["SETTINGS"] = settings
if subcommand != "results" and subcommand != "config":
if instance:
ctx.obj["INSTANCE"] = instance
else:
Expand Down
4 changes: 2 additions & 2 deletions kcidev/subcommands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def add_config(fpath):
)
if os.path.exists(poetry_example_configuration):
config = True
if not os.path.exists(dpath):
if not os.path.exists(dpath) and dpath != "":
# copy config
os.makedirs(dpath)
shutil.copyfile(poetry_example_configuration, fpath)
Expand All @@ -62,7 +62,7 @@ def add_config(fpath):
)
if os.path.exists(pypi_example_configuration):
config = True
if not os.path.exists(dpath):
if not os.path.exists(dpath) and dpath != "":
# copy config
os.makedirs(dpath)
shutil.copyfile(poetry_example_configuration, fpath)
Expand Down
84 changes: 64 additions & 20 deletions tests/test_kcidev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import git
import pytest

from kcidev.subcommands.config import add_config

def test_prepare():

@pytest.fixture(scope="session")
def kcidev_config(tmpdir_factory):
file = tmpdir_factory.mktemp("config").join(".kci-dev.toml")
# prepare enviroment
os.system("cp .kci-dev.toml.example .kci-dev.toml")
assert os.path.exists(".kci-dev.toml")
command = ["poetry", "run", "kci-dev", "config", "--file-path", file]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
return file


def test_kcidev_help():
Expand All @@ -23,8 +28,16 @@ def test_kcidev_help():
assert result.returncode == 0


def test_kcidev_commit_help():
command = ["poetry", "run", "kci-dev", "commit", "--help"]
def test_kcidev_commit_help(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"commit",
"--help",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
Expand All @@ -34,8 +47,16 @@ def test_kcidev_commit_help():
assert result.returncode == 0


def test_kcidev_patch_help():
command = ["poetry", "run", "kci-dev", "patch", "--help"]
def test_kcidev_patch_help(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"patch",
"--help",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
Expand All @@ -45,8 +66,16 @@ def test_kcidev_patch_help():
assert result.returncode == 0


def test_kcidev_results_help():
command = ["poetry", "run", "kci-dev", "maestro-results", "--help"]
def test_kcidev_results_help(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"maestro-results",
"--help",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
Expand All @@ -56,8 +85,16 @@ def test_kcidev_results_help():
assert result.returncode == 0


def test_kcidev_testretry_help():
command = ["poetry", "run", "kci-dev", "testretry", "--help"]
def test_kcidev_testretry_help(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"testretry",
"--help",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
Expand All @@ -67,8 +104,16 @@ def test_kcidev_testretry_help():
assert result.returncode == 0


def test_kcidev_checkout_help():
command = ["poetry", "run", "kci-dev", "checkout", "--help"]
def test_kcidev_checkout_help(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"checkout",
"--help",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
Expand All @@ -78,11 +123,13 @@ def test_kcidev_checkout_help():
assert result.returncode == 0


def test_kcidev_results_tests():
def test_kcidev_results_tests(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"--instance",
"staging",
"maestro-results",
Expand Down Expand Up @@ -112,11 +159,13 @@ def test_create_repo():
r.index.commit("test")


def test_kcidev_commit():
def test_kcidev_commit(kcidev_config):
command = [
"poetry",
"run",
"kci-dev",
"--settings",
kcidev_config,
"--instance",
"staging",
"commit",
Expand Down Expand Up @@ -149,8 +198,3 @@ def test_main():
def test_clean():
# clean enviroment
shutil.rmtree("my-new-repo/")

if os.path.isfile(".kci-dev.toml"):
os.remove(".kci-dev.toml")
else:
print("File does not exist")
Loading