From 17aa3c00dc93048d9af695b2788088f772d9f5d2 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 24 May 2020 22:52:00 +0200 Subject: [PATCH] more tests --- python/damask/_geom.py | 2 +- python/tests/test_Geom.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 26a7611c5..12dbcc181 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -612,12 +612,12 @@ class Geom: def canvas(self,grid=None,offset=None,fill=None): """Crop or enlarge/pad microstructure.""" if fill is None: fill = np.nanmax(self.microstructure) + 1 + if offset is None: offset = 0 dtype = float if np.isnan(fill) or int(fill) != fill or self.microstructure.dtype==np.float else int canvas = np.full(self.grid if grid is None else grid, fill if fill is not None else np.nanmax(self.microstructure)+1, self.microstructure.dtype) - if offset is None: offset = 0 l = np.clip( offset, 0,np.minimum(self.grid +offset,grid)) # noqa r = np.clip( offset+self.grid,0,np.minimum(self.grid*2+offset,grid)) diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index e3aaf84a9..7a3823ab3 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -37,6 +37,7 @@ class TestGeom: default.get_size(), default.get_origin() ) + print(modified) assert geom_equal(modified,default) @@ -58,6 +59,22 @@ class TestGeom: new = Geom.from_file(tmpdir.join('default.geom')) assert geom_equal(new,default) + def test_invalid_combination(self,default): + with pytest.raises(ValueError): + default.update(default.microstructure[1:,1:,1:],size=np.ones(3), rescale=True) + + def test_invalid_size(self,default): + with pytest.raises(ValueError): + default.update(default.microstructure[1:,1:,1:],size=np.ones(2)) + + def test_invalid_microstructure(self,default): + with pytest.raises(ValueError): + default.update(default.microstructure[1]) + + def test_invalid_homogenization(self,default): + with pytest.raises(TypeError): + default.set_homogenization(homogenization=0) + @pytest.mark.parametrize('directions,reflect',[ (['x'], False), (['x','y','z'],True), @@ -122,7 +139,7 @@ class TestGeom: @pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]), np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])]) - def test_rotate90(self,default,axis_angle): + def test_rotate360(self,default,axis_angle): modified = copy.deepcopy(default) for i in range(np.rint(360/axis_angle[3]).astype(int)): modified.rotate(Rotation.from_axis_angle(axis_angle,degrees=True)) @@ -138,6 +155,12 @@ class TestGeom: if update: modified.to_file(reference) assert geom_equal(modified,Geom.from_file(reference)) + def test_canvas(self,default): + grid_add = np.random.randint(0,30,(3)) + modified = copy.deepcopy(default) + modified.canvas(modified.grid + grid_add) + e = default.grid + assert np.all(modified.microstructure[:e[0],:e[1],:e[2]] == default.microstructure) @pytest.mark.parametrize('periodic',[True,False]) def test_tessellation_approaches(self,periodic):