diff --git a/kcidev/libs/common.py b/kcidev/libs/common.py index 2d62469..24f00e9 100644 --- a/kcidev/libs/common.py +++ b/kcidev/libs/common.py @@ -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 diff --git a/kcidev/main.py b/kcidev/main.py index 883b0f4..3e46706 100755 --- a/kcidev/main.py +++ b/kcidev/main.py @@ -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: diff --git a/kcidev/subcommands/config.py b/kcidev/subcommands/config.py index 507f3e8..b5899c8 100644 --- a/kcidev/subcommands/config.py +++ b/kcidev/subcommands/config.py @@ -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) @@ -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) diff --git a/tests/test_kcidev.py b/tests/test_kcidev.py index 69bff16..bf915e7 100644 --- a/tests/test_kcidev.py +++ b/tests/test_kcidev.py @@ -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(): @@ -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 ####") @@ -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 ####") @@ -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 ####") @@ -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 ####") @@ -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 ####") @@ -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", @@ -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", @@ -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")