Пример #1
0
def test_io_dig_points():
    """Test Writing for dig files."""
    tempdir = _TempDir()
    points = _read_dig_points(hsp_fname)

    dest = op.join(tempdir, 'test.txt')
    dest_bad = op.join(tempdir, 'test.mne')
    pytest.raises(ValueError, _write_dig_points, dest, points[:, :2])
    pytest.raises(ValueError, _write_dig_points, dest_bad, points)
    _write_dig_points(dest, points)
    points1 = _read_dig_points(dest, unit='m')
    err = "Dig points diverged after writing and reading."
    assert_array_equal(points, points1, err)

    points2 = np.array([[-106.93, 99.80], [99.80, 68.81]])
    np.savetxt(dest, points2, delimiter='\t', newline='\n')
    pytest.raises(ValueError, _read_dig_points, dest)
Пример #2
0
def test_io_mrk():
    """Test IO for mrk files."""
    tempdir = _TempDir()
    pts = read_mrk(mrk_fname)

    # txt
    path = os.path.join(tempdir, 'mrk.txt')
    _write_dig_points(path, pts)
    pts_2 = read_mrk(path)
    assert_array_equal(pts, pts_2, "read/write mrk to text")

    # pickle
    fname = os.path.join(tempdir, 'mrk.pickled')
    with open(fname, 'wb') as fid:
        pickle.dump(dict(mrk=pts), fid)
    pts_2 = read_mrk(fname)
    assert_array_equal(pts_2, pts, "pickle mrk")
    with open(fname, 'wb') as fid:
        pickle.dump(dict(), fid)
    pytest.raises(ValueError, read_mrk, fname)

    # unsupported extension
    pytest.raises(ValueError, read_mrk, "file.ext")
Пример #3
0
def test_io_dig_points(tmpdir):
    """Test Writing for dig files."""
    points = _read_dig_points(hsp_fname)

    dest = str(tmpdir.join('test.txt'))
    dest_bad = str(tmpdir.join('test.mne'))
    with pytest.raises(ValueError, match='must be of shape'):
        _write_dig_points(dest, points[:, :2])
    with pytest.raises(ValueError, match='extension'):
        _write_dig_points(dest_bad, points)
    _write_dig_points(dest, points)
    points1 = _read_dig_points(dest, unit='m')
    err = "Dig points diverged after writing and reading."
    assert_array_equal(points, points1, err)

    points2 = np.array([[-106.93, 99.80], [99.80, 68.81]])
    np.savetxt(dest, points2, delimiter='\t', newline='\n')
    with pytest.raises(ValueError, match='must be of shape'):
        _read_dig_points(dest)