|
26 | 26 | class TestWfChef: |
27 | 27 |
|
28 | 28 | @pytest.mark.unit |
| 29 | + @pytest.mark.skip |
29 | 30 | def test_recipe_management_functions(self) -> None: |
30 | 31 | """ |
31 | 32 | 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: |
85 | 86 |
|
86 | 87 | try: |
87 | 88 | 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") |
89 | 90 | except FileNotFoundError as e: |
90 | 91 | pass |
91 | 92 |
|
@@ -147,6 +148,119 @@ def test_recipe_management_functions(self) -> None: |
147 | 148 | except Exception as e: |
148 | 149 | pass |
149 | 150 |
|
| 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/") |
150 | 158 |
|
| 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) |
151 | 170 |
|
| 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") |
152 | 265 |
|
| 266 | + assert(new_new_num_recipes == num_recipes) |
0 commit comments