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

Fix coverage issue with unchanged files #1730

Merged
merged 5 commits into from
Dec 22, 2022
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
6 changes: 5 additions & 1 deletion examples/00-mapdl-examples/composite_dcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# Start MAPDL as a service
# ~~~~~~~~~~~~~~~~~~~~~~~~
# This example begins by importing the required packages and then launching Ansys Mechanical APDL.

import os
import tempfile

from ansys.dpf import core as dpf
Expand Down Expand Up @@ -448,4 +448,8 @@
###############################################################################
#
# Exit MAPDL
try:
os.remove(rst_path)
except FileNotFoundError:
pass
mapdl.exit()
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ def result(self) -> "ansys.mapdl.reader.rst.Result":
result = Result(result_path, read_mesh=False)
if result._is_cyclic:
result_path = self._result_file
else:
else: # pragma: no cover
# return the file with the last access time
filenames = [
self._distributed_result_file,
Expand Down
7 changes: 4 additions & 3 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,14 +969,15 @@ def _cache_pids(self):
pids = set(re.findall(r"-9 (\d+)", raw))
self._pids = [int(pid) for pid in pids]

def _remove_lock_file(self):
def _remove_lock_file(self, mapdl_path=None):
"""Removes the lock file.

Necessary to call this as a segfault of MAPDL or exit(0) will
not remove the lock file.
"""
self._log.debug("Removing lock file after exit.")
mapdl_path = self.directory
if mapdl_path is None: # pragma: no cover
mapdl_path = self.directory
if mapdl_path:
for lockname in [self.jobname + ".lock", "file.lock"]:
lock_file = os.path.join(mapdl_path, lockname)
Expand Down Expand Up @@ -2369,7 +2370,7 @@ def result(self):
result = Result(result_path, read_mesh=False)
if result._is_cyclic:
result_path = self._result_file
else:
else: # pragma: no cover
# return the file with the last access time
filenames = [
self._distributed_result_file,
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def read(self, recordname, asarray=False):
elif data_info.objtype in [
mapdl_pb2.DataType.DMAT,
mapdl_pb2.DataType.SMAT,
]:
]: # pragma: no cover
out = self._mapdl.math.mat(dtype=dtype, name=rand_name)
else: # pragma: no cover
raise ValueError(f"Unhandled MAPDL matrix object type {data_info.objtype}")
Expand Down
1 change: 1 addition & 0 deletions tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_basic_input_output(mapdl, tmpdir):
mapdl._send_command("/OUT, TERM", mute=True)
mapdl.download(tmpfile)
assert os.path.isfile(tmpfile)
os.remove(tmpfile)
# input file won't actually run, but we want to see if the output switches


Expand Down
10 changes: 10 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,3 +1658,13 @@ def test_mode(mapdl):
assert mapdl.is_console

mapdl._mode = "grpc" # Going back to default


def test_remove_lock_file(mapdl, tmpdir):
tmpdir_ = tmpdir.mkdir("ansys")
lock_file = tmpdir_.join("file.lock")
with open(lock_file, "w") as fid:
fid.write("test")

mapdl._remove_lock_file(tmpdir_)
assert not os.path.exists(lock_file)
7 changes: 6 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,18 @@ def test_load_file_local(mapdl, tmpdir, file_):
if mapdl._local:
with open(os.path.join(mapdl.directory, file_), "r") as fid:
assert "not that empty" in fid.read()
os.remove(file_)
else:
mapdl.download(file_)
with open(os.path.join(file_), "r") as fid:
assert "empty" in fid.read()
os.remove(file_)

# File is in the MAPDL working directory
os.remove(file_path) # removing local file
try:
os.remove(file_path) # removing local file
except FileNotFoundError:
pass
assert not os.path.exists(file_path)

mapdl.slashdelete(file_)
Expand Down