completely tested
This commit is contained in:
parent
fdfcb16d15
commit
5ad46ae021
|
@ -28,21 +28,29 @@ class Config(dict):
|
|||
|
||||
@classmethod
|
||||
def load(cls,fname):
|
||||
"""Load from yaml file."""
|
||||
"""
|
||||
Load from yaml file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : file, str, or pathlib.Path
|
||||
Filename or file for writing.
|
||||
|
||||
"""
|
||||
try:
|
||||
fhandle = open(fname)
|
||||
except TypeError:
|
||||
fhandle = fname
|
||||
return cls(yaml.safe_load(fhandle))
|
||||
|
||||
def save(self,fname='material.yaml'):
|
||||
def save(self,fname):
|
||||
"""
|
||||
Save to yaml file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : file, str, or pathlib.Path
|
||||
Filename or file for reading.
|
||||
Filename or file for writing.
|
||||
|
||||
"""
|
||||
try:
|
||||
|
|
|
@ -9,6 +9,18 @@ from . import Rotation
|
|||
class ConfigMaterial(Config):
|
||||
"""Material configuration."""
|
||||
|
||||
def save(self,fname='material.yaml'):
|
||||
"""
|
||||
Save to yaml file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : file, str, or pathlib.Path, optional
|
||||
Filename or file for writing. Defaults to 'material.yaml'.
|
||||
|
||||
"""
|
||||
super().save(fname)
|
||||
|
||||
@property
|
||||
def is_complete(self):
|
||||
"""Check for completeness."""
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
from damask import Config
|
||||
|
||||
class TestConfig:
|
||||
|
||||
def test_load_save_str(self,tmp_path):
|
||||
config = Config()
|
||||
config['A'] = 1
|
||||
config['B'] = [2,3]
|
||||
config.save(tmp_path/'config.yaml')
|
||||
assert Config.load(tmp_path/'config.yaml') == config
|
||||
|
||||
def test_load_save_file(self,tmp_path):
|
||||
config = Config()
|
||||
config['A'] = 1
|
||||
config['B'] = [2,3]
|
||||
with open(tmp_path/'config.yaml','w') as f:
|
||||
config.save(f)
|
||||
with open(tmp_path/'config.yaml') as f:
|
||||
assert Config.load(f) == config
|
||||
|
||||
def test_repr(self,tmp_path):
|
||||
config = Config()
|
||||
config['A'] = 1
|
||||
config['B'] = [2,3]
|
||||
with open(tmp_path/'config.yaml','w') as f:
|
||||
f.write(config.__repr__())
|
||||
assert Config.load(tmp_path/'config.yaml') == config
|
||||
|
||||
|
||||
def test_abstract_is_valid(self):
|
||||
assert Config().is_valid is None
|
||||
|
||||
def test_abstract_is_complete(self):
|
||||
assert Config().is_complete is None
|
|
@ -10,8 +10,8 @@ def reference_dir(reference_dir_base):
|
|||
return reference_dir_base/'ConfigMaterial'
|
||||
|
||||
|
||||
class TestMaterial:
|
||||
|
||||
class TestConfigMaterial:
|
||||
|
||||
@pytest.mark.parametrize('fname',[None,'test.yaml'])
|
||||
def test_load_save(self,reference_dir,tmp_path,fname):
|
||||
reference = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
|
@ -32,29 +32,44 @@ class TestMaterial:
|
|||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
material_config['phase']['Aluminum']['lattice']='fxc'
|
||||
assert not material_config.is_valid
|
||||
|
||||
|
||||
def test_invalid_orientation(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
material_config['microstructure'][0]['constituents'][0]['orientation']=[0,0,0,0]
|
||||
assert not material_config.is_valid
|
||||
|
||||
|
||||
def test_invalid_fraction(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
material_config['microstructure'][0]['constituents'][0]['fraction']=.9
|
||||
assert not material_config.is_valid
|
||||
|
||||
|
||||
@pytest.mark.parametrize('item',['homogenization','phase','microstructure'])
|
||||
def test_incomplete_missing(self,reference_dir,item):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
del material_config[item]
|
||||
assert not material_config.is_complete
|
||||
|
||||
|
||||
@pytest.mark.parametrize('item',['orientation','phase'])
|
||||
def test_incomplete_material_constituent(self,reference_dir,item):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
del material_config['microstructure'][0]['constituents'][0][item]
|
||||
assert not material_config.is_complete
|
||||
|
||||
def test_incomplete_material_homogenization(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
del material_config['microstructure'][0]['homogenization']
|
||||
assert not material_config.is_complete
|
||||
|
||||
def test_incomplete_phase_lattice(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
del material_config['phase']['Aluminum']['lattice']
|
||||
assert not material_config.is_complete
|
||||
|
||||
def test_incomplete_wrong_phase(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
new = material_config.microstructure_rename_phase({'Steel':'FeNbC'})
|
||||
assert not new.is_complete
|
||||
|
||||
|
||||
def test_incomplete_wrong_homogenization(self,reference_dir):
|
||||
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
|
||||
new = material_config.microstructure_rename_homogenization({'Taylor':'isostrain'})
|
Loading…
Reference in New Issue