transparently handle orientations/rotations
This commit is contained in:
parent
4f40e58ce6
commit
fe0cd8e5e2
|
@ -6,6 +6,9 @@ import abc
|
|||
import numpy as np
|
||||
import yaml
|
||||
|
||||
from . import Rotation
|
||||
from . import Orientation
|
||||
|
||||
class NiceDumper(yaml.SafeDumper):
|
||||
"""Make YAML readable for humans."""
|
||||
|
||||
|
@ -20,8 +23,12 @@ class NiceDumper(yaml.SafeDumper):
|
|||
|
||||
def represent_data(self, data):
|
||||
"""Cast Config objects and its subclasses to dict."""
|
||||
return self.represent_data(dict(data)) if isinstance(data, dict) and type(data) != dict else \
|
||||
super().represent_data(data)
|
||||
if isinstance(data, dict) and type(data) != dict:
|
||||
return self.represent_data(dict(data))
|
||||
if isinstance(data, (Rotation, Orientation)):
|
||||
return self.represent_data(data.as_quaternion())
|
||||
else:
|
||||
return super().represent_data(data)
|
||||
|
||||
def ignore_aliases(self, data):
|
||||
"""No references."""
|
||||
|
|
|
@ -2,6 +2,8 @@ import pytest
|
|||
import numpy as np
|
||||
|
||||
from damask import Config
|
||||
from damask import Rotation
|
||||
from damask import Orientation
|
||||
|
||||
class TestConfig:
|
||||
|
||||
|
@ -51,3 +53,7 @@ class TestConfig:
|
|||
|
||||
def test_abstract_is_complete(self):
|
||||
assert Config().is_complete is None
|
||||
|
||||
@pytest.mark.parametrize('data',[Rotation.from_random(),Orientation.from_random()])
|
||||
def test_rotation_orientation(self,data):
|
||||
assert str(Config(a=data)) == str(Config(a=data.as_quaternion()))
|
||||
|
|
Loading…
Reference in New Issue