diff --git a/src/ansys/pyensight/core/ensight_grpc.py b/src/ansys/pyensight/core/ensight_grpc.py index e24269546c1..4eeb9384408 100644 --- a/src/ansys/pyensight/core/ensight_grpc.py +++ b/src/ansys/pyensight/core/ensight_grpc.py @@ -173,8 +173,8 @@ def _metadata(self) -> List[Tuple[bytes, Union[str, bytes]]]: if type(s) == str: s = s.encode("utf-8") ret.append((b"shared_secret", s)) - if self._session_name: - s = self._session_name.encode("utf-8") + if self.session_name: + s = self.session_name.encode("utf-8") ret.append((b"session_name", s)) return ret diff --git a/src/ansys/pyensight/core/ensobj.py b/src/ansys/pyensight/core/ensobj.py index 876ed3b4d74..12725f6e5d2 100644 --- a/src/ansys/pyensight/core/ensobj.py +++ b/src/ansys/pyensight/core/ensobj.py @@ -74,7 +74,7 @@ def __del__(self): try: cmd = f"ensight.objs.release_id('{tmp_session.name}', {self.__OBJID__})" tmp_session.cmd(cmd, do_eval=False) - except Exception: + except Exception: # pragma: no cover # This could happen at any time, including outside # the scope of the session, so we need to be # ready for any error. diff --git a/src/ansys/pyensight/core/listobj.py b/src/ansys/pyensight/core/listobj.py index b5178b3c70d..39abc1f45ad 100644 --- a/src/ansys/pyensight/core/listobj.py +++ b/src/ansys/pyensight/core/listobj.py @@ -161,7 +161,6 @@ def set_attr(self, attr: Any, value: Any) -> int: >>> session.ensight.objs.core.PARTS.set_attr("VISIBLE", True) """ - objid_list = [] session = None objid_list = [x.__OBJID__ for x in self if isinstance(x, ENSOBJ)] for item in self: diff --git a/src/ansys/pyensight/core/session.py b/src/ansys/pyensight/core/session.py index eb4c23a306e..f77f6d4ee1b 100644 --- a/src/ansys/pyensight/core/session.py +++ b/src/ansys/pyensight/core/session.py @@ -309,7 +309,7 @@ def _check_rest_connection(self) -> None: except Exception: pass time.sleep(0.5) - raise RuntimeError("Unable to establish a REST connection to EnSight.") + raise RuntimeError("Unable to establish a REST connection to EnSight.") # pragma: no cover @property def name(self) -> str: @@ -1024,7 +1024,7 @@ def close(self) -> None: if self.cei_suffix >= "242": try: self._release_remote_objects() - except RuntimeError: + except RuntimeError: # pragma: no cover # handle some intermediate EnSight builds. pass if self._launcher and self._halt_ensight_on_close: diff --git a/tests/example_tests/test_remote_objects.py b/tests/example_tests/test_remote_objects.py new file mode 100644 index 00000000000..c7e0b7a9afa --- /dev/null +++ b/tests/example_tests/test_remote_objects.py @@ -0,0 +1,31 @@ +from ansys.pyensight.core import DockerLauncher, LocalLauncher + +import gc +import pytest + + +def test_remote_objects(tmpdir, pytestconfig: pytest.Config): + data_dir = tmpdir.mkdir("datadir") + use_local = pytestconfig.getoption("use_local_launcher") + if use_local: + launcher = LocalLauncher() + else: + launcher = DockerLauncher(data_directory=data_dir, use_dev=True) + session = launcher.start() + session.load_data(f"{session.cei_home}/ensight{session.cei_suffix}/data/guard_rail/crash.case") + + # call __str__ on an ENSOBJ object w/o DESCRIPTION attribute (for coverage) + print(session.ensight.objs.core) + + if session.cei_suffix >= "242": + # Create an ENS_GROUP object (a remote object) + g = session.ensight.objs.core.PARTS.find('*rail*', wildcard=1, group=1) + assert "ENS_GROUP" in g.__str__(), "ensobjlist.find() did not return an ENS_GROUP instance" + assert "Owned" in g.__str__(), "Remote ENS_GROUP is not 'Owned'" + assert "Owned" not in g.CHILDREN.__str__(), "Objects in ENS_GROUP are incorrectly 'Owned'" + + # Exercise the custom __del__() method + g = None + gc.collect() + + session.close()