Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for geometry export and particle traces handling #354

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ name = "ansys.pyensight.core"

[tool.coverage.run]
branch = true
omit = [
"*/locallauncher.py",
"*/adr.py"
]

[tool.coverage.report]
exclude_lines = [
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/pyensight/core/dockerlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def connect(self):
if self._pim_instance is None:
ws_port = self._service_host_port["ws"][1]
else:
ws_port = self._service_host_port["http"][1]
ws_port = self._service_host_port["http"][1] # pragma: no cover
session = ansys.pyensight.core.session.Session(
host=self._service_host_port["grpc_private"][0],
grpc_port=self._service_host_port["grpc_private"][1],
Expand Down
58 changes: 32 additions & 26 deletions src/ansys/pyensight/core/enshell_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -300,17 +300,17 @@ 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(
command_line=command_string, env_line=env_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)

Expand Down Expand Up @@ -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
#
Expand All @@ -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."""
Expand All @@ -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)
22 changes: 11 additions & 11 deletions src/ansys/pyensight/core/launch_ensight.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from ansys.pyensight.core.locallauncher import LocalLauncher
from ansys.pyensight.core.session import Session

pim_is_available = False
pim_is_available = False # pragma: no cover
try:
import ansys.platform.instancemanagement as pypim

pim_is_available = True
except Exception:
pass
pim_is_available = True # pragma: no cover
except Exception: # pragma: no cover
pass # pragma: no cover
logging.debug(f"pim_is_available: {pim_is_available}\n")

docker_is_available = False
Expand Down Expand Up @@ -164,10 +164,10 @@ def launch_ensight(
return launcher.start()

# use local installation of EnSight
launcher = LocalLauncher(
ansys_installation=ansys_installation,
application=application,
batch=batch,
**kwargs,
)
return launcher.start()
launcher = LocalLauncher( # pragma: no cover
ansys_installation=ansys_installation, # pragma: no cover
application=application, # pragma: no cover
batch=batch, # pragma: no cover
**kwargs, # pragma: no cover
) # pragma: no cover
return launcher.start() # pragma: no cover
34 changes: 17 additions & 17 deletions src/ansys/pyensight/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def _find_unused_ports(count: int, avoid: Optional[List[int]] = None) -> Optiona
# There have been some issues with 65534+ so we stop at 65530
port = base_port % port_mod
# port 0 is special
if port == 0:
continue
if port == 0: # pragma: no cover
continue # pragma: no cover
# avoid admin ports
if port < 1024:
continue
if port < 1024: # pragma: no cover
continue # pragma: no cover
# are we supposed to skip this one?
if port in avoid:
continue
if port in avoid: # pragma: no cover
continue # pragma: no cover
# is anyone listening?
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(("127.0.0.1", port))
Expand All @@ -219,8 +219,8 @@ def _find_unused_ports(count: int, avoid: Optional[List[int]] = None) -> Optiona
if len(ports) >= count:
return ports
# in case we failed...
if len(ports) < count:
return None
if len(ports) < count: # pragma: no cover
return None # pragma: no cover
return ports

def _use_egl(self) -> bool:
Expand All @@ -240,12 +240,12 @@ def _use_egl(self) -> bool:
# if the system can't do it, return False now
return False

if self._egl_env_val is not None:
if self._egl_env_val is not None: # pragma: no cover
# if the environment variable was set, that overrides the constructor option
return self._egl_env_val

# otherwise, use the arg passed to the constructor
return self._use_egl_param_val
return self._use_egl_param_val # pragma: no cover

def _is_system_egl_capable(self) -> bool: # pragma: no cover
"""Return True if the system supports the EGL launch.
Expand Down Expand Up @@ -292,8 +292,8 @@ def _add_query_parameters(self, params: Dict[str, str]) -> None:
params: dict :
query parameters to add to overall dict
"""
for item, value in params.items():
self._query_parameters[item] = value
for item, value in params.items(): # pragma: no cover
self._query_parameters[item] = value # pragma: no cover

def _delete_query_parameters(self, params: List[str]) -> None:
"""Delete query parameters supplied by params from the
Expand All @@ -304,8 +304,8 @@ def _delete_query_parameters(self, params: List[str]) -> None:
params: list :
query parameters to delete from the overall dict
"""
for item in params:
try:
del self._query_parameters[item]
except Exception:
pass
for item in params: # pragma: no cover
try: # pragma: no cover
del self._query_parameters[item] # pragma: no cover
except Exception: # pragma: no cover
pass # pragma: no cover
18 changes: 10 additions & 8 deletions src/ansys/pyensight/core/utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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})"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading