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

ci: improving testing #3716

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions doc/changelog.d/3716.dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci: improving testing
1 change: 1 addition & 0 deletions doc/changelog.d/3731.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: adding opened attribute
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ markers = [
]
testpaths = "tests"
image_cache_dir = "tests/.image_cache"
# Output logging records as they are emitted directly into the console
# https://docs.pytest.org/en/stable/how-to/logging.html#live-logs
log_cli = true

[tool.isort]
profile = "black"
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

"""Module to control interaction with MAPDL through Python"""

import atexit
# import atexit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes have been commented, is there a reason to keep them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I am still checking their impact... I might remove them, and create an issue to remind me to check this.

from functools import wraps
import glob
import logging
Expand Down Expand Up @@ -264,7 +264,7 @@ def __init__(
**start_parm,
):
"""Initialize connection with MAPDL."""
atexit.register(self.__del__) # registering to exit properly
# atexit.register(self.__del__) # registering to exit properly
self._show_matplotlib_figures = True # for testing
self._query = None
self._exited: bool = False
Expand Down
12 changes: 11 additions & 1 deletion src/ansys/mapdl/core/xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def close(self):
"""
response = self._mapdl.run("*XPL,CLOSE")
self._check_ignored(response)
self._filename = None
self._open = False
return response

Expand Down Expand Up @@ -373,6 +374,8 @@ def save(self):
"""Save the current file, ignoring the marked records."""
response = self._mapdl.run("*XPL,SAVE").strip()
self._check_ignored(response)
self._open = False
self._filename = None
return response

def extract(self, recordname, sets="ALL", asarray=False):
Expand Down Expand Up @@ -550,8 +553,15 @@ def write(self, recordname, vecname):
def __repr__(self):
txt = "MAPDL File Explorer\n"
if self._open:
txt += "\tOpen file:%s" % self._filename
txt += f"\tOpen file : {self._filename}"
txt += "\n".join(self.where().splitlines()[1:])
else:
txt += "\tNo open file"
return txt

@property
def opened(self):
if self._open:
return self._filename
else:
return None
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def path_tests(tmpdir):


def clear(mapdl):
mapdl.mute = True
# mapdl.mute = True
mapdl.finish()
# *MUST* be NOSTART. With START fails after 20 calls...
# this has been fixed in later pymapdl and MAPDL releases
Expand All @@ -525,7 +525,7 @@ def clear(mapdl):
mapdl.page("DEFA")

mapdl.prep7()
mapdl.mute = False
# mapdl.mute = False


@pytest.fixture(scope="function")
Expand Down
38 changes: 23 additions & 15 deletions tests/test_xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def create_cube(self, mapdl):

clear(mapdl)

# Delete files
self.full_file = mapdl.jobname + ".full"

if "full.file" in mapdl.list_files():
mapdl.slashdelete("full.file")

if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

# set up the full file
mapdl.block(0, 1, 0, 1, 0, 1)
mapdl.et(1, 186)
Expand All @@ -59,20 +68,9 @@ def create_cube(self, mapdl):
mapdl.esize(0.5)
mapdl.vmesh("all")

# Delete files
self.full_file = mapdl.jobname + ".full"
if "full.file" in mapdl.list_files():
mapdl.slashdelete("full.file")

if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

# solve first 10 non-trivial modes
mapdl.modal_analysis(nmode=10, freqb=1)
mapdl.save("cube_solve_xpl")
mapdl.save("cube_solve_xpl", slab="all")

@pytest.fixture(scope="class")
def cube_solve(self, mapdl):
Expand All @@ -88,10 +86,13 @@ def xpl(self, mapdl, cube_solve):
self.create_cube(mapdl)

xpl.open(self.full_file)
return xpl

@staticmethod
def test_close(xpl):
yield xpl

if xpl.opened:
xpl.close()

def test_close(self, xpl):
xpl.close()
with pytest.raises(MapdlCommandIgnoredError):
xpl.list()
Expand Down Expand Up @@ -198,3 +199,10 @@ def test_extract(self, xpl):

mat = xpl.extract("NSL")
assert mat.shape == (243, 10)

def test_opened(self, xpl):
assert xpl.opened
xpl.close()
assert not xpl.opened
xpl.open(self.full_file)
assert xpl.opened
Loading