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

Improved /TBFT function. #782

Merged
merged 17 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
24 changes: 24 additions & 0 deletions ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,30 @@ 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):

if oper.lower() == 'eadd':
# Option 2 is a file and option 4 is the directory.
# Option 3 is be extension
option3 = option3.replace('.', '')
filename = os.path.join(option4, option2 + '.' + option3)

if self._local:
if not os.path.exists(file) and filename not in self.list_files:
raise Exception(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 Exception(f"File '{filename}' could not be found.")

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

@protect_grpc
def input(
self,
Expand Down
27 changes: 26 additions & 1 deletion tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,29 @@ 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", ['expdata.dat', 'expdata', 'expdata'])
@pytest.mark.parametrize("option3", ['', '.dat', 'dat'])
@pytest.mark.parametrize("option4", ['', '', os.getcwd()])
def test_tbft(mapdl, option2, option3, option4):
fname = 'expdata0.dat'
with open(fname, '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""")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the tmpdir fixture instead of writing to the local directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Implementing this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmhh... I cannot use tmpdir because that will create a file in a tmpdir, hence I would have to modify the @parametrize options, which are outside of that function. It probably can be done, but I feel like it is not worthy.

Also I want to check the option where only fname is given, hence it cannot be in a folder.

Other option is too forget the parametrize and use a more elaborated case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other option is too forget the parametrize and use a more elaborated case.

In this case it might be acceptable to create the file in the current working directory given the inflexibility of this command. What I would do instead is try...finally. That way we'll still capture all the AssertionError raised by our assert statements, but always remove the file in finally.


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

assert fname in mapdl.list_files

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