Skip to content

Commit

Permalink
[GeoMechanicsApplication] Investigate the occasional failure of the "…
Browse files Browse the repository at this point in the history
…test_parameter_field_with_python_umat_parameters" test on the build server 2nd (#12760)

* added more prints

* used RuntimeError to raise exceptions

* response to the review

---------

Co-authored-by: Gennady Markelov <[email protected]>
  • Loading branch information
markelov208 and Gennady Markelov authored Oct 21, 2024
1 parent 79f2a86 commit 9323173
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions applications/GeoMechanicsApplication/tests/test_parameter_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_parameter_field_with_python_umat_parameters(self):

custom_script_name = "custom_field_umat_parameters.py"
custom_python_file = os.path.join(file_path, custom_script_name)
if not os.path.isfile(custom_python_file):
raise RuntimeError(f"Source file does not exist. {custom_python_file}")

# copy user defined python script to installation folder
new_custom_script_path = os.path.join(os.path.dirname(KratosGeo.__file__), "user_defined_scripts")
Expand All @@ -71,21 +73,28 @@ def test_parameter_field_with_python_umat_parameters(self):
try:
shutil.copy(custom_python_file, new_custom_script_path)
except shutil.SameFileError as e:
print(f"Source and destination represents the same file. {e}")
raise
raise RuntimeError(f"Source and destination represents the same file.") from e
except PermissionError as e:
print(f"Permission denied: {e}")
raise
raise RuntimeError(f"Permission denied.") from e
except IOError as e:
print(f"Try to change the destination file permission {e}")
os.chmod(new_custom_script_path, stat.S_IRWXU)
shutil.copy(custom_python_file, new_custom_script_path)
print(f"Try to change the destination file permission {e}")
os.chmod(new_custom_script_path, stat.S_IRWXU)
shutil.copy(custom_python_file, new_custom_script_path)
except Exception as e:
print(f"Error occurred while copying the file {e}.")
raise
raise RuntimeError(f"Error occurred while copying the file.") from e
except BaseException as e:
raise RuntimeError(f"An unknown error occurred while copying the file.") from e

custom_python_file_new_location = os.path.join(new_custom_script_path, custom_script_name)

if not os.path.isfile(custom_python_file_new_location):
raise RuntimeError(f"File {custom_python_file_new_location} does not exist after copying the source.")

simulation = test_helper.run_kratos(file_path)

if not os.path.isfile(custom_python_file_new_location):
raise RuntimeError(f"File {custom_python_file_new_location} does not exist after run_kratos.")

# get element centers
elements = simulation._list_of_output_processes[0].model_part.Elements
center_coords = [element.GetGeometry().Center() for element in elements]
Expand All @@ -98,6 +107,9 @@ def test_parameter_field_with_python_umat_parameters(self):
expected_res = 20000 * center_coord[0] + 30000 * center_coord[1]
self.assertAlmostEqual(expected_res, res[0][0])

if not os.path.isfile(custom_python_file_new_location):
raise RuntimeError(f"File {custom_python_file_new_location} does not exist before removal.")

# remove user defined python script from installation folder
os.remove(os.path.join(new_custom_script_path, custom_script_name))

Expand Down Expand Up @@ -125,7 +137,6 @@ def test_parameter_field_with_json_umat_parameters(self):
expected_res = 20000 * center_coord[0] + 30000 * center_coord[1]
self.assertAlmostEqual(expected_res, res[0][0])


def test_parameter_field_with_function(self):
"""
Test to check if values from a function defined parameter field are correctly added to each individual element
Expand Down

0 comments on commit 9323173

Please sign in to comment.