Skip to content

Commit

Permalink
raise error on missing default
Browse files Browse the repository at this point in the history
  • Loading branch information
Satrat committed Sep 22, 2023
1 parent b2bd3b2 commit b565413
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sparsezoo/objects/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def default(self) -> File:
return recipe

# fallback to first recipe in list
if len(self._recipes) == 0:
raise ValueError("No recipes found, could not retrieve a default.")

_LOGGER.warning(
f"No default recipe {self._default_recipe_name} found, falling back to "
f"first listed recipe {self._recipes[0].name}"
Expand Down
11 changes: 11 additions & 0 deletions tests/sparsezoo/objects/test_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import tempfile

import pytest

from sparsezoo.model import Model


Expand Down Expand Up @@ -59,3 +61,12 @@ def test_custom_default():
available_recipes = model.recipes.available
assert len(available_recipes) == 1
assert available_recipes[0] == "recipe_transfer_text_classification"


def test_fail_default_on_empty():
false_recipe_stub = "zoo:bert-base-wikipedia_bookcorpus-pruned90?recipe=nope"
temp_dir = tempfile.TemporaryDirectory(dir="/tmp")
model = Model(false_recipe_stub, temp_dir.name)

with pytest.raises(ValueError):
_ = model.recipes.default

0 comments on commit b565413

Please sign in to comment.