From 4dd387d7f51c5b25535126f2c8733a3a91f25bec Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 27 Oct 2020 06:34:05 +0100 Subject: [PATCH] compatibility with old pyyaml + test for numpy --- python/damask/_config.py | 6 +++++- python/tests/test_Config.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/damask/_config.py b/python/damask/_config.py index f2ffbbbf3..24245f4bd 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -79,7 +79,11 @@ class Config(dict): 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 diff --git a/python/tests/test_Config.py b/python/tests/test_Config.py index e715ad763..67c419b3e 100644 --- a/python/tests/test_Config.py +++ b/python/tests/test_Config.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from damask import Config @@ -29,6 +30,8 @@ class TestConfig: f.write(config.__repr__()) 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): assert Config().is_valid is None