Example #1
0
    def test_save_item(self, tmpdir):
        schema_node = schema.Bool()
        storage_path = str(tmpdir.join('test_save_item.mat'))
        mat_file = mat.Storage(storage_path=storage_path,
                               schema_node=schema_node)
        mat_file.data.value = True
        mat_file.save()

        file_ = sio.loadmat(storage_path, squeeze_me=True)
        assert 'schema' in file_
        assert file_['schema'] == json.dumps(schema_node.to_dict(),
                                             sort_keys=True)
        assert 'data' in file_
        assert file_['data']
Example #2
0
    def test_load_list(self, tmpdir):
        schema_node = schema.List(schema.Bool())
        schema_data = json.dumps(schema_node.to_dict(), sort_keys=True)
        storage_path = str(tmpdir.join('test_load_list.mat'))
        data = np.zeros((2, ), dtype=np.object)
        data[0] = np.array([True])
        data[1] = np.array([False])
        test_data = {'data': data, 'schema': schema_data}
        sio.savemat(storage_path, test_data)

        mat_file = mat.Storage(storage_path=storage_path)
        assert hasattr(mat_file, 'data')
        assert isinstance(mat_file.data, mat.List)
        assert mat_file.data[0].value is True
        assert mat_file.data[1].value is False
Example #3
0
    def test_save_list(self, tmpdir):
        schema_node = schema.List(schema.Bool())
        storage_path = str(tmpdir.join('test_save_list.mat'))
        mat_file = mat.Storage(storage_path=storage_path,
                               schema_node=schema_node)
        mat_file.data.replace([True, False])
        mat_file.save()

        file_ = sio.loadmat(storage_path, squeeze_me=True)
        assert 'schema' in file_
        assert file_['schema'] == json.dumps(schema_node.to_dict(),
                                             sort_keys=True)
        assert 'data' in file_
        assert len(file_['data']) == 2
        assert file_['data'][0]
        assert not file_['data'][1]
Example #4
0
    def test_save_compilation(self, tmpdir):
        schema_node = schema.Compilation({
            'spam': schema.Bool(),
            'eggs': schema.Bool()
        })
        storage_path = str(tmpdir.join('test_save_compilation.mat'))
        mat_file = mat.Storage(storage_path=storage_path,
                               schema_node=schema_node)
        mat_file.data.spam.value = True
        mat_file.data.eggs.value = False
        mat_file.save()

        file_ = sio.loadmat(storage_path, squeeze_me=True)
        assert 'schema' in file_
        assert file_['schema'] == json.dumps(schema_node.to_dict(),
                                             sort_keys=True)
        assert 'data' in file_
        assert 'spam' in file_['data'].dtype.fields
        assert file_['data']['spam']
        assert 'eggs' in file_['data'].dtype.fields
        assert not file_['data']['eggs']
Example #5
0
    def test_load_compilation(self, tmpdir):
        schema_node = schema.Compilation({
            'spam': schema.Bool(),
            'eggs': schema.Bool()
        })
        schema_data = json.dumps(schema_node.to_dict(), sort_keys=True)
        storage_path = str(tmpdir.join('test_load_compilation.mat'))
        test_data = {
            'data': {
                'spam': np.array([True]),
                'eggs': np.array([False])
            },
            'schema': schema_data
        }
        sio.savemat(storage_path, test_data)

        mat_file = mat.Storage(storage_path=storage_path)
        assert hasattr(mat_file, 'data')
        assert hasattr(mat_file.data, 'spam')
        assert hasattr(mat_file.data, 'eggs')
        assert isinstance(mat_file.data.spam, mat.Bool)
        assert isinstance(mat_file.data.eggs, mat.Bool)
        assert mat_file.data.spam.value is True
        assert mat_file.data.eggs.value is False