compatibility with old pyyaml + test for numpy
This commit is contained in:
parent
4159ae5f3d
commit
4dd387d7f5
|
@ -79,7 +79,11 @@ class Config(dict):
|
||||||
|
|
||||||
NiceDumper.add_representer(np.ndarray, array_representer)
|
NiceDumper.add_representer(np.ndarray, array_representer)
|
||||||
|
|
||||||
fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs))
|
try:
|
||||||
|
fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs))
|
||||||
|
except TypeError: # compatibility with old pyyaml
|
||||||
|
del kwargs['sort_keys']
|
||||||
|
fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs))
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from damask import Config
|
from damask import Config
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ class TestConfig:
|
||||||
f.write(config.__repr__())
|
f.write(config.__repr__())
|
||||||
assert Config.load(tmp_path/'config.yaml') == config
|
assert Config.load(tmp_path/'config.yaml') == config
|
||||||
|
|
||||||
|
def test_numpy(self,tmp_path):
|
||||||
|
assert Config({'A':np.ones(3,'i')}).__repr__() == Config({'A':[1,1,1]}).__repr__()
|
||||||
|
|
||||||
def test_abstract_is_valid(self):
|
def test_abstract_is_valid(self):
|
||||||
assert Config().is_valid is None
|
assert Config().is_valid is None
|
||||||
|
|
Loading…
Reference in New Issue