Skip to content

Commit

Permalink
Improved /TBFT function. (#782)
Browse files Browse the repository at this point in the history
* Improved /TBFT function.
It does know upload the experimental data files.

* Improved /TBFT function.
It does know upload the experimental data files.

* Added test case.

* Small fix.

* Apply suggestions from code review

Co-authored-by: Alex Kaszynski <[email protected]>

* Using get.

* Fixing test unit.

* Fixing test unit.

* Fixing tbft

* Added another unit test with raises File not found.

* Added another unit test with raises File not found.

And fixs.

* Added try and finally statements.

* Improved unit test.

Co-authored-by: Alex Kaszynski <[email protected]>
  • Loading branch information
germa89 and akaszynski authored Dec 21, 2021
1 parent a4f9b64 commit 2cafb93
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
25 changes: 25 additions & 0 deletions ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,31 @@ def cdread(self, *args, **kwargs):

self.input(fname, **kwargs)

@wraps(_MapdlCore.tbft)
def tbft(self, oper='', id_='', option1='', option2='', option3='', option4='', option5='', option6='', option7='', **kwargs):
"""Wraps ``_MapdlCore.tbft``."""
if oper.lower() == 'eadd':
# Option 2 is a file and option 4 is the directory.
# Option 3 is be extension
option3 = option3.replace('.', '')
fname = option2 if not option3 else option2 + '.' + option3
filename = os.path.join(option4, fname)

if self._local:
if not os.path.exists(filename) and filename not in self.list_files():
raise FileNotFoundError(f"File '{filename}' could not be found.")
else:
if os.path.exists(filename):
self.upload(filename)
option4 = '' # You don't need the directory if you upload it.
elif filename in self.list_files():
option4 = '' # You don't need the directory if the file is in WDIR
pass
else:
raise FileNotFoundError(f"File '{filename}' could not be found.")

return super().tbft(oper, id_, option1, option2, option3, option4, option5, option6, option7, **kwargs)

@protect_grpc
def input(
self,
Expand Down
40 changes: 39 additions & 1 deletion tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,42 @@ def test_inquire(mapdl):
# **Returning Information About a File to a Parameter**
jobname = mapdl.inquire("", 'jobname')
assert float(mapdl.inquire("", 'exist', jobname + '.lock')) in [0, 1]
assert float(mapdl.inquire("", 'exist', jobname , 'lock')) in [0, 1]
assert float(mapdl.inquire("", 'exist', jobname, 'lock')) in [0, 1]


@pytest.mark.parametrize("option2,option3,option4", [('expdata.dat', '', ''), ('expdata', '.dat', ''), ('expdata', 'dat', 'DIR')])
def test_tbft(mapdl, option2, option3, option4):
try:
fname = 'expdata.dat'
fpath = os.path.join(os.getcwd(), fname)

with open(fpath, 'w') as fid:
fid.write("""0.819139E-01 0.82788577E+00
0.166709E+00 0.15437247E+01
0.253960E+00 0.21686152E+01
0.343267E+00 0.27201819E+01
0.434257E+00 0.32129833E+0""")

if option4 == 'DIR':
option4 = os.getcwd()

mapdl.prep7(mute=True)
mat_id = mapdl.get_value('MAT', 0, 'NUM', 'MAX') + 1
mapdl.tbft('FADD', mat_id, 'HYPER', 'MOONEY', '3', mute=True)
mapdl.tbft('EADD', mat_id, 'UNIA', option2, option3, option4, mute=True)

assert fname in mapdl.list_files()

finally:
try:
os.remove(fname)
except OSError:
pass


def test_tbft_not_found(mapdl):
with pytest.raises(FileNotFoundError):
mapdl.prep7(mute=True)
mat_id = mapdl.get_value('MAT', 0, 'NUM', 'MAX') + 1
mapdl.tbft('FADD', mat_id, 'HYPER', 'MOONEY', '3', mute=True)
mapdl.tbft('EADD', mat_id, 'UNIA', 'non_existing.file', '', '', mute=True)

0 comments on commit 2cafb93

Please sign in to comment.