11import os
2+ import sys
23
34import appdirs
45import pytest
78from ansys .tools .path .path import (
89 _check_uncommon_executable_path ,
910 _clear_config_file ,
11+ _is_common_executable_path ,
1012 change_default_mapdl_path ,
13+ find_mechanical ,
1114 get_available_ansys_installations ,
1215 get_mapdl_path ,
1316 is_valid_executable_path ,
1821paths = [
1922 ("/usr/dir_v2019.1/slv/ansys_inc/v211/ansys/bin/ansys211" , 211 ),
2023 ("C:/Program Files/ANSYS Inc/v202/ansys/bin/win64/ANSYS202.exe" , 202 ),
24+ ("C:\\ Program Files\\ ANSYS Inc\\ v202\\ ansys\\ bin\\ win64\\ ANSYS202.exe" , 202 ),
2125 ("/usr/ansys_inc/v211/ansys/bin/mapdl" , 211 ),
2226 pytest .param (("/usr/ansys_inc/ansys/bin/mapdl" , 211 ), marks = pytest .mark .xfail ),
2327]
2428
29+ mechanical_paths = [
30+ ("/usr/install/ansys_inc/v211/ansys/aisol/.workbench" , 211 ),
31+ ("C:\\ Program Files\\ ANSYS Inc\\ v202\\ aisol\\ Bin\\ winx64\\ ANSYSWBU.exe" , 202 ),
32+ ("C:/Program Files/ANSYS Inc/v202/aisol/Bin/winx64/ANSYSWBU.exe" , 202 ),
33+ ]
34+
35+ linux_mapdl_executable_paths = [
36+ ("/usr/dir_v2019.1/slv/ansys_inc/v211/ansys/bin/ansys211" , True ),
37+ ("/usr/ansys_inc/v211/ansys/bin/mapdl" , False ),
38+ ]
39+
40+ windows_mapdl_executable_paths = [
41+ ("C:/Program Files/ANSYS Inc/v202/ansys/bin/win64/ANSYS202.exe" , True ),
42+ ("C:\\ Program Files\\ ANSYS Inc\\ v202\\ ansys\\ bin\\ win64\\ ANSYS202.exe" , True ),
43+ ]
44+
45+ windows_mechanical_executable_paths = [
46+ ("C:\\ Program Files\\ ANSYS Inc\\ v221\\ aisol\\ Bin\\ winx64\\ ANSYSWBU.exe" , True ),
47+ ("C:/Program Files/ANSYS Inc/v221/aisol/Bin/winx64/ANSYSWBU.exe" , True ),
48+ ]
49+
50+ linux_mechanical_executable_paths = [
51+ ("/usr/install/ansys_inc/v211/ansys/aisol/.workbench" , True ),
52+ ]
53+
2554
2655skip_if_ansys_not_local = pytest .mark .skipif (
2756 os .environ .get ("ANSYS_LOCAL" , "" ).upper () != "TRUE" , reason = "Skipping on CI"
@@ -34,6 +63,11 @@ def test_mapdl_version_from_path(path_data):
3463 assert version_from_path ("mapdl" , exec_file ) == version
3564
3665
66+ @pytest .mark .parametrize ("exec_file,version" , mechanical_paths )
67+ def test_mechanical_version_from_path (exec_file , version ):
68+ assert version_from_path ("mechanical" , exec_file ) == version
69+
70+
3771@skip_if_ansys_not_local
3872def test_find_mapdl_linux ():
3973 # assuming Ansys MAPDL is installed, should be able to find it on linux
@@ -107,3 +141,58 @@ def test_warn_uncommon_executable_path():
107141def test_get_mapdl_path ():
108142 assert get_mapdl_path ()
109143 assert get_mapdl_path (version = 222 )
144+
145+
146+ @pytest .fixture
147+ def mock_is_valid_executable_path (monkeypatch : pytest .MonkeyPatch ):
148+ monkeypatch .setattr ("ansys.tools.path.path.is_valid_executable_path" , lambda _1 , _2 : True )
149+
150+
151+ @pytest .mark .skipif (sys .platform != "win32" , reason = "Test only available on windows" )
152+ @pytest .mark .parametrize ("path,expected" , windows_mapdl_executable_paths )
153+ def test_windows_is_common_executable_path_mapdl (mock_is_valid_executable_path , path , expected ):
154+ assert _is_common_executable_path ("mapdl" , path ) == expected
155+
156+
157+ @pytest .mark .skipif (sys .platform != "linux" , reason = "Test only available on linux" )
158+ @pytest .mark .parametrize ("path,expected" , linux_mapdl_executable_paths )
159+ def test_linux_is_common_executable_path_mapdl (mock_is_valid_executable_path , path , expected ):
160+ assert _is_common_executable_path ("mapdl" , path ) == expected
161+
162+
163+ @pytest .mark .skipif (sys .platform != "win32" , reason = "Test only available on windows" )
164+ @pytest .mark .parametrize ("path,expected" , windows_mechanical_executable_paths )
165+ def test_windows_is_common_executable_path_mechanical (
166+ mock_is_valid_executable_path , path , expected
167+ ):
168+ assert _is_common_executable_path ("mechanical" , path ) == expected
169+
170+
171+ @pytest .mark .skipif (sys .platform != "linux" , reason = "Test only available on linux" )
172+ @pytest .mark .parametrize ("path,expected" , linux_mechanical_executable_paths )
173+ def test_linux_is_common_executable_path_mechanical (mock_is_valid_executable_path , path , expected ):
174+ assert _is_common_executable_path ("mechanical" , path ) == expected
175+
176+
177+ @pytest .fixture
178+ def mock_default_linux_base_path (monkeypatch : pytest .MonkeyPatch ):
179+ monkeypatch .setattr ("os.path.isdir" , lambda x : (x == "/usr/ansys_inc" ))
180+ monkeypatch .setattr ("ansys.tools.path.path.glob" , lambda _ : ["/usr/ansys_inc/v221" ])
181+
182+
183+ @pytest .fixture
184+ def mock_empty_linux_base_path (monkeypatch : pytest .MonkeyPatch ):
185+ monkeypatch .setattr ("os.path.isdir" , lambda x : (x == "/usr/ansys_inc" ))
186+ monkeypatch .setattr ("ansys.tools.path.path.glob" , lambda _ : [])
187+
188+
189+ def test_get_available_ansys_installation (mock_default_linux_base_path ):
190+ assert get_available_ansys_installations () == {221 : "/usr/ansys_inc/v221" }
191+
192+
193+ def test_empty_ansys_inttallation (mock_empty_linux_base_path ):
194+ assert get_available_ansys_installations () == {}
195+
196+
197+ def test_find_mechanical (mock_default_linux_base_path ):
198+ assert find_mechanical () == ("/usr/ansys_inc/v221/aisol/.workbench" , 22.1 )
0 commit comments