Debian Codegraph @

tests/instruments/ipgphotonics/test_yar.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25
26 import pytest
27 from pymeasure.test import expected_protocol
28
29 from pymeasure.instruments.ipgphotonics.yar import YAR
30
31
32 init_comm = [("RNP", "RNP: 0.200"), ("RMP", "RMP: 10.5"), ("RDPT", "RDPT: 0.100")]
33
34 ################################
35 # Values according to the manual
36
37
38 def test_init():
39 """This test tests already getting min/max output power."""
40 with expected_protocol(
41 YAR,
42 init_comm
43 ):
44 pass
45
46
47 def test_status_emission():
48 with expected_protocol(
49 YAR,
50 init_comm + [("STA", "STA: 1")]
51 ) as inst:
52 assert inst.status == YAR.Status.EMISSION
53
54
55 def test_status_backreflection():
56 with expected_protocol(
57 YAR,
58 init_comm + [("STA", "STA: 131072")]
59 ) as inst:
60 assert inst.status == YAR.Status.HIGH_BACKREFLECTION
61
62
63 def test_emission_enabled_getter():
64 with expected_protocol(
65 YAR,
66 init_comm + [("STA", "STA:1")]
67 ) as inst:
68 assert inst.emission_enabled is True
69
70
71 def test_emission_enabled_setter_on():
72 with expected_protocol(
73 YAR,
74 init_comm + [("EMON", "EMON")]
75 ) as inst:
76 inst.emission_enabled = True
77
78
79 def test_emission_enabled_setter_off():
80 with expected_protocol(
81 YAR,
82 init_comm + [("EMOFF", "EMOFF")]
83 ) as inst:
84 inst.emission_enabled = False
85
86
87 def test_power():
88 with expected_protocol(
89 YAR,
90 init_comm + [("ROP", "ROP: 3.45")]
91 ) as inst:
92 assert inst.power == 3.45
93
94
95 def test_power_off():
96 """Verify, that power 'Off' is translated to 0."""
97 with expected_protocol(
98 YAR,
99 init_comm + [("ROP", "ROP: Off")]
100 ) as inst:
101 assert inst.power == 0
102
103
104 def test_power_low():
105 """Verify, that power 'Low' is translated to the default minimum 0.1."""
106 with expected_protocol(
107 YAR,
108 init_comm + [("ROP", "ROP: Low")]
109 ) as inst:
110 assert inst.power == 0.1
111
112
113 def test_init_sets_minimum_display_power():
114 """Test, that a different minimum power is shown in the translation of 'Low'."""
115 # not in the manual!
116 with expected_protocol(
117 YAR,
118 # init_comm is modified
119 [("RNP", "RNP: 0.200"), ("RMP", "RMP: 10.5"), ("RDPT", "RDPT: 5"),
120 ("ROP", "ROP: Low")]
121 ) as inst:
122 assert inst.power == 5
123
124
125 def test_power_setpoint_getter():
126 with expected_protocol(
127 YAR,
128 init_comm + [("RPS", "RPS: 1.23")]
129 ) as inst:
130 assert inst.power_setpoint == 1.23
131
132
133 def test_power_setpoint_setter():
134 with expected_protocol(
135 YAR,
136 init_comm + [("SPS 9.7", "SPS: 9.7")]
137 ) as inst:
138 inst.power_setpoint = 9.7
139
140
141 def test_power_setpoint_setter_out_of_range_driver():
142 with expected_protocol(
143 YAR,
144 # init_comm is modified
145 [("RNP", "RNP: 0.200"), ("RMP", "RMP: 10.5"), ("RDPT", "RDPT: 0.100")]
146 ) as inst:
147 with pytest.raises(ValueError):
148 inst.power_setpoint = 20
149
150
151 def test_power_setpoint_setter_out_of_range_device():
152 with expected_protocol(
153 YAR,
154 init_comm + [("SPS 5", "ERR: Out of Range")]
155 ) as inst:
156 with pytest.raises(ConnectionError):
157 inst.power_setpoint = 5
158
159
160 def test_current():
161 with expected_protocol(
162 YAR,
163 init_comm + [("RDC", "RDC: 2.34")]
164 ) as inst:
165 assert inst.current == 2.34
166
167
168 def test_temperature():
169 with expected_protocol(
170 YAR,
171 init_comm + [("RCT", "RCT: 28.9")]
172 ) as inst:
173 assert inst.temperature == 28.9
174
175
176 def test_wavelength_temperature_getter():
177 with expected_protocol(
178 YAR,
179 init_comm + [("RWA", "RWA: 31.345")]
180 ) as inst:
181 assert inst.wavelength_temperature == 31.345
182
183
184 def test_wavelength_temperature_setter():
185 with expected_protocol(
186 YAR,
187 init_comm + [("SWA 35.658", "SWA: 35.658")]
188 ) as inst:
189 inst.wavelength_temperature = 35.658
190
191
192 def test_seed_temperature():
193 with expected_protocol(
194 YAR,
195 init_comm + [("RST", "RST: 31.345")]
196 ) as inst:
197 assert inst.temperature_seed == 31.345
198
199
200 def test_clear():
201 with expected_protocol(
202 YAR,
203 init_comm + [("RERR", "RERR")]
204 ) as inst:
205 inst.clear()
206
207
208 def test_model():
209 with expected_protocol(
210 YAR,
211 init_comm + [("RMN", "RMN: YLM-10-SF")]
212 ) as inst:
213 assert inst.id == "YLM-10-SF"
214
215
216 def test_firmware():
217 with expected_protocol(
218 YAR,
219 init_comm + [("RFV", "RFV: 1.0.114")]
220 ) as inst:
221 assert inst.firmware == "1.0.114"
222
223
224 def test_minimum_display_power():
225 with expected_protocol(
226 YAR,
227 init_comm + [("RDPT", "RDPT: 0.100")]
228 ) as inst:
229 assert inst.minimum_display_power == 0.1