Skip to content

Commit

Permalink
Make list atlas function more robust (#417)
Browse files Browse the repository at this point in the history
* Make list atlas function more robust

* Add tests
  • Loading branch information
adamltyson authored Oct 29, 2024
1 parent e718f4c commit 04043bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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


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

0 comments on commit 04043bc

Please sign in to comment.