コード例 #1
0
def test_custom_save_nosave():
    """ 
    Test matrices are saved in the savedir with the specified name
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        mat = np.random.rand(4, 4)
        wsp.set_item("testmat", mat, save_fn=_custom_save, save=False)
        path = os.path.join(tempdir, "testmat")
        assert(not os.path.exists(path))
    finally:
        shutil.rmtree(tempdir)
コード例 #2
0
def test_matrix_nosave():
    """ 
    Test setting an matrix without saving
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        mat = np.random.rand(4, 4)
        wsp.set_item("testmat", mat, save=False)
        path = os.path.join(tempdir, "testmat.mat")
        assert(not os.path.exists(path))
        assert(np.all(mat == wsp.testmat))
    finally:
        shutil.rmtree(tempdir)
コード例 #3
0
def test_image_nosave():
    """ 
    Test setting an image without saving
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        img = Image(np.random.rand(5, 5, 5))
        wsp.set_item("testimg", img, save=False)
        path = os.path.join(tempdir, "testimg.nii.gz")
        assert(not os.path.exists(path))
        assert(np.all(img.data == wsp.testimg.data))
    finally:
        shutil.rmtree(tempdir)
コード例 #4
0
def test_custom_save_name():
    """ 
    Test matrices are saved in the savedir with the specified name
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        mat = np.random.rand(4, 4)
        wsp.set_item("testmat", mat, save_name="potato", save_fn=_custom_save)
        path = os.path.join(tempdir, "testmat")
        assert(not os.path.exists(path))
        path = os.path.join(tempdir, "potato")
        assert(os.path.exists(path))
        with open(path) as sfile:
            assert("Custom Save" == sfile.read())
    finally:
        shutil.rmtree(tempdir)
コード例 #5
0
def test_image_save_name():
    """ 
    Test images are saved in the savedir with the specified name
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        img = Image(np.random.rand(5, 5, 5))
        wsp.set_item("testimg", img, save_name="pumpkin")
        path = os.path.join(tempdir, "testimg.nii.gz")
        assert(not os.path.exists(path))
        path = os.path.join(tempdir, "pumpkin.nii.gz")
        assert(os.path.isfile(path))
        otherimg = Image(path)
        assert(np.all(img.data == wsp.testimg.data))
        assert(np.all(img.data == otherimg.data))
    finally:
        shutil.rmtree(tempdir)
コード例 #6
0
def test_matrix_save_name():
    """ 
    Test matrices are saved in the savedir with the specified name
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        mat = np.random.rand(4, 4)
        wsp.set_item("testmat", mat, save_name="parsnip")
        path = os.path.join(tempdir, "testmat.mat")
        assert(not os.path.exists(path))
        path = os.path.join(tempdir, "parsnip.mat")
        assert(os.path.isfile(path))
        with open(path) as matfile:
            othermat = text_to_matrix(matfile.read())
        assert(np.all(mat == wsp.testmat))
        assert(np.all(mat == othermat))
    finally:
        shutil.rmtree(tempdir)