Skip to content

Commit e9656a7

Browse files
Merge pull request #125 from wfcommons/testing
WfChef script Testing++
2 parents 332fef0 + 08f0e15 commit e9656a7

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

tests/wfchef/test_wfchef.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ def test_recipe_management_wfchef_main(self, monkeypatch, capsys) -> None:
193193
with capsys.disabled():
194194
sys.stderr.write("✓ Script called successfully\n")
195195

196+
# Calling main with no argument, which should be the same as --help
197+
with capsys.disabled():
198+
sys.stderr.write("\n" + "=" * 60 + "\n")
199+
sys.stderr.write("Calling wfchef script with no argument...\n")
200+
sys.stderr.write("=" * 60 + "\n")
201+
monkeypatch.setattr(sys, 'argv', ["wfchef"])
202+
try:
203+
main()
204+
except SystemExit as e:
205+
assert e.code == 0
206+
captured = capsys.readouterr()
207+
if "usage" not in captured.out.lower():
208+
raise RuntimeError("wfchef script does not print usage information with -h flag")
209+
with capsys.disabled():
210+
sys.stderr.write("✓ Script called successfully\n")
211+
196212
# Calling main with 'ls' command
197213
with capsys.disabled():
198214
sys.stderr.write("\n" + "=" * 60 + "\n")
@@ -210,12 +226,12 @@ def test_recipe_management_wfchef_main(self, monkeypatch, capsys) -> None:
210226
with capsys.disabled():
211227
sys.stderr.write(f"✓ Script called successfully ({num_recipes} recipes listed)\n")
212228

213-
# Calling main with 'create' command
229+
# Calling main with 'create' command with the --no-install flag
214230
with capsys.disabled():
215231
sys.stderr.write("\n" + "=" * 60 + "\n")
216-
sys.stderr.write("Calling wfchef script with 'create' command...\n")
232+
sys.stderr.write("Calling wfchef script with 'create' command withe the --no-install flag...\n")
217233
sys.stderr.write("=" * 60 + "\n")
218-
monkeypatch.setattr(sys, 'argv', ["wfchef", "create", str(dirpath), "-o", str(dirpath), "-n", "SomeRecipe"])
234+
monkeypatch.setattr(sys, 'argv', ["wfchef", "create", str(dirpath), "-o", str(dirpath), "-n", "SomeRecipe", "--no-install"])
219235
try:
220236
main()
221237
except SystemExit as e:
@@ -239,7 +255,39 @@ def test_recipe_management_wfchef_main(self, monkeypatch, capsys) -> None:
239255
with capsys.disabled():
240256
sys.stderr.write(f"✓ Script called successfully ({new_num_recipes} recipes listed)\n")
241257

242-
assert(num_recipes + 1 == new_num_recipes)
258+
assert(num_recipes == new_num_recipes)
259+
260+
# Calling main with 'create' command WITHOUT the --no-install flag
261+
with capsys.disabled():
262+
sys.stderr.write("\n" + "=" * 60 + "\n")
263+
sys.stderr.write("Calling wfchef script with 'create' command without the --no-install flag...\n")
264+
sys.stderr.write("=" * 60 + "\n")
265+
monkeypatch.setattr(sys, 'argv',
266+
["wfchef", "create", str(dirpath), "-o", str(dirpath), "-n", "SomeRecipe"])
267+
try:
268+
main()
269+
except SystemExit as e:
270+
assert e.code == 0
271+
capsys.readouterr() # Clear output
272+
273+
# Calling main with 'ls' command
274+
with capsys.disabled():
275+
sys.stderr.write("\n" + "=" * 60 + "\n")
276+
sys.stderr.write("Calling wfchef script with 'ls' command...\n")
277+
sys.stderr.write("=" * 60 + "\n")
278+
monkeypatch.setattr(sys, 'argv', ["wfchef", "ls"])
279+
try:
280+
main()
281+
except SystemExit as e:
282+
assert e.code == 0
283+
captured = capsys.readouterr()
284+
if "_recipe" not in captured.out.lower():
285+
raise RuntimeError("wfchef script does not list recipes with 'ls' command")
286+
new_num_recipes = sum(["_recipe" in x for x in captured.out.splitlines()])
287+
with capsys.disabled():
288+
sys.stderr.write(f"✓ Script called successfully ({new_num_recipes} recipes listed)\n")
289+
290+
assert (num_recipes + 1 == new_num_recipes)
243291

244292
# Calling main with 'uninstall' command
245293
with capsys.disabled():

0 commit comments

Comments
 (0)