Skip to content

Commit 8185809

Browse files
committed
Refactored the recipe installing/uninstalling/ls feature
1 parent fd0641a commit 8185809

File tree

2 files changed

+337
-121
lines changed

2 files changed

+337
-121
lines changed

tests/wfchef/test_wfchef.py

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from tests.test_helpers import _create_fresh_local_dir
1919
from wfcommons.wfchef.chef import create_recipe
20+
from wfcommons.wfchef.chef import install_recipe
2021
from wfcommons.wfchef.chef import uninstall_recipe
2122
from wfcommons.wfchef.chef import ls_recipe
2223

@@ -32,10 +33,11 @@ def test_create_recipe(self) -> None:
3233
dirpath = _create_fresh_local_dir("/tmp/recipe/")
3334

3435
# Put a few JSON workflows in /tmp
35-
urls = ["https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json",
36-
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-002.json",
37-
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-003.json",
38-
]
36+
urls = [
37+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json",
38+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-002.json",
39+
"https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-003.json",
40+
]
3941
for url in urls:
4042
response = requests.get(url)
4143
local_file_name = url.split("/")[-1]
@@ -49,33 +51,78 @@ def test_create_recipe(self) -> None:
4951
"name": "somename",
5052
"cutoff": 4000
5153
}
52-
create_recipe(args["path"], args["out"], args["name"], cutoff=args["cutoff"], verbose=True)
5354

54-
# Check that some of the expected files are there
55-
assert((dirpath / "pyproject.toml").exists())
56-
assert((dirpath / "recipe_recipes" / "__init__.py").exists())
57-
assert((dirpath / "recipe_recipes" / "somename" / "__init__.py").exists())
58-
assert((dirpath / "recipe_recipes" / "somename" / "recipe.py").exists())
59-
assert((dirpath / "recipe_recipes" / "somename" / "microstructures").exists())
60-
61-
sys.stderr.write("1. CALLING LS_RECIPE()\n")
55+
sys.stderr.write("\n" + "=" * 60 + "\n")
56+
sys.stderr.write("Creating recipe...\n")
57+
sys.stderr.write("=" * 60 + "\n")
58+
59+
create_recipe(
60+
args["path"],
61+
args["out"],
62+
args["name"],
63+
cutoff=args["cutoff"],
64+
verbose=True
65+
)
66+
67+
# Check that expected files are there
68+
sys.stderr.write("\nVerifying created files...\n")
69+
assert (dirpath / "pyproject.toml").exists(), "pyproject.toml not found"
70+
assert (dirpath / "wfchef_recipe_somename" / "__init__.py").exists(), "package __init__.py not found"
71+
assert (dirpath / "wfchef_recipe_somename" / "recipe.py").exists(), "recipe.py not found"
72+
assert (dirpath / "wfchef_recipe_somename" / "microstructures").exists(), "microstructures not found"
73+
sys.stderr.write("✓ All expected files created\n")
74+
75+
sys.stderr.write("\n" + "=" * 60 + "\n")
76+
sys.stderr.write("Calling ls_recipe before the install:\n")
77+
sys.stderr.write("=" * 60 + "\n")
6278
ls_recipe()
6379

6480
# Install the recipe
81+
sys.stderr.write("\n" + "=" * 60 + "\n")
6582
sys.stderr.write("Installing the recipe...\n")
66-
subprocess.check_call([sys.executable, "-m", "pip", "install", "/tmp/recipe/"])
83+
sys.stderr.write("=" * 60 + "\n")
84+
85+
success = install_recipe(dirpath, verbose=True)
86+
assert success, "Recipe installation failed"
87+
sys.stderr.write("✓ Recipe installed successfully\n")
6788

68-
sys.stderr.write("2. CALLING LS_RECIPE()\n")
89+
sys.stderr.write("\n" + "=" * 60 + "\n")
90+
sys.stderr.write("Calling ls_recipe after the install:\n")
91+
sys.stderr.write("=" * 60 + "\n")
6992
ls_recipe()
7093

94+
# Verify the recipe can be loaded
95+
sys.stderr.write("\n" + "=" * 60 + "\n")
96+
sys.stderr.write("Testing the recipe import...\n")
97+
sys.stderr.write("=" * 60 + "\n")
98+
99+
try:
100+
from wfchef_recipe_somename import SomenameRecipe
101+
sys.stderr.write("✓ Successfully imported SomenameRecipe\n")
102+
sys.stderr.write(f" Recipe class: {SomenameRecipe}\n")
103+
sys.stderr.write(f" Module: {SomenameRecipe.__module__}\n")
104+
except ImportError as e:
105+
sys.stderr.write(f"✗ Failed to import recipe: {e}\n")
106+
raise
107+
71108
# Uninstall the recipe
72-
# TODO: This does not uninstall the recipe (to fix)
109+
sys.stderr.write("\n" + "=" * 60 + "\n")
73110
sys.stderr.write("Uninstalling the recipe...\n")
74-
uninstall_recipe("recipe_recipes.somename", dirpath)
75-
sys.stderr.write("3. CALLING LS_RECIPE()\n")
111+
sys.stderr.write("=" * 60 + "\n")
112+
113+
success = uninstall_recipe("somename")
114+
assert success, "Recipe uninstallation failed"
115+
sys.stderr.write("✓ Recipe uninstalled successfully\n")
76116

117+
sys.stderr.write("\n" + "=" * 60 + "\n")
118+
sys.stderr.write("Calling ls_recipe after the uninstall:\n")
119+
sys.stderr.write("=" * 60 + "\n")
77120
ls_recipe()
78121

122+
sys.stderr.write("\n" + "=" * 60 + "\n")
123+
sys.stderr.write("TEST COMPLETED SUCCESSFULLY\n")
124+
sys.stderr.write("=" * 60 + "\n")
125+
79126

80127
# TODO: Do more extensive tests
81128
# - Install/Uninstall the recipe

0 commit comments

Comments
 (0)