-
Notifications
You must be signed in to change notification settings - Fork 122
/
test_commands.py
192 lines (154 loc) · 5.04 KB
/
test_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import pytest
import inspect
import numpy as np
from ansys.mapdl.core import examples
from ansys.mapdl.core.commands import CommandOutput, CommandListingOutput, BoundaryConditionsListingOutput
from ansys.mapdl.core.commands import CMD_LISTING, CMD_BC_LISTING
try:
import pandas as pd
HAS_PANDAS = True
except ModuleNotFoundError:
HAS_PANDAS = False
LIST_OF_INQUIRE_FUNCTIONS = [
'ndinqr',
'elmiqr',
'kpinqr',
'lsinqr',
'arinqr',
'vlinqr',
'rlinqr',
'gapiqr',
'masiqr',
'ceinqr',
'cpinqr',
'csyiqr',
'etyiqr',
'foriqr',
'sectinqr',
'mpinqr',
'dget',
'fget',
'erinqr'
]
# Generic args
ARGS_INQ_FUNC = {
'node': 1,
'key': 0,
'ielem': 1,
'knmi': 1,
'line': 1,
'anmi': 1,
'vnmi': 1,
'nreal': 1,
'ngap': 1,
'nce': 1,
'ncp': 1,
'ncsy': 1,
'itype': 1,
'nsect': 1,
'mat': 1,
'iprop': 1,
'idf': 1,
'kcmplx': 1
}
PRNSOL_OUT = """PRINT F REACTION SOLUTIONS PER NODE
1 0.1287512532E+008 0.4266737217E+007
2 -0.1512012179E+007 0.2247558576E+007
3 -0.7065315064E+007 -0.4038004530E+007
4 -0.4297798077E+007 -0.2476291263E+007"""
CMD_DOC_STRING_INJECTOR = CMD_LISTING.copy()
CMD_DOC_STRING_INJECTOR.extend(CMD_BC_LISTING)
@pytest.fixture(scope="module")
def plastic_solve(mapdl):
mapdl.mute = True
mapdl.finish()
mapdl.clear()
mapdl.input(examples.verif_files.vmfiles["vm273"])
mapdl.post1()
mapdl.set(1, 2)
mapdl.mute = False
@pytest.fixture(scope="module")
def beam_solve(mapdl):
mapdl.mute = True
mapdl.finish()
mapdl.clear()
mapdl.input(examples.verif_files.vmfiles["vm10"])
mapdl.post1()
mapdl.set(1, 2)
mapdl.mute = False
def test_cmd_class():
output = """This is the output.
This is the second line.
These are numbers 1234567890.
These are symbols !"£$%^^@~+_@~€
This is for the format: {format1}-{format2}-{format3}"""
cmd = '/INPUT'
cmd_out = CommandOutput(output, cmd=cmd)
assert isinstance(cmd_out, (str, CommandOutput))
assert isinstance(cmd_out[1:], (str, CommandOutput))
assert isinstance(cmd_out.splitlines(), list)
assert isinstance(cmd_out.splitlines()[0], (str, CommandOutput))
assert isinstance(cmd_out.replace('a', 'c'), (str, CommandOutput))
assert isinstance(cmd_out.partition('g'), tuple)
assert isinstance(cmd_out.split('g'), list)
def test_cmd_class_prnsol_short():
cmd = 'PRRSOL,F'
out = CommandListingOutput(PRNSOL_OUT, cmd=cmd)
out_list = out.to_list()
out_array = out.to_array()
assert isinstance(out, CommandListingOutput)
assert isinstance(out_list, list) and bool(out_list)
assert isinstance(out_array, np.ndarray) and out_array.size != 0
if HAS_PANDAS:
out_df = out.to_dataframe()
assert isinstance(out_df, pd.DataFrame) and not out_df.empty
@pytest.mark.parametrize("func", LIST_OF_INQUIRE_FUNCTIONS)
def test_inquire_functions(mapdl, func):
func_ = getattr(mapdl, func)
func_args = inspect.getfullargspec(func_).args
args = [ARGS_INQ_FUNC[each_arg] for each_arg in func_args if each_arg not in ['self']]
output = func_(*args)
if 'GRPC' in mapdl._name:
assert isinstance(output, (float, int))
else:
assert isinstance(output, str)
assert '=' in output
@pytest.mark.parametrize('func,args', [
('prnsol', ('U', 'X')),
('presol', ('S', 'X')),
('presol', ('S', 'ALL'))
])
def test_output_listing(mapdl, plastic_solve, func, args):
mapdl.post1()
func_ = getattr(mapdl, func)
out = func_(*args)
out_list = out.to_list()
out_array = out.to_array()
assert isinstance(out, CommandListingOutput)
assert isinstance(out_list, list) and bool(out_list)
assert isinstance(out_array, np.ndarray) and out_array.size != 0
if HAS_PANDAS:
out_df = out.to_dataframe()
assert isinstance(out_df, pd.DataFrame) and not out_df.empty
@pytest.mark.parametrize('func', ['dlist', 'flist'])
def test_bclist(mapdl, beam_solve, func):
func_ = getattr(mapdl, func)
out = func_()
assert isinstance(out, BoundaryConditionsListingOutput)
assert isinstance(out.to_list(), list) and bool(out.to_list())
with pytest.raises(ValueError):
out.to_array()
if HAS_PANDAS:
out_df = out.to_dataframe()
assert isinstance(out_df, pd.DataFrame) and not out_df.empty
@pytest.mark.parametrize('method', CMD_DOC_STRING_INJECTOR)
def test_docstring_injector(mapdl, method):
"""Check if the docstring has been injected."""
for name in dir(mapdl):
if name[0:4].upper() == method:
func = mapdl.__getattribute__(name)
docstring = func.__doc__ # If '__func__' not present (AttributeError) very likely it has not been wrapped.
assert "Returns" in docstring
assert "``str.to_list()``" in docstring
assert "``str.to_array()``" in docstring
assert "``str.to_dataframe()``" in docstring