diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index 14df016744..c2cc0539e5 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -116,15 +116,25 @@ def set_result_file_path(self, filepath, key=""): ['/tmp/file.rst'] """ - # Handle the case of files without extension, such as the LS-DYNA d3plot file - if os.path.splitext(filepath)[1] == "": - if "d3plot" in os.path.basename(filepath): - key = "d3plot" + # Handle no key given and no file extension + if key == "" and os.path.splitext(filepath)[1] == "": + key = self.guess_result_key(str(filepath)) if key == "": self._api.data_sources_set_result_file_path_utf8(self, str(filepath)) else: self._api.data_sources_set_result_file_path_with_key_utf8(self, str(filepath), key) + @staticmethod + def guess_result_key(filepath: str) -> str: + """Guess result key for files without a file extension.""" + result_keys = ["d3plot", "binout"] + base_name = os.path.basename(filepath) + # Handle files without extension + for result_key in result_keys: + if result_key in base_name: + return result_key + return "" + def set_domain_result_file_path(self, path, domain_id): """Add a result file path by domain. diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 37c1ac64fc..ce28e25313 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -42,9 +42,13 @@ def test_addfilepathspecifiedresult_data_sources(allkindofcomplexity, server_typ data_sources.add_file_path_for_specified_result(allkindofcomplexity, "d3plot") -def test_setresultpath_data_sources_no_extension(d3plot_beam, server_type): +def test_setresultpath_data_sources_no_extension(d3plot_beam, binout_glstat, server_type): data_sources = dpf.core.DataSources(server=server_type) data_sources.set_result_file_path(d3plot_beam) + assert data_sources.result_key == "d3plot" + data_sources = dpf.core.DataSources(server=server_type) + data_sources.set_result_file_path(binout_glstat) + assert data_sources.result_key == "binout" def test_addupstream_data_sources(allkindofcomplexity, server_type):