Example #1
0
def test_text_to_matrix_mixed():
    """
    Check that text_to_matrix works with mixed separators
    """
    text = "1\t2   3\n4  ,  5, \t 6\n"
    mat = text_to_matrix(text)
    assert(np.all(mat == [[1, 2, 3], [4, 5, 6]]))
Example #2
0
def test_text_to_matrix_tabs():
    """
    Check that text_to_matrix works with tab separated data
    """
    text = "1\t2\t3\n4\t 5\t 6\n"
    mat = text_to_matrix(text)
    assert(np.all(mat == [[1, 2, 3], [4, 5, 6]]))
Example #3
0
def test_text_to_matrix_comma():
    """
    Check that text_to_matrix works with comma separated data
    """
    text = "1, 2, 3\n4,5,6\n"
    mat = text_to_matrix(text)
    assert(np.all(mat == [[1, 2, 3], [4, 5, 6]]))
Example #4
0
def test_text_to_matrix_spaces():
    """
    Check that text_to_matrix works with space separated data
    """
    text = "1 2 3\n4 5 6\n"
    mat = text_to_matrix(text)
    assert(np.all(mat == [[1, 2, 3], [4, 5, 6]]))
Example #5
0
def test_matrix_save():
    """ 
    Test 2D matrices are saved in the savedir
    """
    tempdir = tempfile.mkdtemp("_oxasl")
    try:
        wsp = Workspace(savedir=tempdir)
        mat = np.random.rand(4, 4)
        wsp.testmat = mat
        path = os.path.join(tempdir, "testmat.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)
Example #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)
Example #7
0
def test_text_to_matrix_not_numbers():
    text = "1 x 3\n4 5 6\n"
    with pytest.raises(ValueError):
        mat = text_to_matrix(text)
Example #8
0
def test_text_to_matrix_not_matrix():
    text = "1 2 3\n4 5\n"
    with pytest.raises(ValueError):
        mat = text_to_matrix(text)