Skip to content

Commit 23a5aaf

Browse files
authored
Merge pull request #97 from aliceinwire/configuration
config: Fix config subcommand asking for config and support current f…
2 parents 9e51cbb + 0433b70 commit 23a5aaf

4 files changed

Lines changed: 76 additions & 30 deletions

File tree

kcidev/libs/common.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ def load_toml(settings, subcommand):
3838
config = tomllib.load(f)
3939
return config
4040

41-
if not config:
42-
kci_err(
43-
f"No config file found, please use `kci-dev config` to create a config file"
44-
)
45-
raise click.Abort()
41+
# config and results subcommand work without a config file
42+
if subcommand != "config" and subcommand != "results":
43+
if not config:
44+
kci_err(
45+
f"No config file found, please use `kci-dev config` to create a config file"
46+
)
47+
raise click.Abort()
4648

4749
return config
4850

kcidev/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
@click.pass_context
3131
def cli(ctx, settings, instance):
3232
subcommand = ctx.invoked_subcommand
33-
if subcommand != "results":
34-
ctx.obj = {"CFG": load_toml(settings, subcommand)}
35-
ctx.obj["SETTINGS"] = settings
33+
ctx.obj = {"CFG": load_toml(settings, subcommand)}
34+
ctx.obj["SETTINGS"] = settings
35+
if subcommand != "results" and subcommand != "config":
3636
if instance:
3737
ctx.obj["INSTANCE"] = instance
3838
else:

kcidev/subcommands/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def add_config(fpath):
5151
)
5252
if os.path.exists(poetry_example_configuration):
5353
config = True
54-
if not os.path.exists(dpath):
54+
if not os.path.exists(dpath) and dpath != "":
5555
# copy config
5656
os.makedirs(dpath)
5757
shutil.copyfile(poetry_example_configuration, fpath)
@@ -62,7 +62,7 @@ def add_config(fpath):
6262
)
6363
if os.path.exists(pypi_example_configuration):
6464
config = True
65-
if not os.path.exists(dpath):
65+
if not os.path.exists(dpath) and dpath != "":
6666
# copy config
6767
os.makedirs(dpath)
6868
shutil.copyfile(poetry_example_configuration, fpath)

tests/test_kcidev.py

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
import git
66
import pytest
77

8+
from kcidev.subcommands.config import add_config
89

9-
def test_prepare():
10+
11+
@pytest.fixture(scope="session")
12+
def kcidev_config(tmpdir_factory):
13+
file = tmpdir_factory.mktemp("config").join(".kci-dev.toml")
1014
# prepare enviroment
11-
os.system("cp .kci-dev.toml.example .kci-dev.toml")
12-
assert os.path.exists(".kci-dev.toml")
15+
command = ["poetry", "run", "kci-dev", "config", "--file-path", file]
16+
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
17+
return file
1318

1419

1520
def test_kcidev_help():
@@ -23,8 +28,16 @@ def test_kcidev_help():
2328
assert result.returncode == 0
2429

2530

26-
def test_kcidev_commit_help():
27-
command = ["poetry", "run", "kci-dev", "commit", "--help"]
31+
def test_kcidev_commit_help(kcidev_config):
32+
command = [
33+
"poetry",
34+
"run",
35+
"kci-dev",
36+
"--settings",
37+
kcidev_config,
38+
"commit",
39+
"--help",
40+
]
2841
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
2942
print("returncode: " + str(result.returncode))
3043
print("#### stdout ####")
@@ -34,8 +47,16 @@ def test_kcidev_commit_help():
3447
assert result.returncode == 0
3548

3649

37-
def test_kcidev_patch_help():
38-
command = ["poetry", "run", "kci-dev", "patch", "--help"]
50+
def test_kcidev_patch_help(kcidev_config):
51+
command = [
52+
"poetry",
53+
"run",
54+
"kci-dev",
55+
"--settings",
56+
kcidev_config,
57+
"patch",
58+
"--help",
59+
]
3960
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
4061
print("returncode: " + str(result.returncode))
4162
print("#### stdout ####")
@@ -45,8 +66,16 @@ def test_kcidev_patch_help():
4566
assert result.returncode == 0
4667

4768

48-
def test_kcidev_results_help():
49-
command = ["poetry", "run", "kci-dev", "maestro-results", "--help"]
69+
def test_kcidev_results_help(kcidev_config):
70+
command = [
71+
"poetry",
72+
"run",
73+
"kci-dev",
74+
"--settings",
75+
kcidev_config,
76+
"maestro-results",
77+
"--help",
78+
]
5079
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
5180
print("returncode: " + str(result.returncode))
5281
print("#### stdout ####")
@@ -56,8 +85,16 @@ def test_kcidev_results_help():
5685
assert result.returncode == 0
5786

5887

59-
def test_kcidev_testretry_help():
60-
command = ["poetry", "run", "kci-dev", "testretry", "--help"]
88+
def test_kcidev_testretry_help(kcidev_config):
89+
command = [
90+
"poetry",
91+
"run",
92+
"kci-dev",
93+
"--settings",
94+
kcidev_config,
95+
"testretry",
96+
"--help",
97+
]
6198
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
6299
print("returncode: " + str(result.returncode))
63100
print("#### stdout ####")
@@ -67,8 +104,16 @@ def test_kcidev_testretry_help():
67104
assert result.returncode == 0
68105

69106

70-
def test_kcidev_checkout_help():
71-
command = ["poetry", "run", "kci-dev", "checkout", "--help"]
107+
def test_kcidev_checkout_help(kcidev_config):
108+
command = [
109+
"poetry",
110+
"run",
111+
"kci-dev",
112+
"--settings",
113+
kcidev_config,
114+
"checkout",
115+
"--help",
116+
]
72117
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
73118
print("returncode: " + str(result.returncode))
74119
print("#### stdout ####")
@@ -78,11 +123,13 @@ def test_kcidev_checkout_help():
78123
assert result.returncode == 0
79124

80125

81-
def test_kcidev_results_tests():
126+
def test_kcidev_results_tests(kcidev_config):
82127
command = [
83128
"poetry",
84129
"run",
85130
"kci-dev",
131+
"--settings",
132+
kcidev_config,
86133
"--instance",
87134
"staging",
88135
"maestro-results",
@@ -112,11 +159,13 @@ def test_create_repo():
112159
r.index.commit("test")
113160

114161

115-
def test_kcidev_commit():
162+
def test_kcidev_commit(kcidev_config):
116163
command = [
117164
"poetry",
118165
"run",
119166
"kci-dev",
167+
"--settings",
168+
kcidev_config,
120169
"--instance",
121170
"staging",
122171
"commit",
@@ -149,8 +198,3 @@ def test_main():
149198
def test_clean():
150199
# clean enviroment
151200
shutil.rmtree("my-new-repo/")
152-
153-
if os.path.isfile(".kci-dev.toml"):
154-
os.remove(".kci-dev.toml")
155-
else:
156-
print("File does not exist")

0 commit comments

Comments
 (0)