def test_label_io(): """Test IO of label files.""" tempdir = _TempDir() label = read_label(label_fname) # label attributes assert_equal(label.name, 'test-lh') assert_is(label.subject, None) assert_is(label.color, None) # save and reload label.save(op.join(tempdir, 'foo')) label2 = read_label(op.join(tempdir, 'foo-lh.label')) assert_labels_equal(label, label2) # pickling dest = op.join(tempdir, 'foo.pickled') with open(dest, 'wb') as fid: pickle.dump(label, fid, pickle.HIGHEST_PROTOCOL) with open(dest, 'rb') as fid: label2 = pickle.load(fid) assert_labels_equal(label, label2)
def test_label_io(): """Test IO of label files.""" tempdir = _TempDir() label = read_label(label_fname) # label attributes assert_equal(label.name, 'test-lh') assert_is(label.subject, None) assert_is(label.color, None) # save and reload label.save(op.join(tempdir, 'foo')) label2 = read_label(op.join(tempdir, 'foo-lh.label')) assert_labels_equal(label, label2) # pickling dest = op.join(tempdir, 'foo.pickled') with open(dest, 'wb') as fid: pickle.dump(label, fid, pickle.HIGHEST_PROTOCOL) with open(dest, 'rb') as fid: label2 = pickle.load(fid) assert_labels_equal(label, label2)
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")