Skip to content

Commit

Permalink
✨ Add downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Nov 23, 2023
1 parent 3ec9db9 commit 338f721
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions bananalyzer/data/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit 338f721

Please sign in to comment.