allow user do control output style
(numerics.yaml looks strange otherwise)
This commit is contained in:
parent
5ad46ae021
commit
33685bc493
|
@ -43,7 +43,7 @@ class Config(dict):
|
|||
fhandle = fname
|
||||
return cls(yaml.safe_load(fhandle))
|
||||
|
||||
def save(self,fname):
|
||||
def save(self,fname,**kwargs):
|
||||
"""
|
||||
Save to yaml file.
|
||||
|
||||
|
@ -51,13 +51,20 @@ class Config(dict):
|
|||
----------
|
||||
fname : file, str, or pathlib.Path
|
||||
Filename or file for writing.
|
||||
**kwargs : dict
|
||||
Keyword arguments parsed to yaml.dump.
|
||||
|
||||
"""
|
||||
try:
|
||||
fhandle = open(fname,'w')
|
||||
except TypeError:
|
||||
fhandle = fname
|
||||
fhandle.write(yaml.dump(dict(self),width=256,default_flow_style=None,Dumper=NiceDumper))
|
||||
|
||||
if 'width' not in kwargs:
|
||||
kwargs['width'] = 256
|
||||
if 'default_flow_style' not in kwargs:
|
||||
kwargs['default_flow_style'] = None
|
||||
fhandle.write(yaml.dump(dict(self),Dumper=NiceDumper,**kwargs))
|
||||
|
||||
|
||||
@property
|
||||
|
|
|
@ -9,7 +9,7 @@ from . import Rotation
|
|||
class ConfigMaterial(Config):
|
||||
"""Material configuration."""
|
||||
|
||||
def save(self,fname='material.yaml'):
|
||||
def save(self,fname='material.yaml',**kwargs):
|
||||
"""
|
||||
Save to yaml file.
|
||||
|
||||
|
@ -17,9 +17,11 @@ class ConfigMaterial(Config):
|
|||
----------
|
||||
fname : file, str, or pathlib.Path, optional
|
||||
Filename or file for writing. Defaults to 'material.yaml'.
|
||||
**kwargs : dict
|
||||
Keyword arguments parsed to yaml.dump.
|
||||
|
||||
"""
|
||||
super().save(fname)
|
||||
super().save(fname,**kwargs)
|
||||
|
||||
@property
|
||||
def is_complete(self):
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import pytest
|
||||
|
||||
from damask import Config
|
||||
|
||||
class TestConfig:
|
||||
|
||||
def test_load_save_str(self,tmp_path):
|
||||
@pytest.mark.parametrize('flow_style',[None,True,False])
|
||||
def test_load_save_str(self,tmp_path,flow_style):
|
||||
config = Config()
|
||||
config['A'] = 1
|
||||
config['B'] = [2,3]
|
||||
config.save(tmp_path/'config.yaml')
|
||||
config.save(tmp_path/'config.yaml',default_flow_style=flow_style)
|
||||
assert Config.load(tmp_path/'config.yaml') == config
|
||||
|
||||
def test_load_save_file(self,tmp_path):
|
||||
|
|
Loading…
Reference in New Issue