a test with reference results
This commit is contained in:
parent
ea4c4b6636
commit
2810531c97
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import damask
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--update",
|
||||
action="store_true",
|
||||
default=False)
|
||||
|
||||
@pytest.fixture
|
||||
def update(request):
|
||||
"""store current results as new reference results."""
|
||||
return request.config.getoption("--update")
|
||||
|
||||
@pytest.fixture
|
||||
def reference_dir_base():
|
||||
"""directory containing reference results."""
|
||||
env = damask.Environment()
|
||||
return os.path.join(env.rootDir(),'python','tests','reference')
|
|
@ -0,0 +1,35 @@
|
|||
4 header
|
||||
grid a 14 b 5 c 6
|
||||
size x 1.4e-05 y 5e-06 z 6e-06
|
||||
origin x 0.0 y 0.0 z 0.0
|
||||
homogenization 1
|
||||
1 1 2 22 2 2 1 21 1 2 2 22 2 1
|
||||
1 1 6 26 2 2 5 25 5 2 2 26 6 1
|
||||
1 1 10 30 2 2 9 29 9 2 2 30 10 1
|
||||
1 1 14 34 2 2 13 33 13 2 2 34 14 1
|
||||
1 1 18 38 2 2 17 37 17 2 2 38 18 1
|
||||
1 1 3 23 2 2 2 22 2 2 2 23 3 1
|
||||
1 1 7 27 2 2 6 26 6 2 2 27 7 1
|
||||
1 1 11 31 2 2 10 30 10 2 2 31 11 1
|
||||
1 1 15 35 2 2 14 34 14 2 2 35 15 1
|
||||
1 1 19 39 2 2 18 38 18 2 2 39 19 1
|
||||
1 1 4 24 2 2 3 23 3 2 2 24 4 1
|
||||
1 1 8 28 2 2 7 27 7 2 2 28 8 1
|
||||
1 1 12 32 2 2 11 31 11 2 2 32 12 1
|
||||
1 1 16 36 2 2 15 35 15 2 2 36 16 1
|
||||
1 1 20 40 2 2 19 39 19 2 2 40 20 1
|
||||
1 1 5 25 2 2 4 24 4 2 2 25 5 1
|
||||
1 1 9 29 2 2 8 28 8 2 2 29 9 1
|
||||
1 1 13 33 2 2 12 32 12 2 2 33 13 1
|
||||
1 1 17 37 2 2 16 36 16 2 2 37 17 1
|
||||
1 1 21 41 2 2 20 40 20 2 2 41 21 1
|
||||
1 1 4 24 2 2 3 23 3 2 2 24 4 1
|
||||
1 1 8 28 2 2 7 27 7 2 2 28 8 1
|
||||
1 1 12 32 2 2 11 31 11 2 2 32 12 1
|
||||
1 1 16 36 2 2 15 35 15 2 2 36 16 1
|
||||
1 1 20 40 2 2 19 39 19 2 2 40 20 1
|
||||
1 1 3 23 2 2 2 22 2 2 2 23 3 1
|
||||
1 1 7 27 2 2 6 26 6 2 2 27 7 1
|
||||
1 1 11 31 2 2 10 30 10 2 2 31 11 1
|
||||
1 1 15 35 2 2 14 34 14 2 2 35 15 1
|
||||
1 1 19 39 2 2 18 38 18 2 2 39 19 1
|
|
@ -0,0 +1,59 @@
|
|||
import copy
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import numpy as np
|
||||
|
||||
from damask import Geom
|
||||
|
||||
|
||||
def geom_equal(a,b):
|
||||
return np.all(a.get_microstructure() == b.get_microstructure()) and \
|
||||
np.all(a.get_size() == b.get_size()) and \
|
||||
np.all(a.get_grid() == b.get_grid())
|
||||
|
||||
@pytest.fixture
|
||||
def default():
|
||||
"""Simple geometry."""
|
||||
x=np.concatenate((np.ones(40,dtype=int),
|
||||
np.arange(2,42),
|
||||
np.ones(40,dtype=int)*2,
|
||||
np.arange(1,41))).reshape((8,5,4))
|
||||
return Geom(x,[8e-6,5e-6,4e-6])
|
||||
|
||||
@pytest.fixture
|
||||
def reference_dir(reference_dir_base):
|
||||
"""directory containing reference results."""
|
||||
return os.path.join(reference_dir_base,'Geom')
|
||||
|
||||
|
||||
class TestGeom:
|
||||
|
||||
def test_update(self,default):
|
||||
modified = copy.deepcopy(default)
|
||||
modified.update(
|
||||
default.get_microstructure(),
|
||||
default.get_size(),
|
||||
default.get_origin()
|
||||
)
|
||||
assert geom_equal(modified,default)
|
||||
|
||||
|
||||
def test_write_read_str(self,default,tmpdir):
|
||||
default.to_file(str(tmpdir.join('default.geom')))
|
||||
new = Geom.from_file(str(tmpdir.join('default.geom')))
|
||||
assert geom_equal(new,default)
|
||||
|
||||
def test_write_read_file(self,default,tmpdir):
|
||||
with open(tmpdir.join('default.geom'),'w') as f:
|
||||
default.to_file(f)
|
||||
with open(tmpdir.join('default.geom')) as f:
|
||||
new = Geom.from_file(f)
|
||||
assert geom_equal(new,default)
|
||||
|
||||
def test_mirror(self,default,update,reference_dir):
|
||||
modified = copy.deepcopy(default)
|
||||
modified.mirror(['x','z'])
|
||||
reference = os.path.join(reference_dir,'mirror.geom')
|
||||
if update: modified.to_file(reference)
|
||||
assert geom_equal(modified,Geom.from_file(reference))
|
Loading…
Reference in New Issue