tests/specifications
This commit is contained in:
parent
572c3204d0
commit
1ff6a09746
|
@ -395,7 +395,7 @@ def DREAM3D_base_group(fname):
|
||||||
base_group = f.visit(lambda path: path.rsplit('/',2)[0] if '_SIMPL_GEOMETRY/SPACING' in path else None)
|
base_group = f.visit(lambda path: path.rsplit('/',2)[0] if '_SIMPL_GEOMETRY/SPACING' in path else None)
|
||||||
|
|
||||||
if base_group is None:
|
if base_group is None:
|
||||||
raise ValueError('Could not determine base group in file {fname}.')
|
raise ValueError(f'Could not determine base group in file {fname}.')
|
||||||
|
|
||||||
return base_group
|
return base_group
|
||||||
|
|
||||||
|
@ -415,13 +415,13 @@ def DREAM3D_cell_data_group(fname):
|
||||||
"""
|
"""
|
||||||
base_group = DREAM3D_base_group(fname)
|
base_group = DREAM3D_base_group(fname)
|
||||||
with h5py.File(fname,'r') as f:
|
with h5py.File(fname,'r') as f:
|
||||||
N_points = np.prod(f[os.path.join(base_group,'_SIMPL_GEOMETRY','DIMENSIONS')])
|
cells = tuple(f[os.path.join(base_group,'_SIMPL_GEOMETRY','DIMENSIONS')][()][::-1])
|
||||||
cell_data_group = f[base_group].visititems(lambda path,obj: path.split('/')[0] \
|
cell_data_group = f[base_group].visititems(lambda path,obj: path.split('/')[0] \
|
||||||
if isinstance(obj,h5py._hl.dataset.Dataset) and np.prod(np.shape(obj)) == N_points \
|
if isinstance(obj,h5py._hl.dataset.Dataset) and np.shape(obj)[:-1] == cells \
|
||||||
else None)
|
else None)
|
||||||
|
|
||||||
if cell_data_group is None:
|
if cell_data_group is None:
|
||||||
raise ValueError('Could not determine cell data group in file {fname}.')
|
raise ValueError(f'Could not determine cell data group in file {fname}/{base_group}.')
|
||||||
|
|
||||||
return cell_data_group
|
return cell_data_group
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
import random
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import stats
|
from scipy import stats
|
||||||
|
import h5py
|
||||||
|
|
||||||
from damask import util
|
from damask import util
|
||||||
|
|
||||||
|
@ -102,3 +106,36 @@ class TestUtil:
|
||||||
@pytest.mark.parametrize('style',[util.emph,util.deemph,util.warn,util.strikeout])
|
@pytest.mark.parametrize('style',[util.emph,util.deemph,util.warn,util.strikeout])
|
||||||
def test_decorate(self,style):
|
def test_decorate(self,style):
|
||||||
assert 'DAMASK' in style('DAMASK')
|
assert 'DAMASK' in style('DAMASK')
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('complete',[True,False])
|
||||||
|
def test_D3D_base_group(self,tmp_path,complete):
|
||||||
|
base_group = ''.join(random.choices('DAMASK', k=10))
|
||||||
|
with h5py.File(tmp_path/'base_group.dream3d','w') as f:
|
||||||
|
f.create_group(os.path.join(base_group,'_SIMPL_GEOMETRY'))
|
||||||
|
if complete:
|
||||||
|
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('SPACING',data=np.ones(3))
|
||||||
|
|
||||||
|
if complete:
|
||||||
|
assert base_group == util.DREAM3D_base_group(tmp_path/'base_group.dream3d')
|
||||||
|
else:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
util.DREAM3D_base_group(tmp_path/'base_group.dream3d')
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('complete',[True,False])
|
||||||
|
def test_D3D_cell_data_group(self,tmp_path,complete):
|
||||||
|
base_group = ''.join(random.choices('DAMASK', k=10))
|
||||||
|
cell_data_group = ''.join(random.choices('KULeuven', k=10))
|
||||||
|
cells = np.random.randint(1,50,3)
|
||||||
|
with h5py.File(tmp_path/'cell_data_group.dream3d','w') as f:
|
||||||
|
f.create_group(os.path.join(base_group,'_SIMPL_GEOMETRY'))
|
||||||
|
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('SPACING',data=np.ones(3))
|
||||||
|
f[os.path.join(base_group,'_SIMPL_GEOMETRY')].create_dataset('DIMENSIONS',data=cells[::-1])
|
||||||
|
f[base_group].create_group(cell_data_group)
|
||||||
|
if complete:
|
||||||
|
f[os.path.join(base_group,cell_data_group)].create_dataset('data',shape=np.append(cells,1))
|
||||||
|
|
||||||
|
if complete:
|
||||||
|
assert cell_data_group == util.DREAM3D_cell_data_group(tmp_path/'cell_data_group.dream3d')
|
||||||
|
else:
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
util.DREAM3D_cell_data_group(tmp_path/'cell_data_group.dream3d')
|
||||||
|
|
Loading…
Reference in New Issue