use pytest instead of hand-written test class

This commit is contained in:
Martin Diehl 2019-12-08 21:29:26 +01:00
parent 6dfe24290c
commit 53cb59fc47
3 changed files with 13 additions and 14 deletions

View File

@ -115,13 +115,6 @@ Pytest:
- release - release
################################################################################################### ###################################################################################################
OrientationRelationship:
stage: preprocessing
script: OrientationRelationship/test.py
except:
- master
- release
Pre_SeedGeneration: Pre_SeedGeneration:
stage: preprocessing stage: preprocessing
script: PreProcessing_SeedGeneration/test.py script: PreProcessing_SeedGeneration/test.py

View File

@ -1025,7 +1025,7 @@ class Lattice:
https://doi.org/10.1016/j.actamat.2004.11.021 https://doi.org/10.1016/j.actamat.2004.11.021
""" """
models={'KS':self.KS, 'GT':self.GT, "GT'":self.GTprime, models={'KS':self.KS, 'GT':self.GT, 'GT_prime':self.GTprime,
'NW':self.NW, 'Pitsch': self.Pitsch, 'Bain':self.Bain} 'NW':self.NW, 'Pitsch': self.Pitsch, 'Bain':self.Bain}
try: try:
relationship = models[model] relationship = models[model]

View File

@ -2,6 +2,7 @@ import pytest
import numpy as np import numpy as np
from damask import Rotation from damask import Rotation
from damask import Orientation
n = 1000 n = 1000
@ -18,38 +19,43 @@ class TestRotation:
assert np.allclose(rot.asQuaternion(), assert np.allclose(rot.asQuaternion(),
Rotation.fromEulers(rot.asEulers()).asQuaternion()) Rotation.fromEulers(rot.asEulers()).asQuaternion())
def test_AxisAngle(self,default): def test_AxisAngle(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asEulers(), assert np.allclose(rot.asEulers(),
Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers()) Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers())
def test_Matrix(self,default): def test_Matrix(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asAxisAngle(), assert np.allclose(rot.asAxisAngle(),
Rotation.fromMatrix(rot.asMatrix()).asAxisAngle()) Rotation.fromMatrix(rot.asMatrix()).asAxisAngle())
def test_Rodriques(self,default): def test_Rodriques(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asMatrix(), assert np.allclose(rot.asMatrix(),
Rotation.fromRodrigues(rot.asRodrigues()).asMatrix()) Rotation.fromRodrigues(rot.asRodrigues()).asMatrix())
def test_Homochoric(self,default): def test_Homochoric(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asRodrigues(), assert np.allclose(rot.asRodrigues(),
Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues()) Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues())
def test_Cubochoric(self,default): def test_Cubochoric(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asHomochoric(), assert np.allclose(rot.asHomochoric(),
Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric()) Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric())
def test_Quaternion(self,default): def test_Quaternion(self,default):
for rot in default: for rot in default:
assert np.allclose(rot.asCubochoric(), assert np.allclose(rot.asCubochoric(),
Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric()) Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric())
@pytest.mark.parametrize('model',['Bain','KS','GT','GT_prime','NW','Pitsch'])
@pytest.mark.parametrize('lattice',['fcc','bcc'])
def test_relationship_forward_backward(self,model,lattice):
ori = Orientation(Rotation.fromRandom(),lattice)
for i,r in enumerate(ori.relatedOrientations(model)):
ori2 = r.relatedOrientations(model)[i]
misorientation = ori.rotation.misorientation(ori2.rotation)
assert misorientation.asAxisAngle(degrees=True)[3]<1.0e-5