diff --git a/src/ansys/pyensight/core/enshell_grpc.py b/src/ansys/pyensight/core/enshell_grpc.py index bf4a3a430bf..66367fda8dd 100644 --- a/src/ansys/pyensight/core/enshell_grpc.py +++ b/src/ansys/pyensight/core/enshell_grpc.py @@ -213,12 +213,12 @@ def connect(self, timeout: Optional[float] = 15.0): ) try: grpc.channel_ready_future(self._channel).result(timeout=timeout) - except grpc.FutureTimeoutError: - self._channel = None - return + except grpc.FutureTimeoutError: # pragma: no cover + self._channel = None # pragma: no cover + return # pragma: no cover self._stub = enshell_pb2_grpc.EnShellServiceStub(self._channel) - def connect_existing_channel(self, channel: grpc.Channel): + def connect_existing_channel(self, channel: grpc.Channel): # pragma: no cover """Establish a connection to an EnShell gRPC server. Attempt to connect to an EnShell gRPC server using the host and port @@ -268,15 +268,15 @@ def run_command(self, command_string: str): A tuple of (int, string) for (returnCode, returnString) """ self.connect() - if not self._stub: - return (0, "") + if not self._stub: # pragma: no cover + return (0, "") # pragma: no cover try: response = self._stub.run_command( enshell_pb2.EnShellCommandLine(command_line=command_string), metadata=self.metadata(), ) - except Exception: - raise IOError("gRPC connection dropped") + except Exception: # pragma: no cover + raise IOError("gRPC connection dropped") # pragma: no cover return (response.ret, response.response) @@ -300,8 +300,8 @@ def run_command_with_env(self, command_string: str, env_string: str): A tuple of (int, string) for (returnCode, returnString) """ self.connect() - if not self._stub: - return (0, "") + if not self._stub: # pragma: no cover + return (0, "") # pragma: no cover try: response = self._stub.run_command_with_env( enshell_pb2.EnShellCommandWithEnvLine( @@ -309,8 +309,8 @@ def run_command_with_env(self, command_string: str, env_string: str): ), metadata=self.metadata(), ) - except Exception: - raise IOError("gRPC connection dropped") + except Exception: # pragma: no cover + raise IOError("gRPC connection dropped") # pragma: no cover return (response.ret, response.response) @@ -350,10 +350,10 @@ def start_ensight(self, ensight_args: Optional[str] = None, ensight_env: Optiona if ensight_args and (ensight_args != ""): command_string += " " + ensight_args - if ensight_env is None or ensight_env == "": + if ensight_env is None or ensight_env == "": # pragma: no cover return self.run_command(command_string) else: - return self.run_command_with_env(command_string, ensight_env) + return self.run_command_with_env(command_string, ensight_env) # pragma: no cover # @brief # @@ -380,10 +380,10 @@ def start_other(self, cmd: str, extra_env: Optional[str] = None): self.connect() command_string = "start_app OTHER " + cmd - if extra_env is None or extra_env == "": + if extra_env is None or extra_env == "": # pragma: no cover return self.run_command(command_string) else: - return self.run_command_with_env(command_string, extra_env) + return self.run_command_with_env(command_string, extra_env) # pragma: no cover def cei_home(self): """Get the value of CEI_HOME from EnShell.""" @@ -403,24 +403,30 @@ def _get_cei_home(self): command_string = "show_ceihome" ret = self.run_command(command_string) # logging.debug(f"{command_string} :: ret = {ret}\n") - if ret[0] != 0: - self._cei_home = None - raise RuntimeError("Error getting printenv from EnShell") + if ret[0] != 0: # pragma: no cover + self._cei_home = None # pragma: no cover + raise RuntimeError("Error getting printenv from EnShell") # pragma: no cover # split the newline delimited string into a list of strings env_vars = ret[1].strip().split("\n") # find the string containing CEI_HOME cei_home_line = [x for x in env_vars if "CEI_HOME" in x][0] - if cei_home_line is None: - raise RuntimeError("Error getting CEI_HOME env var from the Docker container.\n{ret}\n") + if cei_home_line is None: # pragma: no cover + raise RuntimeError( + "Error getting CEI_HOME env var from the Docker container.\n{ret}\n" + ) # pragma: no cover # CEI_HOME is everything after the equal sign equal_sign_loc = cei_home_line.find("=") - if equal_sign_loc < 0: - raise RuntimeError("Error getting CEI_HOME env var from the Docker container.\n{ret}\n") + if equal_sign_loc < 0: # pragma: no cover + raise RuntimeError( + "Error getting CEI_HOME env var from the Docker container.\n{ret}\n" + ) # pragma: no cover self._cei_home = cei_home_line[equal_sign_loc + 1 :] m = re.search("/v(\d\d\d)/", self._cei_home) - if not m: - self.stop_server() - raise RuntimeError("Can't find version from cei_home in the Docker container.\n{ret}\n") + if not m: # pragma: no cover + self.stop_server() # pragma: no cover + raise RuntimeError( + "Can't find version from cei_home in the Docker container.\n{ret}\n" + ) # pragma: no cover self._ansys_version = m.group(1) diff --git a/src/ansys/pyensight/core/utils/export.py b/src/ansys/pyensight/core/utils/export.py index 100ad8b3cab..bac31bc5b41 100644 --- a/src/ansys/pyensight/core/utils/export.py +++ b/src/ansys/pyensight/core/utils/export.py @@ -49,8 +49,8 @@ def _remote_support_check(self): RuntimeError if the module is not present. """ # if a module, then we are inside EnSight - if isinstance(self._ensight, ModuleType): - return + if isinstance(self._ensight, ModuleType): # pragma: no cover + return # pragma: no cover try: _ = self._ensight._session.cmd("dir(ensight.utils.export)") except RuntimeError: @@ -108,8 +108,10 @@ def image( if height is None: height = win_size[1] - if isinstance(self._ensight, ModuleType): - raw_image = self._image_remote(width, height, passes, enhanced, raytrace) + if isinstance(self._ensight, ModuleType): # pragma: no cover + raw_image = self._image_remote( + width, height, passes, enhanced, raytrace + ) # pragma: no cover else: cmd = f"ensight.utils.export._image_remote({width}, {height}, {passes}, " cmd += f"{enhanced}, {raytrace})" @@ -348,8 +350,8 @@ def animation( or no FLIPBOOK/KEYFRAME defined." ) - if isinstance(self._ensight, ModuleType): - raw_mpeg4 = self._animation_remote( + if isinstance(self._ensight, ModuleType): # pragma: no cover + raw_mpeg4 = self._animation_remote( # pragma: no cover width, height, passes, @@ -557,8 +559,8 @@ def geometry( delta_timestep = 1 self._remote_support_check() raw_data_list = None - if isinstance(self._ensight, ModuleType): - raw_data_list = self._geometry_remote( + if isinstance(self._ensight, ModuleType): # pragma: no cover + raw_data_list = self._geometry_remote( # pragma: no cover format, starting_timestep=starting_timestep, frames=frames, diff --git a/src/ansys/pyensight/core/utils/parts.py b/src/ansys/pyensight/core/utils/parts.py index 8c73dbd77a7..f943f35a2e2 100644 --- a/src/ansys/pyensight/core/utils/parts.py +++ b/src/ansys/pyensight/core/utils/parts.py @@ -58,12 +58,12 @@ def convert_variable( class Parts: """Controls the parts in the current EnSight ``Session`` instance.""" - class _EnSEmitterPoint(ens_emitterobj): - def __init__( + class _EnSEmitterPoint(ens_emitterobj): # pragma: no cover + def __init__( # pragma: no cover self, ensight: "ensight", point1: Optional[List[float]] = [0, 0, 0], - ): + ): # pragma: no cover if not isinstance(ensight, ModuleType): raise RuntimeError( "The class cannot be used directly in PyEnSight. It should not be used directly even in EnSight" @@ -73,8 +73,8 @@ def __init__( self.ensight.view_transf.cursor(*point1) self.CENTROID = point1 - class _EnSEmitterGrid(ens_emitterobj): - def __init__( + class _EnSEmitterGrid(ens_emitterobj): # pragma: no cover + def __init__( # pragma: no cover self, ensight: "ensight", point1: Optional[List[float]] = [0, 0, 0], @@ -83,7 +83,7 @@ def __init__( point4: Optional[List[float]] = [0, 0, 0], num_points_x: Optional[int] = 25, num_points_y: Optional[int] = 25, - ): + ): # pragma: no cover if not isinstance(ensight, ModuleType): raise RuntimeError( "The class cannot be used directly in PyEnSight. It should not be used directly even in EnSight" @@ -100,14 +100,14 @@ def __init__( self.NUM_POINTS_X = num_points_x self.NUM_POINTS_Y = num_points_y - class _EnSEmitterLine(ens_emitterobj): - def __init__( + class _EnSEmitterLine(ens_emitterobj): # pragma: no cover + def __init__( # pragma: no cover self, ensight: "ensight", point1: Optional[List[float]] = [0, 0, 0], point2: Optional[List[float]] = [0, 0, 0], num_points: Optional[int] = 100, - ): + ): # pragma: no cover if not isinstance(ensight, ModuleType): raise RuntimeError( "The class cannot be used directly in PyEnSight. It should not be used directly even in EnSight" @@ -120,14 +120,14 @@ def __init__( self.POINT2 = point2 self.NUM_POINTS = num_points - class _EnSEmitterPart(ens_emitterobj): - def __init__( + class _EnSEmitterPart(ens_emitterobj): # pragma: no cover + def __init__( # pragma: no cover self, ensight: "ensight", part: Optional[Any] = None, part_kind: Optional[Any] = 0, num_points: Optional[int] = 100, - ): + ): # pragma: no cover if not isinstance(ensight, ModuleType): raise RuntimeError( "The class cannot be used directly in PyEnSight. It should not be used directly even in EnSight" @@ -257,8 +257,10 @@ def _create_emitters( if not points: raise RuntimeError("list of points needed if particle trace emitted from points") for p in points: - if isinstance(self.ensight, ModuleType): - new_emitters.append(self._EnSEmitterPoint(self.ensight, point1=p)) + if isinstance(self.ensight, ModuleType): # pragma: no cover + new_emitters.append( + self._EnSEmitterPoint(self.ensight, point1=p) + ) # pragma: no cover else: new_emitters.append( f"ensight.utils.parts._EnSEmitterPoint(ensight, point1={p})" @@ -266,8 +268,8 @@ def _create_emitters( elif emitter_type == self._EMIT_LINE: if not any([point1, point2]): raise RuntimeError("point1 and point2 needed if particle trace emitted from line") - if isinstance(self.ensight, ModuleType): - new_emitters.append( + if isinstance(self.ensight, ModuleType): # pragma: no cover + new_emitters.append( # pragma: no cover self._EnSEmitterLine( self.ensight, point1=point1, point2=point2, num_points=num_points ) @@ -281,8 +283,8 @@ def _create_emitters( raise RuntimeError( "point1, point2 and point3 needed if particle trace emitted from plane" ) - if isinstance(self.ensight, ModuleType): - new_emitters.append( + if isinstance(self.ensight, ModuleType): # pragma: no cover + new_emitters.append( # pragma: no cover self._EnSEmitterGrid( self.ensight, point1=point1, @@ -300,8 +302,8 @@ def _create_emitters( if not parts: raise RuntimeError("part and num_points needed if particle trace emitted from part") for p in parts: - if isinstance(self.ensight, ModuleType): - new_emitters.append( + if isinstance(self.ensight, ModuleType): # pragma: no cover + new_emitters.append( # pragma: no cover self._EnSEmitterPart( self.ensight, part=p, @@ -370,13 +372,13 @@ def _add_emitters_to_particle_trace_part( clean: Optional[bool] = False, ) -> "ENS_PART_PARTICLE_TRACE": """Private utility to add emitters to an existing particle trace part.""" - if isinstance(self.ensight, ModuleType): - if clean: - emitters = [] - else: - emitters = particle_trace_part.EMITTERS.copy() - emitters.extend(new_emitters) - particle_trace_part.EMITTERS = emitters + if isinstance(self.ensight, ModuleType): # pragma: no cover + if clean: # pragma: no cover + emitters = [] # pragma: no cover + else: # pragma: no cover + emitters = particle_trace_part.EMITTERS.copy() # pragma: no cover + emitters.extend(new_emitters) # pragma: no cover + particle_trace_part.EMITTERS = emitters # pragma: no cover else: if clean: self.ensight._session.cmd("enscl.emitters=[]", do_eval=False) diff --git a/tests/example_tests/test_coverage_increase.py b/tests/example_tests/test_coverage_increase.py index b8530db9593..4fa41e1791c 100644 --- a/tests/example_tests/test_coverage_increase.py +++ b/tests/example_tests/test_coverage_increase.py @@ -370,4 +370,8 @@ def test_sos(tmpdir, pytestconfig: pytest.Config): assert session.grpc.security_token == session._secret_key session.close() if is_docker: - launch_ensight(use_docker=True, use_dev=True, data_directory=data_dir) + session = launch_ensight(use_docker=True, use_dev=True, data_directory=data_dir) + assert session._launcher._enshell.host() == session._hostname + session._launcher._enshell.port() + session._launcher._enshell.security_token() + session._launcher._enshell.metadata()