Debian Codegraph @

tests/instruments/hp/test_hp34401a_with_device.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 import time
27 import logging
28 from pymeasure.instruments.hp.hp34401A import HP34401A
29
30 log = logging.getLogger(__name__)
31 log.addHandler(logging.NullHandler())
32
33 FUNCTIONS = ["DCV", "DCV_RATIO", "ACV", "DCI", "ACI", "R2W",
34 "R4W", "FREQ", "PERIOD", "CONTINUITY", "DIODE"]
35
36 FUNCTIONS_WITH_RANGE = ["DCV", "ACV", "DCI", "ACI",
37 "R2W", "R4W", "FREQ", "PERIOD"]
38
39 TEST_RANGES = {
40 "DCV": [0.1, 1, 10], "ACV": [0.1, 1, 10], "DCI": [0.1, 1, 3],
41 "ACI": [1, 3], "R2W": [100, 1e3, 10e3], "R4W": [100, 1e3, 10e3],
42 "FREQ": [0.1, 1, 10], "PERIOD": [0.1, 1, 10]}
43
44
45 @pytest.fixture(scope="module")
46 def hp34401a(connected_device_address):
47 instr = HP34401A(connected_device_address)
48 return instr
49
50
51 @pytest.fixture
52 def resetted_hp34401a(hp34401a):
53 hp34401a.clear()
54 hp34401a.write("*RST")
55 return hp34401a
56
57
58 def test_correct_model_by_idn(resetted_hp34401a):
59 assert "34401a" in resetted_hp34401a.id.lower()
60
61
62 @pytest.mark.parametrize("function_", FUNCTIONS)
63 def test_given_function_when_set_then_function_is_set(resetted_hp34401a, function_):
64 resetted_hp34401a.function_ = function_
65 assert len(resetted_hp34401a.check_errors()) == 0
66 assert resetted_hp34401a.function_ == function_
67
68
69 @pytest.mark.parametrize("function_", FUNCTIONS)
70 def test_given_function_is_set_then_reading_avaliable(resetted_hp34401a, function_):
71 resetted_hp34401a.function_ = function_
72 assert len(resetted_hp34401a.check_errors()) == 0
73 assert resetted_hp34401a.reading is not None
74
75
76 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
77 def test_given_function_is_set_then_range_avaliable(resetted_hp34401a, function_):
78 resetted_hp34401a.function_ = function_
79 assert len(resetted_hp34401a.check_errors()) == 0
80 assert resetted_hp34401a.range_ is not None
81
82
83 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
84 def test_given_function_set_then_autorange_enabled(resetted_hp34401a, function_):
85 resetted_hp34401a.function_ = function_
86 assert len(resetted_hp34401a.check_errors()) == 0
87 assert resetted_hp34401a.autorange is True
88
89
90 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
91 def test_given_range_set_then_range_correct(resetted_hp34401a, function_):
92 for range in TEST_RANGES[function_]:
93 resetted_hp34401a.function_ = function_
94 resetted_hp34401a.range_ = range
95 assert len(resetted_hp34401a.check_errors()) == 0
96 assert resetted_hp34401a.range_ == range
97
98
99 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
100 def test_autorange_enable(resetted_hp34401a, function_):
101 resetted_hp34401a.function_ = function_
102 resetted_hp34401a.autorange = True
103 assert len(resetted_hp34401a.check_errors()) == 0
104 assert resetted_hp34401a.autorange is True
105
106
107 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
108 def test_autorange_disable(resetted_hp34401a, function_):
109 resetted_hp34401a.function_ = function_
110 resetted_hp34401a.autorange = False
111 assert len(resetted_hp34401a.check_errors()) == 0
112 assert resetted_hp34401a.autorange is False
113
114
115 def test_dcv_range_min_max(resetted_hp34401a):
116 resetted_hp34401a.function_ = "DCV"
117 resetted_hp34401a.range_ = "MIN"
118 assert len(resetted_hp34401a.check_errors()) == 0
119 assert resetted_hp34401a.range_ == 0.1
120 resetted_hp34401a.range_ = "MAX"
121 assert len(resetted_hp34401a.check_errors()) == 0
122 assert resetted_hp34401a.range_ == 1000
123
124
125 @pytest.mark.parametrize("enabled", [True, False])
126 def test_display_enabled(resetted_hp34401a, enabled):
127 resetted_hp34401a.display_enabled = enabled
128 assert len(resetted_hp34401a.check_errors()) == 0
129 assert resetted_hp34401a.display_enabled == enabled
130
131
132 @pytest.mark.parametrize("function_", ["DCV", "ACV", "DCI", "R2W"])
133 def test_resolution(resetted_hp34401a, function_):
134 resetted_hp34401a.function_ = function_
135 resetted_hp34401a.range_ = 1
136 resetted_hp34401a.resolution = 0.0001
137 assert len(resetted_hp34401a.check_errors()) == 0
138 assert resetted_hp34401a.resolution == 0.0001
139
140
141 @pytest.mark.parametrize("function_", ["DCV", "DCI", "R2W"])
142 @pytest.mark.parametrize("nplc", [0.02, 1, 100])
143 def test_nplc(resetted_hp34401a, function_, nplc):
144 resetted_hp34401a.function_ = function_
145 resetted_hp34401a.nplc = nplc
146 assert len(resetted_hp34401a.check_errors()) == 0
147 assert resetted_hp34401a.nplc == nplc
148
149
150 @pytest.mark.parametrize("function_", ["FREQ", "PERIOD"])
151 @pytest.mark.parametrize("gate_time", [0.01, 0.01, 1])
152 def test_gate_time(resetted_hp34401a, function_, gate_time):
153 resetted_hp34401a.function_ = function_
154 resetted_hp34401a.gate_time = gate_time
155 assert len(resetted_hp34401a.check_errors()) == 0
156 assert resetted_hp34401a.gate_time == gate_time
157
158
159 @pytest.mark.parametrize("detector_bandwidth", [3, 20, 200])
160 def test_detector_bandwidth(resetted_hp34401a, detector_bandwidth):
161 resetted_hp34401a.function_ = "FREQ"
162 resetted_hp34401a.detector_bandwidth = detector_bandwidth
163 assert len(resetted_hp34401a.check_errors()) == 0
164 assert resetted_hp34401a.detector_bandwidth == detector_bandwidth
165
166
167 @pytest.mark.parametrize("enable", [True, False])
168 def test_autozero(resetted_hp34401a, enable):
169 resetted_hp34401a.autozero_enabled = enable
170 assert len(resetted_hp34401a.check_errors()) == 0
171 assert resetted_hp34401a.autozero_enabled == enable
172
173
174 def test_single_autozero(resetted_hp34401a):
175 resetted_hp34401a.autozero_enabled = True
176 resetted_hp34401a.trigger_single_autozero()
177 assert len(resetted_hp34401a.check_errors()) == 0
178 assert resetted_hp34401a.autozero_enabled is False
179
180
181 def test_auto_input_impedance(resetted_hp34401a):
182 resetted_hp34401a.auto_input_impedance_enabled = True
183 assert len(resetted_hp34401a.check_errors()) == 0
184 assert resetted_hp34401a.auto_input_impedance_enabled is True
185 resetted_hp34401a.auto_input_impedance_enabled = False
186 assert len(resetted_hp34401a.check_errors()) == 0
187 assert resetted_hp34401a.auto_input_impedance_enabled is False
188
189
190 def test_terminals_used(resetted_hp34401a):
191 assert resetted_hp34401a.terminals_used in ["FRONT", "REAR"]
192 assert len(resetted_hp34401a.check_errors()) == 0
193
194
195 def test_when_init_trigger_called_then_no_error(resetted_hp34401a):
196 resetted_hp34401a.init_trigger()
197 assert len(resetted_hp34401a.check_errors()) == 0
198
199
200 @pytest.mark.parametrize("trigger_source", ["IMM", "BUS", "EXT"])
201 def test_trigger_source(resetted_hp34401a, trigger_source):
202 resetted_hp34401a.trigger_source = trigger_source
203 assert len(resetted_hp34401a.check_errors()) == 0
204 assert resetted_hp34401a.trigger_source == trigger_source
205
206
207 def test_trigger_delay(resetted_hp34401a):
208 resetted_hp34401a.trigger_delay = 10.5
209 trigger_delay = resetted_hp34401a.trigger_delay
210 assert len(resetted_hp34401a.check_errors()) == 0
211 assert trigger_delay == 10.5
212
213
214 @pytest.mark.parametrize("enabled", [True, False])
215 def test_trigger_auto_delay_enabled(resetted_hp34401a, enabled):
216 resetted_hp34401a.trigger_auto_delay_enabled = enabled
217 trigger_auto_delay_enabled = resetted_hp34401a.trigger_auto_delay_enabled
218 assert len(resetted_hp34401a.check_errors()) == 0
219 assert trigger_auto_delay_enabled == enabled
220
221
222 def test_sample_count(resetted_hp34401a):
223 resetted_hp34401a.sample_count = 10
224 assert resetted_hp34401a.sample_count == 10
225 assert len(resetted_hp34401a.check_errors()) == 0
226
227
228 def test_trigger_count(resetted_hp34401a):
229 resetted_hp34401a.trigger_count = 10
230 assert len(resetted_hp34401a.check_errors()) == 0
231 assert resetted_hp34401a.trigger_count == 10
232
233
234 def test_read_stored_reading_multiple_readings(resetted_hp34401a):
235 resetted_hp34401a: HP34401A = resetted_hp34401a
236 resetted_hp34401a.sample_count = 10
237 resetted_hp34401a.trigger_source = "IMM"
238 resetted_hp34401a.nplc = 0.02
239 resetted_hp34401a.init_trigger()
240 resetted_hp34401a.complete
241 readings = resetted_hp34401a.stored_reading
242 print(readings)
243 assert len(resetted_hp34401a.check_errors()) == 0
244 assert len(readings) == 10
245
246
247 def test_displayed_text(resetted_hp34401a):
248 resetted_hp34401a.displayed_text = "Hello World"
249 assert resetted_hp34401a.displayed_text == "Hello World"
250 assert len(resetted_hp34401a.check_errors()) == 0
251
252
253 def test_beep(resetted_hp34401a):
254 resetted_hp34401a.beep()
255 assert len(resetted_hp34401a.check_errors()) == 0
256
257
258 @pytest.mark.parametrize("enabled", [True, False])
259 def test_beeper_enabled(resetted_hp34401a, enabled):
260 resetted_hp34401a.beeper_enabled = enabled
261 assert resetted_hp34401a.beeper_enabled == enabled
262 assert len(resetted_hp34401a.check_errors()) == 0
263
264
265 def test_scpi_version(resetted_hp34401a):
266 assert len(str(resetted_hp34401a.scpi_version)) > 0
267 assert len(resetted_hp34401a.check_errors()) == 0
268
269
270 def test_stored_readings_count(resetted_hp34401a):
271 resetted_hp34401a.nplc = 0.02
272 resetted_hp34401a.sample_count = 10
273 resetted_hp34401a.trigger_source = "IMM"
274 resetted_hp34401a.init_trigger()
275 time.sleep(1)
276 assert resetted_hp34401a.stored_readings_count == 10
277 assert len(resetted_hp34401a.check_errors()) == 0
278
279
280 def test_self_test_result(resetted_hp34401a):
281 resetted_hp34401a.adapter.connection.timeout = 60000
282 assert resetted_hp34401a.self_test_result in [True, False]
283 assert len(resetted_hp34401a.check_errors()) == 0