Skip to content

Commit

Permalink
Merge branch '254-testing-resources-folder-name' into 'development'
Browse files Browse the repository at this point in the history
more reasonable name

Closes #254

See merge request damask/DAMASK!758
  • Loading branch information
eisenlohr committed May 1, 2023
2 parents da9b3c5 + e62d1ac commit 4eb5577
Show file tree
Hide file tree
Showing 179 changed files with 159 additions and 158 deletions.
8 changes: 4 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
*.pbz2 binary

# ignore files from MSC.Marc in language statistics
install/MarcMentat/** linguist-vendored
src/Marc/include/* linguist-vendored
install/MarcMentat/** linguist-vendored
src/Marc/include/* linguist-vendored
install/MarcMentat/MSC_modifications.py linguist-vendored=false

# ignore reference files for tests in language statistics
python/tests/reference/** linguist-vendored
python/tests/resources/** linguist-vendored

# ignore deprecated scripts
processing/legacy/** linguist-vendored
processing/legacy/** linguist-vendored
2 changes: 1 addition & 1 deletion PRIVATE
6 changes: 3 additions & 3 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def update(request):


@pytest.fixture
def ref_path_base():
"""Directory containing reference results."""
return Path(__file__).parent/'reference'
def res_path_base():
"""Directory containing testing resources."""
return Path(__file__).parent/'resources'


@pytest.fixture
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions python/tests/resources/Grid/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
n10-id1_scaled.vtk binary
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions python/tests/test_Colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from damask import Colormap

@pytest.fixture
def ref_path(ref_path_base):
"""Directory containing reference results."""
return ref_path_base/'Colormap'
def res_path(res_path_base):
"""Directory containing testing resources."""
return res_path_base/'Colormap'

class TestColormap:

Expand Down Expand Up @@ -156,13 +156,13 @@ def test_at_value(self, N, cmap, at, result):
rtol=0.005)

@pytest.mark.parametrize('bounds',[None,[2,10]])
def test_shade(self,ref_path,update,bounds):
def test_shade(self,res_path,update,bounds):
data = np.add(*np.indices((10, 11)))
img_current = Colormap.from_predefined('orientation').shade(data,bounds=bounds)
if update:
img_current.save(ref_path/f'shade_{bounds}.png')
img_current.save(res_path/f'shade_{bounds}.png')
else:
img_reference = Image.open(ref_path/f'shade_{bounds}.png')
img_reference = Image.open(res_path/f'shade_{bounds}.png')
diff = ImageChops.difference(img_reference.convert('RGB'),img_current.convert('RGB'))
assert not diff.getbbox()

Expand All @@ -174,14 +174,14 @@ def test_predefined(self):
('GOM','.legend'),
('gmsh','.msh')
])
def test_compare_reference(self,format,ext,tmp_path,ref_path,update):
def test_compare_reference(self,format,ext,tmp_path,res_path,update):
name = 'binary'
c = Colormap.from_predefined(name) # noqa
if update:
os.chdir(ref_path)
os.chdir(res_path)
eval(f'c.save_{format}()')
else:
os.chdir(tmp_path)
eval(f'c.save_{format}()')
time.sleep(.5)
assert filecmp.cmp(tmp_path/(name+ext),ref_path/(name+ext))
assert filecmp.cmp(tmp_path/(name+ext),res_path/(name+ext))
76 changes: 38 additions & 38 deletions python/tests/test_ConfigMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from damask import Grid

@pytest.fixture
def ref_path(ref_path_base):
"""Directory containing reference results."""
return ref_path_base/'ConfigMaterial'
def res_path(res_path_base):
"""Directory containing testing resources."""
return res_path_base/'ConfigMaterial'


class TestConfigMaterial:
Expand All @@ -38,8 +38,8 @@ def test_init_some(self,kwargs):
if k in kwargs: assert v == kwargs[k]

@pytest.mark.parametrize('fname',[None,'test.yaml'])
def test_load_save(self,ref_path,tmp_path,fname):
reference = ConfigMaterial.load(ref_path/'material.yaml')
def test_load_save(self,res_path,tmp_path,fname):
reference = ConfigMaterial.load(res_path/'material.yaml')
os.chdir(tmp_path)
if fname is None:
reference.save()
Expand All @@ -49,60 +49,60 @@ def test_load_save(self,ref_path,tmp_path,fname):
new = ConfigMaterial.load(fname)
assert reference == new

def test_valid_complete(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_valid_complete(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
assert material_config.is_valid and material_config.is_complete

def test_invalid_lattice(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_invalid_lattice(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
material_config['phase']['Aluminum']['lattice']='fxc'
assert not material_config.is_valid

def test_invalid_orientation(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_invalid_orientation(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
material_config['material'][0]['constituents'][0]['O']=[0,0,0,0]
assert not material_config.is_valid

@pytest.mark.xfail(sys.platform == 'win32', reason='utf8 "not equal" might cause trouble')
def test_invalid_fraction(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_invalid_fraction(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
material_config['material'][0]['constituents'][0]['v']=.9
assert not material_config.is_valid

@pytest.mark.parametrize('item',['homogenization','phase','material'])
def test_incomplete_missing(self,ref_path,item):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_incomplete_missing(self,res_path,item):
material_config = ConfigMaterial.load(res_path/'material.yaml')
del material_config[item]
assert not material_config.is_complete

@pytest.mark.parametrize('item',['O','phase'])
def test_incomplete_material_constituent(self,ref_path,item):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_incomplete_material_constituent(self,res_path,item):
material_config = ConfigMaterial.load(res_path/'material.yaml')
del material_config['material'][0]['constituents'][0][item]
assert not material_config.is_complete

def test_incomplete_material_homogenization(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_incomplete_material_homogenization(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
del material_config['material'][0]['homogenization']
assert not material_config.is_complete

def test_incomplete_wrong_phase(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_incomplete_wrong_phase(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
new = material_config.material_rename_phase({'Steel':'FeNbC'})
assert not new.is_complete

def test_incomplete_wrong_homogenization(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_incomplete_wrong_homogenization(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
new = material_config.material_rename_homogenization({'Taylor':'isostrain'})
assert not new.is_complete

def test_empty_phase(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_empty_phase(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
material_config['phase'] = None
assert not material_config.is_complete

def test_empty_homogenization(self,ref_path):
material_config = ConfigMaterial.load(ref_path/'material.yaml')
def test_empty_homogenization(self,res_path):
material_config = ConfigMaterial.load(res_path/'material.yaml')
material_config['homogenization'] = None
assert not material_config.is_complete

Expand All @@ -118,9 +118,9 @@ def test_from_table(self):
for i,m in enumerate(c['material']):
assert m['homogenization'] == 1 and (m['constituents'][0]['O'] == [0,1,0,0]).all()

def test_updated_dicts(self,ref_path):
def test_updated_dicts(self,res_path):
m1 = ConfigMaterial().material_add(phase=['Aluminum'],O=[1.0,0.0,0.0,0.0],homogenization='SX')
m2 = ConfigMaterial.load(ref_path/'material.yaml')
m2 = ConfigMaterial.load(res_path/'material.yaml')
for k in m2['phase']:
m2 = m2.material_add(phase=[k],O=[1.0,0.0,0.0,0.0],homogenization='SX')
assert not m2['phase'].get(k) is None
Expand Down Expand Up @@ -173,17 +173,17 @@ def test_material_add_invalid_v(self,v):
ConfigMaterial().material_add(v=v)

@pytest.mark.parametrize('cell_ensemble_data',[None,'CellEnsembleData'])
def test_load_DREAM3D(self,ref_path,cell_ensemble_data):
grain_c = ConfigMaterial.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d','Grain Data',
def test_load_DREAM3D(self,res_path,cell_ensemble_data):
grain_c = ConfigMaterial.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d','Grain Data',
cell_ensemble_data = cell_ensemble_data)
point_c = ConfigMaterial.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d',
point_c = ConfigMaterial.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d',
cell_ensemble_data = cell_ensemble_data)

assert point_c.is_valid and grain_c.is_valid and \
len(point_c['material'])+1 == len(grain_c['material'])

grain_m = Grid.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d','FeatureIds').material.flatten()
point_m = Grid.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d').material.flatten()
grain_m = Grid.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d','FeatureIds').material.flatten()
point_m = Grid.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d').material.flatten()

for i in np.unique(point_m):
j = int(grain_m[(point_m==i).nonzero()[0][0]])
Expand All @@ -193,11 +193,11 @@ def test_load_DREAM3D(self,ref_path,cell_ensemble_data):
grain_c['material'][j]['constituents'][0]['phase']


def test_load_DREAM3D_reference(self,tmp_path,ref_path,update):
cur = ConfigMaterial.load_DREAM3D(ref_path/'measured.dream3d')
ref = ConfigMaterial.load(ref_path/'measured.material.yaml')
def test_load_DREAM3D_reference(self,tmp_path,res_path,update):
cur = ConfigMaterial.load_DREAM3D(res_path/'measured.dream3d')
ref = ConfigMaterial.load(res_path/'measured.material.yaml')
if update:
cur.save(ref_path/'measured.material.yaml')
cur.save(res_path/'measured.material.yaml')
for i,m in enumerate(ref['material']):
assert Rotation(m['constituents'][0]['O']).isclose(Rotation(cur['material'][i]['constituents'][0]['O']))
assert cur.is_valid and cur['phase'] == ref['phase'] and cur['homogenization'] == ref['homogenization']
56 changes: 28 additions & 28 deletions python/tests/test_Grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def random():
return Grid.from_Voronoi_tessellation(cells,size,s)

@pytest.fixture
def ref_path(ref_path_base):
"""Directory containing reference results."""
return ref_path_base/'Grid'
def res_path(res_path_base):
"""Directory containing testing resources."""
return res_path_base/'Grid'


class TestGrid:
Expand Down Expand Up @@ -116,10 +116,10 @@ def test_invalid_materials_type(self,default):
(['y','z'], False)
]
)
def test_mirror(self,default,update,ref_path,directions,reflect):
def test_mirror(self,default,update,res_path,directions,reflect):
modified = default.mirror(directions,reflect)
tag = f'directions_{"-".join(directions)}+reflect_{reflect}'
reference = ref_path/f'mirror_{tag}.vti'
reference = res_path/f'mirror_{tag}.vti'
if update: modified.save(reference)
assert Grid.load(reference) == modified

Expand All @@ -141,10 +141,10 @@ def test_mirror_order_invariant(self,default,reflect):
['y','z'],
]
)
def test_flip(self,default,update,ref_path,directions):
def test_flip(self,default,update,res_path,directions):
modified = default.flip(directions)
tag = f'directions_{"-".join(directions)}'
reference = ref_path/f'flip_{tag}.vti'
reference = res_path/f'flip_{tag}.vti'
if update: modified.save(reference)
assert Grid.load(reference) == modified

Expand Down Expand Up @@ -175,9 +175,9 @@ def test_flip_invalid(self,default,directions):
@pytest.mark.parametrize('distance',[1.,np.sqrt(3)])
@pytest.mark.parametrize('selection',[None,1,[1],[1,2,3]])
@pytest.mark.parametrize('periodic',[True,False])
def test_clean_reference(self,default,update,ref_path,distance,selection,periodic):
def test_clean_reference(self,default,update,res_path,distance,selection,periodic):
current = default.clean(distance,selection,periodic=periodic,rng_seed=0)
reference = ref_path/f'clean_{distance}_{util.srepr(selection,"+")}_{periodic}.vti'
reference = res_path/f'clean_{distance}_{util.srepr(selection,"+")}_{periodic}.vti'
if update:
current.save(reference)
assert Grid.load(reference) == current
Expand All @@ -202,10 +202,10 @@ def test_clean_selection_empty(self,random):
np.array((10,20,2))
]
)
def test_scale(self,default,update,ref_path,cells):
def test_scale(self,default,update,res_path,cells):
modified = default.scale(cells)
tag = f'grid_{util.srepr(cells,"-")}'
reference = ref_path/f'scale_{tag}.vti'
reference = res_path/f'scale_{tag}.vti'
if update: modified.save(reference)
assert Grid.load(reference) == modified

Expand Down Expand Up @@ -264,10 +264,10 @@ def test_rotate360(self,default,axis_angle):

@pytest.mark.parametrize('Eulers',[[32.0,68.0,21.0],
[0.0,32.0,240.0]])
def test_rotate(self,default,update,ref_path,Eulers):
def test_rotate(self,default,update,res_path,Eulers):
modified = default.rotate(Rotation.from_Euler_angles(Eulers,degrees=True))
tag = f'Eulers_{util.srepr(Eulers,"-")}'
reference = ref_path/f'rotate_{tag}.vti'
reference = res_path/f'rotate_{tag}.vti'
if update: modified.save(reference)
assert Grid.load(reference) == modified

Expand Down Expand Up @@ -471,39 +471,39 @@ def test_from_table_recover(self,tmp_path):
@pytest.mark.parametrize('periodic',[True,False])
@pytest.mark.parametrize('direction',['x','y','z',['x','y'],'zy','xz',['x','y','z']])
@pytest.mark.xfail(vtkVersion.GetVTKMajorVersion()<8, reason='missing METADATA')
def test_get_grain_boundaries(self,update,ref_path,periodic,direction):
grid = Grid.load(ref_path/'get_grain_boundaries_8g12x15x20.vti')
def test_get_grain_boundaries(self,update,res_path,periodic,direction):
grid = Grid.load(res_path/'get_grain_boundaries_8g12x15x20.vti')
current = grid.get_grain_boundaries(periodic,direction)
if update:
current.save(ref_path/f'get_grain_boundaries_8g12x15x20_{direction}_{periodic}.vtu',parallel=False)
reference = VTK.load(ref_path/f'get_grain_boundaries_8g12x15x20_{"".join(direction)}_{periodic}.vtu')
current.save(res_path/f'get_grain_boundaries_8g12x15x20_{direction}_{periodic}.vtu',parallel=False)
reference = VTK.load(res_path/f'get_grain_boundaries_8g12x15x20_{"".join(direction)}_{periodic}.vtu')
assert current.__repr__() == reference.__repr__()

@pytest.mark.parametrize('directions',[(1,2,'y'),('a','b','x'),[1]])
def test_get_grain_boundaries_invalid(self,default,directions):
with pytest.raises(ValueError):
default.get_grain_boundaries(directions=directions)

def test_load_DREAM3D(self,ref_path):
grain = Grid.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d','FeatureIds')
point = Grid.load_DREAM3D(ref_path/'2phase_irregularGrid.dream3d')
def test_load_DREAM3D(self,res_path):
grain = Grid.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d','FeatureIds')
point = Grid.load_DREAM3D(res_path/'2phase_irregularGrid.dream3d')

assert np.allclose(grain.origin,point.origin) and \
np.allclose(grain.size,point.size) and \
(grain.sort().material == point.material+1).all()

def test_load_DREAM3D_reference(self,ref_path,update):
current = Grid.load_DREAM3D(ref_path/'measured.dream3d')
reference = Grid.load(ref_path/'measured.vti')
def test_load_DREAM3D_reference(self,res_path,update):
current = Grid.load_DREAM3D(res_path/'measured.dream3d')
reference = Grid.load(res_path/'measured.vti')
if update:
current.save(ref_path/'measured.vti')
current.save(res_path/'measured.vti')

assert current == reference

def test_load_Neper_reference(self,ref_path,update):
current = Grid.load_Neper(ref_path/'n10-id1_scaled.vtk')
reference = Grid.load(ref_path/'n10-id1_scaled.vti')
def test_load_Neper_reference(self,res_path,update):
current = Grid.load_Neper(res_path/'n10-id1_scaled.vtk')
reference = Grid.load(res_path/'n10-id1_scaled.vti')
if update:
current.save(ref_path/'n10-id1_scaled.vti')
current.save(res_path/'n10-id1_scaled.vti')

assert current == reference
Loading

0 comments on commit 4eb5577

Please sign in to comment.