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

Added tests for lookup and hierarchy #50

Merged
merged 1 commit into from Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/test_core_atlas.py
@@ -1,6 +1,9 @@
import pytest

import pandas as pd
import numpy as np
import contextlib
from io import StringIO


def test_initialization(atlas):
Expand Down Expand Up @@ -55,6 +58,7 @@ def test_data_from_coords(atlas, coords):
assert atlas.structure_from_coords(coords) == 997
assert atlas.structure_from_coords(coords, as_acronym=True) == "root"
assert atlas.hemisphere_from_coords(coords) == 0
assert atlas.hemisphere_from_coords(coords, as_string=True) == "left"


def test_meshfile_from_id(atlas):
Expand All @@ -74,3 +78,31 @@ def test_mesh_from_id(atlas):

mesh = atlas.root_mesh()
assert np.allclose(mesh.points[0], [7896.56, 3384.15, 503.781])


def test_lookup(atlas):
df_lookup = atlas.lookup
df = pd.DataFrame(
dict(
acronym=["root", "grey", "CH"],
id=[997, 8, 567],
name=["root", "Basic cell groups and regions", "Cerebrum"],
)
)

assert all(df_lookup == df)


def test_hierarchy(atlas):
hier = atlas.hierarchy
temp_stdout = StringIO()
with contextlib.redirect_stdout(temp_stdout):
print(hier)
output = temp_stdout.getvalue().strip()
assert output == "root\n└── grey\n └── CH"

assert {k: v.tag for k, v in hier.nodes.items()} == {
997: "root",
8: "grey",
567: "CH",
}