Skip to content

Commit 132f655

Browse files
authored
tests for simulation and file transfer + upgrade ansys-optics-speos-grpcapi + precise version of docker image (#51)
* Add tests for simulation and file transfer + upgrade ansys-optics-speos-grpcapi + precise version of docker image * use new version of docker image ghcr.io/pyansys/pyoptics/speos-rpc:2022.2.0.235 * fix test * fix test
1 parent 0ca3822 commit 132f655

File tree

5 files changed

+123
-10
lines changed

5 files changed

+123
-10
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.4"
22
services:
33
pyoptics_speos-rpc:
4-
image: ghcr.io/pyansys/pyoptics/speos-rpc
4+
image: ghcr.io/pyansys/pyoptics/speos-rpc:2022.2.0.235
55
container_name: pyoptics_speos-rpc
66
ports:
77
- "50051:50051"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers=[
2323
"Operating System :: OS Independent",
2424
]
2525
dependencies=[
26-
"ansys-optics-speos-grpcapi==5.0.0",
26+
"ansys-optics-speos-grpcapi==6.0.0",
2727
"grpcio-tools==1.48.1",
2828
]
2929

requirements/requirements_build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build==0.8.0
22
twine==4.0.1
3-
ansys-optics-speos-grpcapi==5.0.0
3+
ansys-optics-speos-grpcapi==6.0.0
44
grpcio-tools==1.48.1

tests/test_lpf_file_reader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from conftest import config, local_test_path, test_path
2323

2424

25-
def test_lpf_file_reader_mono_v1_DirectSimu():
25+
def test_lpf_file_reader_mono_v2_DirectSimu():
2626
# Lpf file reader creation
2727
stub = grpc_stub.get_stub_insecure_channel(
2828
target="localhost:" + str(config.get("SpeosServerPort")),
@@ -73,7 +73,7 @@ def test_lpf_file_reader_mono_v1_DirectSimu():
7373
stub.CloseLpfFileName(lpf_file_reader__v2__pb2.CloseLpfFileName_Request_Mono())
7474

7575

76-
def test_lpf_file_reader_mono_v1_InverseSimu():
76+
def test_lpf_file_reader_mono_v2_InverseSimu():
7777
# Lpf file reader creation
7878
stub = grpc_stub.get_stub_insecure_channel(
7979
target="localhost:" + str(config.get("SpeosServerPort")),
@@ -110,7 +110,7 @@ def test_lpf_file_reader_mono_v1_InverseSimu():
110110
stub.CloseLpfFileName(lpf_file_reader__v2__pb2.CloseLpfFileName_Request_Mono())
111111

112112

113-
def test_lpf_file_reader_multi_v1():
113+
def test_lpf_file_reader_multi_v2():
114114
# Lpf file reader multi creation
115115
stub = grpc_stub.get_stub_insecure_channel(
116116
target="localhost:" + str(config.get("SpeosServerPort")),
@@ -181,7 +181,7 @@ def test_lpf_file_reader_multi_v1():
181181
stub.Delete(lpf_file_reader__v2__pb2.Delete_Request_Multi(lpf_reader_guid=guid))
182182

183183

184-
def test_lpf_file_reader_mono_v1_DirectSimu_with_upload():
184+
def test_lpf_file_reader_mono_v2_DirectSimu_with_file_transfer():
185185
# local file upload to the server
186186
path = os.path.join(local_test_path, "basic_DirectSimu.lpf")
187187
file_transfer_stub = grpc_stub.get_stub_insecure_channel(
@@ -197,7 +197,7 @@ def test_lpf_file_reader_mono_v1_DirectSimu_with_upload():
197197
)
198198

199199
# Init with uri from file transfer
200-
stub.InitLpfFileName(lpf_file_reader__v2__pb2.InitLpfFileName_Request_Mono(lpf_file_uri=upload_response.uri))
200+
stub.InitLpfFileName(lpf_file_reader__v2__pb2.InitLpfFileName_Request_Mono(lpf_file_uri=upload_response.info.uri))
201201

202202
# GetInformation
203203
res_information = stub.GetInformation(lpf_file_reader__v2__pb2.GetInformation_Request_Mono())
@@ -239,4 +239,4 @@ def test_lpf_file_reader_mono_v1_DirectSimu_with_upload():
239239
stub.CloseLpfFileName(lpf_file_reader__v2__pb2.CloseLpfFileName_Request_Mono())
240240

241241
# Delete the file previously uploaded to the server - it is no more needed
242-
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=upload_response.uri))
242+
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=upload_response.info.uri))

