simulation setup export function naming and description was inaccurate

This commit is contained in:
Daniel Otto de Mentock 2022-11-09 12:47:47 +01:00
parent 8d59750b93
commit ce7d2af6e3
2 changed files with 9 additions and 9 deletions

View File

@ -109,7 +109,7 @@ class Result:
if self.version_major != 0 or not 12 <= self.version_minor <= 14:
raise TypeError(f'unsupported DADF5 version "{self.version_major}.{self.version_minor}"')
if self.version_major == 0 and self.version_minor < 14:
self.export_setup = None # type: ignore
self.export_simulation_setup_files = None # type: ignore
self.structured = 'cells' in f['geometry'].attrs.keys()
@ -1951,13 +1951,13 @@ class Result:
return None if (type(r) == dict and r == {}) else r
def export_setup(self,
def export_simulation_setup_files(self,
output: Union[str, List[str]] = '*',
target_dir: Union[str, Path] = None,
overwrite: bool = False,
):
"""
Export configuration files.
Export original simulation setup of Result object.
Parameters
----------
@ -1988,8 +1988,8 @@ class Result:
print(f'"{cfg}" exists, {d} not exported.')
elif type(obj) == h5py.Group:
cfg.mkdir(parents=True,exist_ok=True)
cfg_dir = (Path.cwd() if target_dir is None else Path(target_dir))
cfg_dir.mkdir(parents=True,exist_ok=True)
with h5py.File(self.fname,'r') as f_in:
f_in['setup'].visititems(partial(export,

View File

@ -543,16 +543,16 @@ class TestResult:
'6grains6x7x8_single_phase_tensionY.hdf5'])
@pytest.mark.parametrize('output',['material.yaml','*'])
@pytest.mark.parametrize('overwrite',[True,False])
def test_export_setup(self,ref_path,tmp_path,fname,output,overwrite):
def test_export_simulation_setup_files(self,ref_path,tmp_path,fname,output,overwrite):
r = Result(ref_path/fname)
r.export_setup(output,target_dir=tmp_path)
r.export_simulation_setup_files(output,target_dir=tmp_path)
with h5py.File(ref_path/fname,'r') as f_hdf5:
for file in fnmatch.filter(f_hdf5['setup'].keys(),output):
with open(tmp_path/file) as f:
assert f_hdf5[f'setup/{file}'][()][0].decode() == f.read()
r.export_setup(output,target_dir=tmp_path,overwrite=overwrite)
r.export_simulation_setup_files(output,target_dir=tmp_path,overwrite=overwrite)
def test_export_setup_custom_path(self,ref_path,tmp_path):
def test_export_simulation_setup_files_custom_path(self,ref_path,tmp_path):
src = ref_path/'4grains2x4x3_compressionY.hdf5'
subdir = 'export_dir'
absdir = tmp_path/subdir
@ -561,7 +561,7 @@ class TestResult:
r = Result(src)
for t,cwd in zip([absdir,subdir,None],[tmp_path,tmp_path,absdir]):
os.chdir(cwd)
r.export_setup('material.yaml',target_dir=t)
r.export_simulation_setup_files('material.yaml',target_dir=t)
assert 'material.yaml' in os.listdir(absdir); (absdir/'material.yaml').unlink()
@pytest.mark.parametrize('fname',['4grains2x4x3_compressionY.hdf5',