Skip to content

Commit d4e5d2a

Browse files
committed
refactor: update _file method to allow empty string parameters in _MapdlCommandExtended class test: enhance test_inquire_exist to use temporary files and validate existence checks
1 parent d35c9bf commit d4e5d2a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/ansys/mapdl/core/mapdl_extended.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def file(self, fname: str = "", ext: str = "", **kwargs) -> str:
109109
file_, ext_, _ = self._decompose_fname(fname)
110110
return self._file(file_, ext_, **kwargs)
111111

112-
def _file(self, filename: str, extension: str, **kwargs) -> str:
112+
def _file(self, filename: str = "", extension: str = "", **kwargs) -> str:
113113
"""Run the MAPDL ``file`` command with a proper filename."""
114114
return self.run(f"FILE,{filename},{extension}", **kwargs)
115115

tests/test_mapdl.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,13 +1285,23 @@ def test_inquire_jobname(mapdl, cleared):
12851285
assert jobname
12861286

12871287

1288-
def test_inquire_exist(mapdl, cleared):
1289-
existing_file = [each for each in mapdl.list_files() if each.endswith(".log")][0]
1290-
assert isinstance(mapdl.inquire("", "exist", existing_file), bool)
1291-
assert isinstance(mapdl.inquire("", "exist", "unexisting_file.myext"), bool)
1288+
def test_inquire_exist(mapdl, cleared, tmpdir):
1289+
try:
1290+
existing_file = tempfile.mkstemp(suffix=".log")[1]
1291+
mapdl.upload(existing_file)
1292+
1293+
basename = os.path.basename(existing_file)
1294+
assert isinstance(mapdl.inquire("", "exist", basename), bool)
1295+
assert isinstance(mapdl.inquire("", "exist", "unexisting_file.myext"), bool)
12921296

1293-
assert mapdl.inquire("", "exist", existing_file)
1294-
assert not mapdl.inquire("", "exist", "unexisting_file.myext")
1297+
assert mapdl.inquire("", "exist", basename)
1298+
assert not mapdl.inquire("", "exist", "unexisting_file.myext")
1299+
1300+
finally:
1301+
# Clean up the temporary file
1302+
if os.path.exists(existing_file):
1303+
os.remove(existing_file)
1304+
mapdl.slashdelete(basename)
12951305

12961306

12971307
def test_inquire_non_interactive(mapdl, cleared):
@@ -1562,7 +1572,7 @@ def test_equal_in_comments_and_title(mapdl, cleared):
15621572

15631573
def test_result_file(mapdl, solved_box):
15641574
assert mapdl.result_file
1565-
assert isinstance(mapdl.result_file, str)
1575+
assert isinstance(mapdl.result_file, (str, pathlib.PurePath))
15661576

15671577

15681578
@requires("local")

0 commit comments

Comments
 (0)