Exemplo n.º 1
0
def test_fetch_haxby(tmp_path, request_mocker):

    request_mocker.url_mapping[re.compile(
        r".*(subj\d).*\.tar\.gz")] = _make_haxby_subject_data
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=str(tmp_path),
                                 subjects=[i],
                                 verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert request_mocker.url_count == i + 2
        assert len(haxby.func) == 1
        assert len(haxby.anat) == 1
        assert len(haxby.session_target) == 1
        assert haxby.mask is not None
        assert len(haxby.mask_vt) == 1
        assert len(haxby.mask_face) == 1
        assert len(haxby.mask_house) == 1
        assert len(haxby.mask_face_little) == 1
        assert len(haxby.mask_house_little) == 1
        assert haxby.description != ''

    # subjects with list
    subjects = [1, 2, 6]
    haxby = func.fetch_haxby(data_dir=str(tmp_path),
                             subjects=subjects,
                             verbose=0)
    assert len(haxby.func) == len(subjects)
    assert len(haxby.mask_house_little) == len(subjects)
    assert len(haxby.anat) == len(subjects)
    assert haxby.anat[2] is None
    assert isinstance(haxby.mask, str)
    assert len(haxby.mask_face) == len(subjects)
    assert len(haxby.session_target) == len(subjects)
    assert len(haxby.mask_vt) == len(subjects)
    assert len(haxby.mask_face_little) == len(subjects)

    subjects = ['a', 8]
    message = "You provided invalid subject id {0} in a list"

    for sub_id in subjects:
        with pytest.raises(ValueError, match=message.format(sub_id)):
            func.fetch_haxby(data_dir=str(tmp_path), subjects=[sub_id])
Exemplo n.º 2
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tst.tmpdir, subjects=[i],
                                 verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert_equal(len(tst.mock_url_request.urls), 1 + 2 * (i == 1))
        assert_equal(len(haxby.func), 1)
        assert_equal(len(haxby.anat), 1)
        assert_equal(len(haxby.session_target), 1)
        assert_true(haxby.mask is not None)
        assert_equal(len(haxby.mask_vt), 1)
        assert_equal(len(haxby.mask_face), 1)
        assert_equal(len(haxby.mask_house), 1)
        assert_equal(len(haxby.mask_face_little), 1)
        assert_equal(len(haxby.mask_house_little), 1)
        tst.mock_url_request.reset()
        assert_not_equal(haxby.description, '')

    # subjects with list
    subjects = [1, 2, 6]
    haxby = func.fetch_haxby(data_dir=tst.tmpdir, subjects=subjects,
                             verbose=0)
    assert_equal(len(haxby.func), len(subjects))
    assert_equal(len(haxby.mask_house_little), len(subjects))
    assert_equal(len(haxby.anat), len(subjects))
    assert_true(haxby.anat[2] is None)
    assert_true(isinstance(haxby.mask, _basestring))
    assert_equal(len(haxby.mask_face), len(subjects))
    assert_equal(len(haxby.session_target), len(subjects))
    assert_equal(len(haxby.mask_vt), len(subjects))
    assert_equal(len(haxby.mask_face_little), len(subjects))

    subjects = ['a', 8]
    message = "You provided invalid subject id {0} in a list"

    for sub_id in subjects:
        assert_raises_regex(ValueError,
                            message.format(sub_id),
                            func.fetch_haxby,
                            data_dir=tst.tmpdir,
                            subjects=[sub_id])
Exemplo n.º 3
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tst.tmpdir, subjects=[i],
                                 verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert_equal(len(tst.mock_url_request.urls), 1 + 2 * (i == 1))
        assert_equal(len(haxby.func), 1)
        assert_equal(len(haxby.anat), 1)
        assert_equal(len(haxby.session_target), 1)
        assert_true(haxby.mask is not None)
        assert_equal(len(haxby.mask_vt), 1)
        assert_equal(len(haxby.mask_face), 1)
        assert_equal(len(haxby.mask_house), 1)
        assert_equal(len(haxby.mask_face_little), 1)
        assert_equal(len(haxby.mask_house_little), 1)
        tst.mock_url_request.reset()
        assert_not_equal(haxby.description, '')

    # subjects with list
    subjects = [1, 2, 6]
    haxby = func.fetch_haxby(data_dir=tst.tmpdir, subjects=subjects,
                             verbose=0)
    assert_equal(len(haxby.func), len(subjects))
    assert_equal(len(haxby.mask_house_little), len(subjects))
    assert_equal(len(haxby.anat), len(subjects))
    assert_true(haxby.anat[2] is None)
    assert_true(isinstance(haxby.mask, _basestring))
    assert_equal(len(haxby.mask_face), len(subjects))
    assert_equal(len(haxby.session_target), len(subjects))
    assert_equal(len(haxby.mask_vt), len(subjects))
    assert_equal(len(haxby.mask_face_little), len(subjects))

    subjects = ['a', 8]
    message = "You provided invalid subject id {0} in a list"

    for sub_id in subjects:
        assert_raises_regex(ValueError,
                            message.format(sub_id),
                            func.fetch_haxby,
                            data_dir=tst.tmpdir,
                            subjects=[sub_id])
