import numpy as np
import pandas as pd
from numpy.testing import assert_equal

from .. import locator


def test_locate_peaks():

    challenge = [
        ([(60, 60, 50)], ("L Cereb WM", 95)),
        ([(62, 69, 50)], ("MFG", 20)),
        ([(31, 50, 27)], ("Parahip G, post", 30)),
        ([(26, 55, 27)], ("Temp Fus Ctx, post", 3)),
        ([(29, 50, 30)], ("R Hippocampus", 95))]

    for coord, res in challenge:
        res = dict(zip(["MaxProb Region", "Prob"], list(res)))
        print res
        res = pd.DataFrame(res, index=[0])
        yield assert_equal, np.array(res), np.array(locator.locate_peaks(coord))


def test_shorten_name():

    names = [("Parahippocampal Gyrus, anterior division",
              "Parahip G, ant",
              "ctx"),
             ("Middle Frontal Gyrus", "MFG", "ctx"),
             ("Right Hippocampus", "R Hippocampus", "sub")]

    for orig, new, atlas in names:
        yield assert_equal, new, locator.shorten_name(orig, atlas)


def test_vox_to_mni():

    coords = [((29, 68, 57), (32, 10, 42)),
              ((70, 38, 42), (-50, -50, 12)),
              ((45, 63, 36), (0, 0, 0))]

    for vox, mni in coords:
        vox = np.atleast_2d(vox)
        mni = np.atleast_2d(mni)
        yield assert_equal, mni, locator.vox_to_mni(vox)

@@ -1,12 +1,22 @@
+import os%0A
 import numpy
@@ -42,16 +42,55 @@
 s as pd%0A
+from nose.plugins.skip import SkipTest%0A
 from num
@@ -170,16 +170,128 @@
 peaks():
+%0A    %22%22%22Test that known peaks are located properly.%22%22%22%0A    if %22FSLDIR%22 not in os.environ:%0A        raise SkipTest
 %0A%0A    ch
@@ -802,24 +802,89 @@
 ten_name():%0A
+    %22%22%22Test that verbose Harvard Oxford ROI names are shorted.%22%22%22
 %0A    names =
@@ -1224,16 +1224,139 @@
 o_mni():
+%0A    %22%22%22Test the voxel index to MNI coordinate transformation.%22%22%22%0A    if %22FSLDIR%22 not in os.environ:%0A        raise SkipTest
 %0A%0A    co

Make locator tests more robust to missing FSL install