From d015663b337950ca8f0601e8df3ab09b22630c57 Mon Sep 17 00:00:00 2001 From: Keith Hanson <122566160+anskhanson@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:38:46 -0500 Subject: [PATCH] Updated info call from 3 back to 1 call. --- src/ansys/sherlock/core/common.py | 63 ++++--------------------------- tests/test_common.py | 11 ++++++ tests/test_utils.py | 2 +- 3 files changed, 20 insertions(+), 56 deletions(-) diff --git a/src/ansys/sherlock/core/common.py b/src/ansys/sherlock/core/common.py index 2c1c52808..db13f2757 100644 --- a/src/ansys/sherlock/core/common.py +++ b/src/ansys/sherlock/core/common.py @@ -158,69 +158,22 @@ def list_solder_materials(self): # First PySherlock Release "0.7.0" @require_version(251) - def get_sherlock_version(self) -> str: + def get_sherlock_info(self) -> str: """Get server Sherlock version. Returns ------- - str - Sherlock version - - Examples - -------- - >>> from ansys.sherlock.core.launcher import launch_sherlock - >>> sherlock = launch_sherlock() - >>> sherlock.common.get_sherlock_version() - """ - if not self._is_connection_up(): - LOG.error("Not connected to a gRPC service.") - raise RuntimeError("Not connected to a gRPC service.") - - request = SherlockCommonService_pb2.SherlockInfoRequest() - response = self.stub.getSherlockInfo(request) - if response is not None: - return response.releaseVersion - - # First PySherlock Release "0.7.0" - @require_version(251) - def get_sherlock_default_project_dir(self) -> str: - """Get server Sherlock default project directory. - - Returns - ------- - str - Sherlock default project directory - - Examples - -------- - >>> from ansys.sherlock.core.launcher import launch_sherlock - >>> sherlock = launch_sherlock() - >>> sherlock.common.get_sherlock_default_project_dir() - """ - if not self._is_connection_up(): - LOG.error("Not connected to a gRPC service.") - raise RuntimeError("Not connected to a gRPC service.") - - request = SherlockCommonService_pb2.SherlockInfoRequest() - response = self.stub.getSherlockInfo(request) - if response is not None: - return response.defaultProjectDir - - # First PySherlock Release "0.7.0" - @require_version(251) - def is_single_project_mode(self) -> bool: - """Get flag indicating single project mode. - - Returns - ------- - bool - True if Sherlock single project mode is active, False otherwise + SherlockInfoResponse + Sherlock information containing + releaseVersion, defaultProjectDir and isSingleProjectMode flag Examples -------- >>> from ansys.sherlock.core.launcher import launch_sherlock >>> sherlock = launch_sherlock() - >>> sherlock.common.get_sherlock_default_project_dir() + >>> release_version = sherlock.common.get_sherlock_info().releaseVersion + >>> default_dir = sherlock.common.get_sherlock_info().defaultProjectDir + >>> is_single_project = sherlock.common.get_sherlock_info().isSingleProjectMode """ if not self._is_connection_up(): LOG.error("Not connected to a gRPC service.") @@ -229,4 +182,4 @@ def is_single_project_mode(self) -> bool: request = SherlockCommonService_pb2.SherlockInfoRequest() response = self.stub.getSherlockInfo(request) if response is not None: - return response.isSingleProjectMode + return response diff --git a/tests/test_common.py b/tests/test_common.py index 299559436..cf4441116 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -46,5 +46,16 @@ def helper_test_get_solders(common): pytest.fail(str(e)) +def helper_test_get_sherlock_info(common): + """Test get_sherlock_info API""" + + if common._is_connection_up(): + try: + sherlock_info_response = common.get_sherlock_info() + assert sherlock_info_response is not None + except Exception as e: + pytest.fail(str(e)) + + if __name__ == "__main__": test_all() diff --git a/tests/test_utils.py b/tests/test_utils.py index ec9e9d120..82488c289 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -19,7 +19,7 @@ def test_version_check(): # "get_sherlock_version" was added to PySherlock / Sherlock. common = Common(channel, 242) # This should fail since it did not exist in 242 - common.get_sherlock_version() + common.get_sherlock_info() pytest.fail("Sherlock version should be too low to launch this method") except Exception as e: if not isinstance(e, SherlockVersionError):