7
7
import sys
8
8
import io
9
9
from ansys .dpf import core
10
+ from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0
10
11
11
12
12
13
def test_start_local ():
@@ -21,20 +22,30 @@ def test_start_local():
21
22
assert starting_server == id (core .SERVER )
22
23
23
24
24
- server_configs = [
25
- core .AvailableServerConfigs .InProcessServer ,
26
- core .AvailableServerConfigs .GrpcServer ,
27
- core .AvailableServerConfigs .LegacyGrpcServer
28
- ]
29
-
30
- server_configs_names = ["InProcessServer" ,
31
- "GrpcServer" ,
32
- "LegacyGrpcServer" ,
33
- ]
34
-
35
-
36
- @conftest .raises_for_servers_version_under ("4.0" )
37
- @pytest .mark .parametrize ("server_config" , server_configs , ids = server_configs_names , scope = "class" )
25
+ server_configs = (
26
+ [
27
+ core .AvailableServerConfigs .InProcessServer ,
28
+ core .AvailableServerConfigs .GrpcServer ,
29
+ core .AvailableServerConfigs .LegacyGrpcServer ,
30
+ ]
31
+ if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0
32
+ else [core .AvailableServerConfigs .LegacyGrpcServer ]
33
+ )
34
+
35
+ server_configs_names = (
36
+ [
37
+ "InProcessServer" ,
38
+ "GrpcServer" ,
39
+ "LegacyGrpcServer" ,
40
+ ]
41
+ if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0
42
+ else ["LegacyGrpcServer" ]
43
+ )
44
+
45
+
46
+ @pytest .mark .parametrize (
47
+ "server_config" , server_configs , ids = server_configs_names , scope = "class"
48
+ )
38
49
class TestServerConfigs :
39
50
@pytest .fixture (scope = "class" , autouse = True )
40
51
def cleanup (self , request ):
@@ -45,51 +56,101 @@ def reset_server():
45
56
46
57
request .addfinalizer (reset_server )
47
58
59
+ @pytest .mark .skipif (
60
+ not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0 ,
61
+ reason = "Ans.Dpf.Grpc.bat and .sh need AWP_ROOT221 for 221 install" ,
62
+ )
48
63
def test_start_local_custom_ansys_path (self , server_config ):
49
64
path = os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )]
50
- os .unsetenv ("AWP_ROOT" + str (core ._version .__ansys_version__ ))
51
65
try :
52
- server = core .start_local_server (ansys_path = path , use_docker_by_default = False ,
53
- config = server_config , as_global = True )
66
+ os .unsetenv ("AWP_ROOT" + str (core ._version .__ansys_version__ ))
67
+ except :
68
+ del os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )]
69
+ try :
70
+ server = core .start_local_server (
71
+ ansys_path = path ,
72
+ use_docker_by_default = False ,
73
+ config = server_config ,
74
+ as_global = True ,
75
+ )
54
76
assert isinstance (server .os , str )
55
77
if server_config != core .AvailableServerConfigs .InProcessServer :
56
78
p = psutil .Process (server .info ["server_process_id" ])
57
79
assert path in p .cwd ()
58
- os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )] = path
80
+ os .environ [
81
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
82
+ ] = path
59
83
except Exception as e :
60
- os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )] = path
84
+ os .environ [
85
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
86
+ ] = path
61
87
raise e
62
88
63
89
def test_start_local_no_ansys_path (self , server_config ):
64
- server = core .start_local_server (use_docker_by_default = False ,
65
- config = server_config , as_global = False )
90
+ server = core .start_local_server (
91
+ use_docker_by_default = False , config = server_config , as_global = False
92
+ )
66
93
assert isinstance (server .os , str )
67
94
if server_config != core .AvailableServerConfigs .InProcessServer :
68
95
p = psutil .Process (server .info ["server_process_id" ])
69
- assert os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )] in p .cwd ()
70
-
96
+ for key in os .environ .keys ():
97
+ if "AWP_ROOT" in key :
98
+ awp_root = key
99
+ assert (
100
+ os .environ [awp_root ]
101
+ in p .cwd ()
102
+ )
103
+
104
+ @pytest .mark .skipif (
105
+ not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0 ,
106
+ reason = "Ans.Dpf.Grpc.bat and .sh need AWP_ROOT221 for 221 install" ,
107
+ )
71
108
def test_start_local_ansys_path_environment_variable (self , server_config ):
72
- awp_root = os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )]
109
+ awp_root = os .environ [
110
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
111
+ ]
73
112
try :
74
113
os .environ ["ANSYS_DPF_PATH" ] = awp_root
75
- os .unsetenv ("AWP_ROOT" + str (core ._version .__ansys_version__ ))
76
- server = core .start_local_server (use_docker_by_default = False ,
77
- config = server_config )
114
+ try :
115
+ os .unsetenv ("AWP_ROOT" + str (core ._version .__ansys_version__ ))
116
+ except :
117
+ del os .environ [
118
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
119
+ ]
120
+ server = core .start_local_server (
121
+ use_docker_by_default = False , config = server_config
122
+ )
78
123
assert isinstance (server .os , str )
79
- os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )] = awp_root
80
- os .unsetenv ("ANSYS_DPF_PATH" )
124
+ os .environ [
125
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
126
+ ] = awp_root
127
+ try :
128
+ os .unsetenv ("ANSYS_DPF_PATH" )
129
+ except :
130
+ del os .environ ["ANSYS_DPF_PATH" ]
81
131
82
132
except Exception as e :
83
- os .environ ["AWP_ROOT" + str (core ._version .__ansys_version__ )] = awp_root
84
- os .unsetenv ("ANSYS_DPF_PATH" )
133
+ os .environ [
134
+ "AWP_ROOT" + str (core ._version .__ansys_version__ )
135
+ ] = awp_root
136
+ try :
137
+ os .unsetenv ("ANSYS_DPF_PATH" )
138
+ except :
139
+ del os .environ ["ANSYS_DPF_PATH" ]
85
140
raise e
86
141
87
142
def test_start_local_wrong_ansys_path (self , server_config ):
88
143
if server_config != core .AvailableServerConfigs .InProcessServer :
144
+
89
145
def test_start_local_wrong_ansys_path (self , server_config ):
90
146
with pytest .raises (NotADirectoryError ):
91
- core .start_local_server (ansys_path = "test/" , use_docker_by_default = False ,
92
- config = server_config , as_global = False )
147
+ core .start_local_server (
148
+ ansys_path = "test/" ,
149
+ use_docker_by_default = False ,
150
+ config = server_config ,
151
+ as_global = False ,
152
+ )
153
+
93
154
# the test for in process should be done in another process because if dataProcessingCore
94
155
# is already loaded, no error will be raised
95
156
else :
@@ -100,34 +161,39 @@ def test_start_local_wrong_ansys_path(self, server_config):
100
161
"from ansys.dpf import core\n "
101
162
"try:\n "
102
163
" core.start_local_server(ansys_path='test/', use_docker_by_default=False,"
103
- "config=core.server_factory.AvailableServerConfigs.InProcessServer, as_global=False)\n "
164
+ "config=core.server_factory.AvailableServerConfigs.InProcessServer,\n "
165
+ " as_global=False)\n "
104
166
"except NotADirectoryError:\n "
105
167
" exit()\n "
106
- "raise Exception('should have raised NotADirectoryError')\n "
107
- ]
108
- , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
168
+ "raise Exception('should have raised NotADirectoryError')\n " ,
169
+ ],
170
+ stdout = subprocess .PIPE ,
171
+ stderr = subprocess .PIPE ,
172
+ )
109
173
errors = ""
110
174
for line in io .TextIOWrapper (process .stderr , encoding = "utf-8" ):
111
175
errors += line
112
- if process .returncode != None :
176
+ if process .returncode is not None :
113
177
raise Exception (errors )
114
178
115
179
116
180
def test_start_local_failed_executable ():
117
181
from ansys .dpf .core ._version import __ansys_version__
118
- from ansys .dpf .core .server import find_ansys
182
+ from ansys .dpf .core .misc import find_ansys
119
183
from pathlib import Path
184
+
120
185
with pytest .raises (FileNotFoundError ):
121
- path = Path (os .environ .get ("AWP_ROOT" + __ansys_version__ ,
122
- find_ansys ())).parent .absolute ()
186
+ path = Path (
187
+ os .environ .get ("AWP_ROOT" + __ansys_version__ , find_ansys ())
188
+ ).parent .absolute ()
123
189
core .start_local_server (ansys_path = path )
124
190
125
191
126
192
def test_server_ip (server_type_remote_process ):
127
- assert server_type_remote_process .ip != None
128
- assert server_type_remote_process .port != None
129
- assert server_type_remote_process .version != None
130
- assert server_type_remote_process .info ["server_process_id" ] != None
131
- assert server_type_remote_process .info ["server_ip" ] != None
132
- assert server_type_remote_process .info ["server_port" ] != None
133
- assert server_type_remote_process .info ["server_version" ] != None
193
+ assert server_type_remote_process .ip is not None
194
+ assert server_type_remote_process .port is not None
195
+ assert server_type_remote_process .version is not None
196
+ assert server_type_remote_process .info ["server_process_id" ] is not None
197
+ assert server_type_remote_process .info ["server_ip" ] is not None
198
+ assert server_type_remote_process .info ["server_port" ] is not None
199
+ assert server_type_remote_process .info ["server_version" ] is not None
0 commit comments