Skip to content

Commit 4e9fc46

Browse files
feat: adding opened attribute (#3731)
* feat: adding opened attribute * feat: adding opened attribute * chore: adding changelog file 3731.miscellaneous.md [dependabot-skip] * docs: adding docstring * fix: tests * fix: test --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 7f9b44a commit 4e9fc46

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

doc/changelog.d/3731.miscellaneous.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: adding opened attribute

src/ansys/mapdl/core/xpl.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def close(self):
124124
"""
125125
response = self._mapdl.run("*XPL,CLOSE")
126126
self._check_ignored(response)
127+
self._filename = None
127128
self._open = False
128129
return response
129130

@@ -373,6 +374,8 @@ def save(self):
373374
"""Save the current file, ignoring the marked records."""
374375
response = self._mapdl.run("*XPL,SAVE").strip()
375376
self._check_ignored(response)
377+
self._open = False
378+
self._filename = None
376379
return response
377380

378381
def extract(self, recordname, sets="ALL", asarray=False):
@@ -550,8 +553,22 @@ def write(self, recordname, vecname):
550553
def __repr__(self):
551554
txt = "MAPDL File Explorer\n"
552555
if self._open:
553-
txt += "\tOpen file:%s" % self._filename
556+
txt += f"\tOpen file : {self._filename}"
554557
txt += "\n".join(self.where().splitlines()[1:])
555558
else:
556559
txt += "\tNo open file"
557560
return txt
561+
562+
@property
563+
def opened(self):
564+
"""
565+
Check if a file is currently open.
566+
567+
Returns:
568+
str or None: The filename if a file is open, otherwise None.
569+
"""
570+
571+
if self._open:
572+
return self._filename
573+
else:
574+
return None

tests/test_xpl.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def create_cube(self, mapdl):
4646
from conftest import clear
4747

4848
clear(mapdl)
49+
mapdl.clear()
50+
mapdl.prep7()
4951

5052
# set up the full file
5153
mapdl.block(0, 1, 0, 1, 0, 1)
@@ -70,9 +72,12 @@ def create_cube(self, mapdl):
7072
if mapdl.result_file in mapdl.list_files():
7173
mapdl.slashdelete(mapdl.result_file)
7274

75+
if "cube_solve_xpl" in mapdl.list_files():
76+
mapdl.slashdelete("cube_solve_xpl.db")
77+
7378
# solve first 10 non-trivial modes
7479
mapdl.modal_analysis(nmode=10, freqb=1)
75-
mapdl.save("cube_solve_xpl")
80+
mapdl.save("cube_solve_xpl", "db")
7681

7782
@pytest.fixture(scope="class")
7883
def cube_solve(self, mapdl):
@@ -81,17 +86,20 @@ def cube_solve(self, mapdl):
8186
@pytest.fixture(scope="function")
8287
def xpl(self, mapdl, cube_solve):
8388
mapdl.prep7()
84-
mapdl.resume("cube_solve_xpl")
89+
mapdl.resume("cube_solve_xpl", "db")
8590

8691
xpl = mapdl.xpl
8792
if not self.full_file and not self.full_file in mapdl.list_files():
8893
self.create_cube(mapdl)
8994

9095
xpl.open(self.full_file)
91-
return xpl
9296

93-
@staticmethod
94-
def test_close(xpl):
97+
yield xpl
98+
99+
if xpl.opened:
100+
xpl.close()
101+
102+
def test_close(self, xpl):
95103
xpl.close()
96104
with pytest.raises(MapdlCommandIgnoredError):
97105
xpl.list()
@@ -198,3 +206,10 @@ def test_extract(self, xpl):
198206

199207
mat = xpl.extract("NSL")
200208
assert mat.shape == (243, 10)
209+
210+
def test_opened(self, xpl):
211+
assert xpl.opened
212+
xpl.close()
213+
assert not xpl.opened
214+
xpl.open(self.full_file)
215+
assert xpl.opened

0 commit comments

Comments
 (0)