Debian Codegraph @

tests/instruments/hp/test_hp34401a.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 import pytest
26 from pymeasure.test import expected_protocol
27
28 from pymeasure.instruments.hp.hp34401A import HP34401A
29
30
31 @pytest.mark.parametrize("function_", HP34401A.FUNCTIONS.keys())
32 def test_function(function_):
33 with expected_protocol(
34 HP34401A,
35 [
36 ("FUNC?", HP34401A.FUNCTIONS[function_]),
37 (f"FUNC \"{HP34401A.FUNCTIONS[function_]}\"", None),
38 ],
39 ) as inst:
40 assert function_ == inst.function_
41 inst.function_ = function_
42
43
44 def test_range_dcv():
45 with expected_protocol(
46 HP34401A,
47 [
48 ("FUNC \"VOLT\"", None),
49 ("FUNC?", "VOLT"),
50 ("VOLT:RANG?", "1"),
51 ("FUNC?", "VOLT"),
52 ("VOLT:RANG 1", None),
53 ],
54 ) as inst:
55 inst.function_ = "DCV"
56 assert 1 == inst.range_
57 inst.range_ = 1
58
59
60 def test_range_freq():
61 with expected_protocol(
62 HP34401A,
63 [
64 ("FUNC \"FREQ\"", None),
65 ("FUNC?", "FREQ"),
66 ("FREQ:VOLT:RANG?", "1"),
67 ("FUNC?", "FREQ"),
68 ("FREQ:VOLT:RANG 1", None),
69 ],
70 ) as inst:
71 inst.function_ = "FREQ"
72 assert 1 == inst.range_
73 inst.range_ = 1
74
75
76 @pytest.mark.parametrize("enabled", [True, False])
77 def test_autorange_dcv(enabled):
78 with expected_protocol(
79 HP34401A,
80 [
81 ("FUNC \"VOLT\"", None),
82 ("FUNC?", "VOLT"),
83 ("VOLT:RANG:AUTO?", "1" if enabled else "0"),
84 ("FUNC?", "VOLT"),
85 (f"VOLT:RANG:AUTO {1 if enabled else 0}", None),
86 ],
87 ) as inst:
88 inst.function_ = "DCV"
89 assert enabled == inst.autorange
90 inst.autorange = enabled
91
92
93 @pytest.mark.parametrize("enabled", [True, False])
94 def test_autorange_freq(enabled):
95 with expected_protocol(
96 HP34401A,
97 [
98 ("FUNC \"FREQ\"", None),
99 ("FUNC?", "FREQ"),
100 ("FREQ:VOLT:RANG:AUTO?", "1" if enabled else "0"),
101 ("FUNC?", "FREQ"),
102 (f"FREQ:VOLT:RANG:AUTO {1 if enabled else 0}", None),
103 ],
104 ) as inst:
105 inst.function_ = "FREQ"
106 assert enabled == inst.autorange
107 inst.autorange = enabled
108
109
110 @pytest.mark.parametrize("function_", HP34401A.FUNCTIONS.keys())
111 def test_resolution(function_):
112 with expected_protocol(
113 HP34401A,
114 [
115 (f"FUNC \"{HP34401A.FUNCTIONS[function_]}\"", None),
116 ("FUNC?", HP34401A.FUNCTIONS[function_]),
117 (f"{HP34401A.FUNCTIONS[function_]}:RES?", "1"),
118 ("FUNC?", HP34401A.FUNCTIONS[function_]),
119 (f"{HP34401A.FUNCTIONS[function_]}:RES 1", None),
120 ],
121 ) as inst:
122 inst.function_ = function_
123 assert 1 == inst.resolution
124 inst.resolution = 1
125
126
127 @pytest.mark.parametrize("function_", HP34401A.FUNCTIONS.keys())
128 def test_nplc(function_):
129 with expected_protocol(
130 HP34401A,
131 [
132 (f"FUNC \"{HP34401A.FUNCTIONS[function_]}\"", None),
133 ("FUNC?", HP34401A.FUNCTIONS[function_]),
134 (f"{HP34401A.FUNCTIONS[function_]}:NPLC?", "1"),
135 ("FUNC?", HP34401A.FUNCTIONS[function_]),
136 (f"{HP34401A.FUNCTIONS[function_]}:NPLC 1", None),
137 ],
138 ) as inst:
139 inst.function_ = function_
140 assert 1 == inst.nplc
141 inst.nplc = 1
142
143
144 @pytest.mark.parametrize("function_", ["FREQ", "PERIOD"])
145 def test_gate_time(function_):
146 with expected_protocol(
147 HP34401A,
148 [
149 (f"FUNC \"{HP34401A.FUNCTIONS[function_]}\"", None),
150 ("FUNC?", HP34401A.FUNCTIONS[function_]),
151 (f"{HP34401A.FUNCTIONS[function_]}:APER?", "1"),
152 ("FUNC?", HP34401A.FUNCTIONS[function_]),
153 (f"{HP34401A.FUNCTIONS[function_]}:APER 1", None),
154 ],
155 ) as inst:
156 inst.function_ = function_
157 assert 1 == inst.gate_time
158 inst.gate_time = 1
159
160
161 def test_detector_bandwidth():
162 with expected_protocol(
163 HP34401A,
164 [
165 ("DET:BAND?", "3"),
166 ("DET:BAND 3", None),
167 ],
168 ) as inst:
169 assert 3 == inst.detector_bandwidth
170 inst.detector_bandwidth = 3
171
172
173 @pytest.mark.parametrize("enabled", [True, False])
174 def test_autozero_enabled(enabled):
175 with expected_protocol(
176 HP34401A,
177 [
178 ("ZERO:AUTO?", "1" if enabled else "0"),
179 (f"ZERO:AUTO {1 if enabled else 0}", None),
180 ],
181 ) as inst:
182 assert enabled == inst.autozero_enabled
183 inst.autozero_enabled = enabled
184
185
186 def test_trigger_single_autozero():
187 with expected_protocol(
188 HP34401A,
189 [
190 ("ZERO:AUTO ONCE", None),
191 ],
192 ) as inst:
193 inst.trigger_single_autozero()
194
195
196 @pytest.mark.parametrize("enabled", [True, False])
197 def test_auto_input_impedance_enabled(enabled):
198 with expected_protocol(
199 HP34401A,
200 [
201 ("INP:IMP:AUTO?", "1" if enabled else "0"),
202 (f"INP:IMP:AUTO {1 if enabled else 0}", None),
203 ],
204 ) as inst:
205 assert enabled == inst.auto_input_impedance_enabled
206 inst.auto_input_impedance_enabled = enabled
207
208
209 def test_terminals_used():
210 with expected_protocol(
211 HP34401A,
212 [
213 ("ROUT:TERM?", "FRON"),
214 ],
215 ) as inst:
216 assert "FRONT" == inst.terminals_used
217
218
219 def test_init_trigger():
220 with expected_protocol(
221 HP34401A,
222 [
223 ("INIT", None)
224 ],
225 ) as inst:
226 inst.init_trigger()
227
228
229 def test_reading():
230 with expected_protocol(
231 HP34401A,
232 [
233 ("READ?", "1")
234 ],
235 ) as inst:
236 assert 1 == inst.reading
237
238
239 @pytest.mark.parametrize("trigger_source", ["BUS", "EXT", "IMM"])
240 def test_trigger_source(trigger_source):
241 with expected_protocol(
242 HP34401A,
243 [
244 ("TRIG:SOUR?", trigger_source),
245 (f"TRIG:SOUR {trigger_source}", None),
246 ],
247 ) as inst:
248 assert trigger_source == inst.trigger_source
249 inst.trigger_source = trigger_source
250
251
252 def test_trigger_delay():
253 with expected_protocol(
254 HP34401A,
255 [
256 ("TRIG:DEL?", "1"),
257 ("TRIG:DEL 1", None),
258 ],
259 ) as inst:
260 assert 1 == inst.trigger_delay
261 inst.trigger_delay = 1
262
263
264 @pytest.mark.parametrize("enabled", [True, False])
265 def test_trigger_auto_delay_enabled(enabled):
266 with expected_protocol(
267 HP34401A,
268 [
269 ("TRIG:DEL:AUTO?", "1" if enabled else "0"),
270 (f"TRIG:DEL:AUTO {1 if enabled else 0}", None),
271 ],
272 ) as inst:
273 assert enabled == inst.trigger_auto_delay_enabled
274 inst.trigger_auto_delay_enabled = enabled
275
276
277 def test_sample_count():
278 with expected_protocol(
279 HP34401A,
280 [
281 ("SAMP:COUN?", "1"),
282 ("SAMP:COUN 1", None),
283 ],
284 ) as inst:
285 assert 1 == inst.sample_count
286 inst.sample_count = 1
287
288
289 def test_trigger_count():
290 with expected_protocol(
291 HP34401A,
292 [
293 ("TRIG:COUN?", "1"),
294 ("TRIG:COUN 1", None),
295 ],
296 ) as inst:
297 assert 1 == inst.trigger_count
298 inst.trigger_count = 1
299
300
301 def test_stored_reading():
302 with expected_protocol(
303 HP34401A,
304 [
305 ("FETC?", "1"),
306 ],
307 ) as inst:
308 assert 1 == inst.stored_reading
309
310
311 @pytest.mark.parametrize("enabled", [True, False])
312 def test_display_enabled(enabled):
313 with expected_protocol(
314 HP34401A,
315 [
316 ("DISP?", "1" if enabled else "0"),
317 (f"DISP {1 if enabled else 0}", None),
318 ],
319 ) as inst:
320 assert enabled == inst.display_enabled
321 inst.display_enabled = enabled
322
323
324 def test_displayed_text():
325 with expected_protocol(
326 HP34401A,
327 [
328 ("DISP:TEXT?", "HELLO"),
329 ("DISP:TEXT \"HELLO\"", None),
330 ],
331 ) as inst:
332 assert "HELLO" == inst.displayed_text
333 inst.displayed_text = "HELLO"
334
335
336 def test_beep():
337 with expected_protocol(
338 HP34401A,
339 [
340 ("SYST:BEEP", None),
341 ],
342 ) as inst:
343 inst.beep()
344
345
346 @pytest.mark.parametrize("enabled", [True, False])
347 def test_beeper_enabled(enabled):
348 with expected_protocol(
349 HP34401A,
350 [
351 ("SYST:BEEP:STAT?", "1" if enabled else "0"),
352 (f"SYST:BEEP:STAT {1 if enabled else 0}", None),
353 ],
354 ) as inst:
355 assert enabled == inst.beeper_enabled
356 inst.beeper_enabled = enabled
357
358
359 def test_scpi_version():
360 with expected_protocol(
361 HP34401A,
362 [
363 ("SYST:VERS?", "1-2-3"),
364 ],
365 ) as inst:
366 assert "1-2-3" == inst.scpi_version
367
368
369 def test_stored_readings_count():
370 with expected_protocol(
371 HP34401A,
372 [
373 ("DATA:POIN?", "1"),
374 ],
375 ) as inst:
376 assert 1 == inst.stored_readings_count
377
378
379 def test_self_test_result():
380 with expected_protocol(
381 HP34401A,
382 [
383 ("*TST?", "0"),
384 ],
385 ) as inst:
386 assert 0 == inst.self_test_result