tests/test_simulation.py

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
1212
"""
1313
import os
14+
import shutil
1415

1516
from ansys.api.speos import grpc_stub
17+
from ansys.api.speos.file.v1 import file_transfer
18+
import ansys.api.speos.file.v1.file_transfer_pb2 as file_transfer__v1__pb2
19+
import ansys.api.speos.file.v1.file_transfer_pb2_grpc as file_transfer__v1__pb2_grpc
1620
import ansys.api.speos.simulation.v1.simulation_pb2 as simulation__v1__pb2
1721
import ansys.api.speos.simulation.v1.simulation_pb2_grpc as simulation__v1__pb2_grpc
1822

19-
from conftest import config, test_path
23+
from conftest import config, local_test_path, test_path
2024
from helper import does_file_exist, remove_file
2125

2226

@@ -74,3 +78,112 @@ def test_simulation():
7478
delete_request = simulation__v1__pb2.Delete_Request()
7579
delete_request.guid = guid_simu.guid
7680
simulation_manager_stub.Delete(delete_request)
81+
82+
83+
def test_simu_allocateSyst_load_run_with_file_transfer():
84+
# Stubs creations
85+
file_transfer_stub = grpc_stub.get_stub_insecure_channel(
86+
target="localhost:50051",
87+
stub_type=file_transfer__v1__pb2_grpc.FileTransferServiceStub,
88+
)
89+
simu_manager_stub = grpc_stub.get_stub_insecure_channel(
90+
target="localhost:50051",
91+
stub_type=simulation__v1__pb2_grpc.SpeosSimulationsManagerStub,
92+
)
93+
simu_stub = grpc_stub.get_stub_insecure_channel(
94+
target="localhost:50051",
95+
stub_type=simulation__v1__pb2_grpc.SpeosSimulationStub,
96+
)
97+
98+
# Use upload_folder helper provided within ansys.api.speos.file.v1
99+
sv5_name = "LG_50M_Colorimetric_short.sv5"
100+
upload_responses = file_transfer.upload_folder(
101+
file_transfer_service_stub=file_transfer_stub,
102+
folder_path=os.path.join(local_test_path, sv5_name),
103+
main_file_name=sv5_name,
104+
)
105+
sv5_res_uri = [upload_res.info.uri for upload_res in upload_responses if upload_res.info.file_name == sv5_name][0]
106+
107+
# Allocate system
108+
create_res = simu_manager_stub.Create(simulation__v1__pb2.Create_Request())
109+
110+
# Load sv5 into allocated system
111+
simu_stub.Load(simulation__v1__pb2.Load_Request(guid=create_res.guid, input_file_path=sv5_res_uri))
112+
113+
# Run
114+
run_res = simu_stub.Run(simulation__v1__pb2.Run_Request(guid=create_res.guid))
115+
assert len(run_res.result_upload_responses) == 2
116+
assert run_res.result_upload_responses[0].info.file_name == "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp"
117+
assert run_res.result_upload_responses[1].info.file_name == "ASSEMBLY1.DS (0).html"
118+
119+
# Delete files on Server
120+
# Files uploaded
121+
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=sv5_res_uri))
122+
# Results from simu
123+
for res_uploaded in run_res.result_upload_responses:
124+
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=res_uploaded.info.uri))
125+
126+
127+
def test_simu_allocateSyst_load_save_with_file_transfer():
128+
# Stubs creations
129+
file_transfer_stub = grpc_stub.get_stub_insecure_channel(
130+
target="localhost:50051",
131+
stub_type=file_transfer__v1__pb2_grpc.FileTransferServiceStub,
132+
)
133+
simu_manager_stub = grpc_stub.get_stub_insecure_channel(
134+
target="localhost:50051",
135+
stub_type=simulation__v1__pb2_grpc.SpeosSimulationsManagerStub,
136+
)
137+
simu_stub = grpc_stub.get_stub_insecure_channel(
138+
target="localhost:50051",
139+
stub_type=simulation__v1__pb2_grpc.SpeosSimulationStub,
140+
)
141+
sv5_name = "LG_50M_Colorimetric_short.sv5"
142+
blue_spectrum = "Blue Spectrum.spectrum"
143+
red_spectrum = "Red Spectrum.spectrum"
144+
145+
# Use upload_folder helper provided within ansys.api.speos.file.v1
146+
upload_responses = file_transfer.upload_folder(
147+
file_transfer_service_stub=file_transfer_stub,
148+
folder_path=os.path.join(local_test_path, sv5_name),
149+
main_file_name=sv5_name,
150+
)
151+
sv5_res_uri = [upload_res.info.uri for upload_res in upload_responses if upload_res.info.file_name == sv5_name][0]
152+
153+
# Allocate system
154+
create_res = simu_manager_stub.Create(simulation__v1__pb2.Create_Request())
155+
156+
# Load sv5 into allocated system
157+
simu_stub.Load(simulation__v1__pb2.Load_Request(guid=create_res.guid, input_file_path=sv5_res_uri))
158+
159+
# Reserve an item in file system in order to perform a Save
160+
reserve_res = file_transfer_stub.Reserve(file_transfer__v1__pb2.Reserve_Request())
161+
# And Save
162+
simu_stub.Save(simulation__v1__pb2.Save_Request(guid=create_res.guid, input_folder_path=reserve_res.uri))
163+
164+
# We can then list dependencies of the reserved item to check that it contains two deps with correct names
165+
deps_response = file_transfer_stub.ListDependencies(
166+
file_transfer__v1__pb2.ListDependencies_Request(uri=reserve_res.uri)
167+
)
168+
assert len(deps_response.dependency_infos) == 2
169+
assert [dep_info for dep_info in deps_response.dependency_infos if dep_info.file_name == blue_spectrum]
170+
assert [dep_info for dep_info in deps_response.dependency_infos if dep_info.file_name == red_spectrum]
171+
172+
# And download locally the simu saved - using download_folder helper provided within ansys.api.speos.file.v1
173+
download_loc = os.path.join(local_test_path, "download_simu")
174+
os.mkdir(download_loc)
175+
download_responses = file_transfer.download_folder(
176+
file_transfer_service_stub=file_transfer_stub, main_file_uri=reserve_res.uri, download_location=download_loc
177+
)
178+
# Check that file are well downloaded
179+
for res in download_responses:
180+
downloaded_file = os.path.join(download_loc, res.info.file_name)
181+
assert os.path.exists(downloaded_file)
182+
assert os.path.getsize(downloaded_file) == res.info.file_size
183+
shutil.rmtree(download_loc)
184+
185+
# Delete files on Server
186+
# Files uploaded
187+
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=sv5_res_uri))
188+
# Files saved
189+
file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=reserve_res.uri))

0 commit comments

Comments
 (0)