Skip to content

Commit c492ea8

Browse files
committed
Small wfchef script fix
testing++
1 parent e20a945 commit c492ea8

2 files changed

Lines changed: 116 additions & 2 deletions

File tree

tests/wfchef/test_wfchef.py

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
class TestWfChef:
2727

2828
@pytest.mark.unit
29+
@pytest.mark.skip
2930
def test_recipe_management_functions(self) -> None:
3031
"""
3132
Just calling the create_recipe function from chef.py directly (i.e., bypassing main())
@@ -85,7 +86,7 @@ def test_recipe_management_functions(self) -> None:
8586

8687
try:
8788
install_recipe("/bogus/bogus/whatever", verbose=True)
88-
raise Exception("Should not be able to install a recipe given a bogus path")
89+
raise RuntimeError("Should not be able to install a recipe given a bogus path")
8990
except FileNotFoundError as e:
9091
pass
9192

@@ -147,6 +148,119 @@ def test_recipe_management_functions(self) -> None:
147148
except Exception as e:
148149
pass
149150

151+
@pytest.mark.unit
152+
def test_recipe_management_wfchef_main(self, monkeypatch, capsys) -> None:
153+
154+
# Importing main for easier testing/coverage (compared to subprocessing the executable)
155+
from wfcommons.wfchef.chef import main
156+
157+
dirpath = _create_fresh_local_dir("/tmp/recipe/")
150158

159+
# Put a few JSON workflows in /tmp
160+
urls = [
161+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json",
162+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-002.json",
163+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-003.json",
164+
]
165+
for url in urls:
166+
response = requests.get(url)
167+
local_file_name = url.split("/")[-1]
168+
with open(dirpath / local_file_name, 'wb') as f:
169+
f.write(response.content)
151170

171+
# Calling main with --help
172+
with capsys.disabled():
173+
sys.stderr.write("\n" + "=" * 60 + "\n")
174+
sys.stderr.write("Calling wfchef script with '--help'...\n")
175+
sys.stderr.write("=" * 60 + "\n")
176+
monkeypatch.setattr(sys, 'argv', ["wfchef", "--help"])
177+
try:
178+
main()
179+
except SystemExit as e:
180+
assert e.code == 0
181+
captured = capsys.readouterr()
182+
if "usage" not in captured.out.lower():
183+
raise RuntimeError("wfchef script does not print usage information with -h flag")
184+
with capsys.disabled():
185+
sys.stderr.write("✓ Script called successfully\n")
186+
187+
# Calling main with 'ls' command
188+
with capsys.disabled():
189+
sys.stderr.write("\n" + "=" * 60 + "\n")
190+
sys.stderr.write("Calling wfchef script with 'ls' command...\n")
191+
sys.stderr.write("=" * 60 + "\n")
192+
monkeypatch.setattr(sys, 'argv', ["wfchef", "ls"])
193+
try:
194+
main()
195+
except SystemExit as e:
196+
assert e.code == 0
197+
captured = capsys.readouterr()
198+
if "_recipe" not in captured.out.lower():
199+
raise RuntimeError("wfchef script does not list recipes with 'ls' command")
200+
num_recipes = sum(["_recipe" in x for x in captured.out.splitlines()])
201+
with capsys.disabled():
202+
sys.stderr.write(f"✓ Script called successfully ({num_recipes} recipes listed)\n")
203+
204+
# Calling main with 'create' command
205+
with capsys.disabled():
206+
sys.stderr.write("\n" + "=" * 60 + "\n")
207+
sys.stderr.write("Calling wfchef script with 'create' command...\n")
208+
sys.stderr.write("=" * 60 + "\n")
209+
monkeypatch.setattr(sys, 'argv', ["wfchef", "create", str(dirpath), "-o", str(dirpath), "-n", "SomeRecipe"])
210+
try:
211+
main()
212+
except SystemExit as e:
213+
assert e.code == 0
214+
capsys.readouterr() # Clear output
215+
216+
# Calling main with 'ls' command
217+
with capsys.disabled():
218+
sys.stderr.write("\n" + "=" * 60 + "\n")
219+
sys.stderr.write("Calling wfchef script with 'ls' command...\n")
220+
sys.stderr.write("=" * 60 + "\n")
221+
monkeypatch.setattr(sys, 'argv', ["wfchef", "ls"])
222+
try:
223+
main()
224+
except SystemExit as e:
225+
assert e.code == 0
226+
captured = capsys.readouterr()
227+
if "_recipe" not in captured.out.lower():
228+
raise RuntimeError("wfchef script does not list recipes with 'ls' command")
229+
new_num_recipes = sum(["_recipe" in x for x in captured.out.splitlines()])
230+
with capsys.disabled():
231+
sys.stderr.write(f"✓ Script called successfully ({new_num_recipes} recipes listed)\n")
232+
233+
assert(num_recipes + 1 == new_num_recipes)
234+
235+
# Calling main with 'uninstall' command
236+
with capsys.disabled():
237+
sys.stderr.write("\n" + "=" * 60 + "\n")
238+
sys.stderr.write("Calling wfchef script with 'uninstall' command...\n")
239+
sys.stderr.write("=" * 60 + "\n")
240+
monkeypatch.setattr(sys, 'argv', ["wfchef", "uninstall", "-n", "SomeRecipe"])
241+
try:
242+
main()
243+
except SystemExit as e:
244+
assert e.code == 0
245+
capsys.readouterr() # Clear output
246+
247+
248+
249+
# Calling main with 'ls' command
250+
with capsys.disabled():
251+
sys.stderr.write("\n" + "=" * 60 + "\n")
252+
sys.stderr.write("Calling wfchef script with 'ls' command...\n")
253+
sys.stderr.write("=" * 60 + "\n")
254+
monkeypatch.setattr(sys, 'argv', ["wfchef", "ls"])
255+
try:
256+
main()
257+
except SystemExit as e:
258+
assert e.code == 0
259+
captured = capsys.readouterr()
260+
if "_recipe" not in captured.out.lower():
261+
raise RuntimeError("wfchef script does not list recipes with 'ls' command")
262+
new_new_num_recipes = sum(["_recipe" in x for x in captured.out.splitlines()])
263+
with capsys.disabled():
264+
sys.stderr.write(f"✓ Script called successfully ({new_new_num_recipes} recipes listed)\n")
152265

266+
assert(new_new_num_recipes == num_recipes)

wfcommons/wfchef/chef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def main():
566566
if args.action == ls_recipe:
567567
ls_recipe()
568568
elif args.action == uninstall_recipe:
569-
uninstall_recipe(args.name, pathlib.Path(args.out))
569+
uninstall_recipe(args.name)
570570
elif args.action == create_recipe:
571571
create_recipe(args.path, args.out, args.name, cutoff=args.cutoff, verbose=True)
572572

0 commit comments

Comments
 (0)