Exemplo n.º 4
0
def test_fetch_haxby(tmp_path, request_mocker):
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=str(tmp_path),
                                 subjects=[i],
                                 verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert len(tst.mock_url_request.urls) == 1 + 2 * (i == 1)
        assert len(haxby.func) == 1
        assert len(haxby.anat) == 1
        assert len(haxby.session_target) == 1
        assert haxby.mask is not None
        assert len(haxby.mask_vt) == 1
        assert len(haxby.mask_face) == 1
        assert len(haxby.mask_house) == 1
        assert len(haxby.mask_face_little) == 1
        assert len(haxby.mask_house_little) == 1
        tst.mock_url_request.reset()
        assert haxby.description != ''

    # subjects with list
    subjects = [1, 2, 6]
    haxby = func.fetch_haxby(data_dir=str(tmp_path),
                             subjects=subjects,
                             verbose=0)
    assert len(haxby.func) == len(subjects)
    assert len(haxby.mask_house_little) == len(subjects)
    assert len(haxby.anat) == len(subjects)
    assert haxby.anat[2] is None
    assert isinstance(haxby.mask, str)
    assert len(haxby.mask_face) == len(subjects)
    assert len(haxby.session_target) == len(subjects)
    assert len(haxby.mask_vt) == len(subjects)
    assert len(haxby.mask_face_little) == len(subjects)

    subjects = ['a', 8]
    message = "You provided invalid subject id {0} in a list"

    for sub_id in subjects:
        with pytest.raises(ValueError, match=message.format(sub_id)):
            func.fetch_haxby(data_dir=str(tmp_path), subjects=[sub_id])
Exemplo n.º 5
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tmpdir, n_subjects=i, verbose=0)
        assert_equal(len(mock_url_request.urls), 1 + (i == 1))  # subject_data + md5
        assert_equal(len(haxby.func), i)
        assert_equal(len(haxby.anat), i)
        assert_equal(len(haxby.session_target), i)
        assert_equal(len(haxby.mask_vt), i)
        assert_equal(len(haxby.mask_face), i)
        assert_equal(len(haxby.mask_house), i)
        assert_equal(len(haxby.mask_face_little), i)
        assert_equal(len(haxby.mask_house_little), i)
        mock_url_request.reset()
Exemplo n.º 6
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tmpdir, n_subjects=i, verbose=0)
        assert_equal(len(mock_url_request.urls),
                     1 + (i == 1))  # subject_data + md5
        assert_equal(len(haxby.func), i)
        assert_equal(len(haxby.anat), i)
        assert_equal(len(haxby.session_target), i)
        assert_equal(len(haxby.mask_vt), i)
        assert_equal(len(haxby.mask_face), i)
        assert_equal(len(haxby.mask_house), i)
        assert_equal(len(haxby.mask_face_little), i)
        assert_equal(len(haxby.mask_house_little), i)
        mock_url_request.reset()
Exemplo n.º 7
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tst.tmpdir, n_subjects=i, verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert_equal(len(tst.mock_url_request.urls), 1 + 2 * (i == 1))
        assert_equal(len(haxby.func), i)
        assert_equal(len(haxby.anat), i)
        assert_equal(len(haxby.session_target), i)
        assert_true(haxby.mask is not None)
        assert_equal(len(haxby.mask_vt), i)
        assert_equal(len(haxby.mask_face), i)
        assert_equal(len(haxby.mask_house), i)
        assert_equal(len(haxby.mask_face_little), i)
        assert_equal(len(haxby.mask_house_little), i)
        tst.mock_url_request.reset()
        assert_not_equal(haxby.description, '')
Exemplo n.º 8
0
def test_fetch_haxby():
    for i in range(1, 6):
        haxby = func.fetch_haxby(data_dir=tmpdir, n_subjects=i,
                                 verbose=0)
        # subject_data + (md5 + mask if first subj)
        assert_equal(len(mock_url_request.urls), 1 + 2 * (i == 1))
        assert_equal(len(haxby.func), i)
        assert_equal(len(haxby.anat), i)
        assert_equal(len(haxby.session_target), i)
        assert_true(haxby.mask is not None)
        assert_equal(len(haxby.mask_vt), i)
        assert_equal(len(haxby.mask_face), i)
        assert_equal(len(haxby.mask_house), i)
        assert_equal(len(haxby.mask_face_little), i)
        assert_equal(len(haxby.mask_house_little), i)
        mock_url_request.reset()
        assert_not_equal(haxby.description, '')