Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make list atlas function more robust #417

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions brainglobe_atlasapi/list_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Some functionality to list all available and downloaded brainglobe atlases
"""

import re

from rich import print as rprint
from rich.panel import Panel
from rich.table import Table
Expand Down Expand Up @@ -43,11 +45,15 @@ def get_local_atlas_version(atlas_name):
"""

brainglobe_dir = config.get_brainglobe_dir()
return [
f.name.split("_v")[1]
for f in brainglobe_dir.glob(f"*{atlas_name}*")
if f.is_dir()
][0]
try:
return [
re.search(r"_v(\d+\.\d+)$", f.name).group(1)
for f in brainglobe_dir.glob(f"*{atlas_name}*")
if f.is_dir() and re.search(r"_v(\d+\.\d+)$", f.name)
][0]
except IndexError:
print(f"No atlas found with the name: {atlas_name}")
return None
adamltyson marked this conversation as resolved.
Show resolved Hide resolved


def get_all_atlases_lastversions():
Expand Down
10 changes: 8 additions & 2 deletions tests/atlasapi/test_list_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ def test_get_downloaded_atlases():
assert "example_mouse_100um" in available_atlases


def test_get_local_atlas_version():
def test_get_local_atlas_version_real_atlas():
v = get_local_atlas_version("example_mouse_100um")

assert len(v.split(".")) == 2


def test_get_local_atlas_version_missing_atlas(capsys):
atlas_name = "unicorn_atlas"
assert get_local_atlas_version(atlas_name) is None
captured = capsys.readouterr()
assert f"No atlas found with the name: {atlas_name}" in captured.out


def test_lastversions():
last_versions = get_atlases_lastversions()
example_atlas = last_versions["example_mouse_100um"]
Expand Down
Loading