diff --git a/bananalyzer/data/examples.py b/bananalyzer/data/examples.py index cc9d5467..16cd883a 100644 --- a/bananalyzer/data/examples.py +++ b/bananalyzer/data/examples.py @@ -23,10 +23,16 @@ def are_examples_available(path: Path) -> bool: def get_examples_path() -> Path: + """Determine the path to the examples, preferring local if available.""" if are_examples_available(local_examples_path): - print("### Returning local examples ###") + print("### Using local examples! ###") return local_examples_path - return downloaded_examples_path + elif are_examples_available(downloaded_examples_path): + return downloaded_examples_path + else: + raise FileNotFoundError( + "No examples download. Re-run with `--download` to download example data via git." + ) def download_examples() -> None: diff --git a/tests/test_examples.py b/tests/test_examples.py index 13c5008d..53273e6a 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -13,9 +13,11 @@ downloaded_examples_path, get_all_examples, get_example_by_url, + get_examples_path, get_test_examples, get_training_examples, load_examples_at_path, + local_examples_path, ) from bananalyzer.data.schemas import Example @@ -40,11 +42,23 @@ def test_load_examples_at_path_file_not_found(mocker: MockFixture) -> None: load_examples_at_path(Path("/fake/path"), "fake.json") +def test_get_local_examples_path() -> None: + # Running test in repo will default to local path + assert get_examples_path() == local_examples_path + + +def test_get_examples_path_failure(mocker: MockFixture) -> None: + mocker.patch("pathlib.Path.exists", return_value=False) + + with pytest.raises(FileNotFoundError): + get_examples_path() + + @pytest.mark.skipif( os.getenv("GITHUB_ACTIONS") == "true", reason="Do not download 100MB dataset on GitHub Actions", ) -def test_download_examples(): +def test_download_examples() -> None: if downloaded_examples_path.exists(): shutil.rmtree(downloaded_examples_path)