avoid invalid DADF5

This commit is contained in:
Martin Diehl 2021-08-16 21:31:17 +02:00
parent b79fc5c097
commit b13e7e174b
2 changed files with 9 additions and 1 deletions

View File

@ -567,9 +567,13 @@ class Result:
formula = kwargs['formula']
for d in re.findall(r'#(.*?)#',formula):
formula = formula.replace(f'#{d}#',f"kwargs['{d}']['data']")
data = eval(formula)
if not hasattr(data,'shape') or data.shape[0] != kwargs[d]['data'].shape[0]:
raise ValueError("'{}' results in invalid shape".format(kwargs['formula']))
return {
'data': eval(formula),
'data': data,
'label': kwargs['label'],
'meta': {
'unit': kwargs['unit'],

View File

@ -123,6 +123,10 @@ class TestResult:
in_file = default.place('x')
assert np.allclose(in_memory,in_file)
def test_add_calculation_invalid(self,default):
default.add_calculation('np.linalg.norm(#F#,axis=0)','wrong_dim')
assert default.get('wrong_dim') is None
def test_add_stress_Cauchy(self,default):
default.add_stress_Cauchy('P','F')
in_memory = mechanics.stress_Cauchy(default.place('P'), default.place('F'))