Debian Codegraph @

tests/instruments/keithley/test_keithleyDMM6500_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 logging
27 from pymeasure.instruments.keithley import KeithleyDMM6500
28
29 log = logging.getLogger(__name__)
30 log.addHandler(logging.NullHandler())
31
32 FUNCTIONS = [
33 "voltage",
34 "voltage ac",
35 "current",
36 "current ac",
37 "resistance",
38 "resistance 4W",
39 "diode",
40 "capacitance",
41 "temperature",
42 "continuity",
43 "period",
44 "frequency",
45 "voltage ratio",
46 ]
47
48
49 FUNCTION_METHODS = {
50 "voltage": "measure_voltage",
51 "voltage ac": "measure_voltage",
52 "current": "measure_current",
53 "current ac": "measure_current",
54 "resistance": "measure_resistance",
55 "resistance 4W": "measure_resistance",
56 "diode": "measure_diode",
57 "capacitance": "measure_capacitance",
58 "temperature": "measure_temperature",
59 "period": "measure_period",
60 "frequency": "measure_frequency",
61 }
62
63 FUNCTIONS_WITH_RANGE = (
64 "current",
65 "current ac",
66 "voltage",
67 "voltage ac",
68 "resistance",
69 "resistance 4W",
70 "capacitance",
71 )
72
73 FUNCTIONS_HAVE_AUTORANGE = (
74 "current",
75 "current ac",
76 "voltage",
77 "voltage ac",
78 "resistance",
79 "resistance 4W",
80 "capacitance",
81 )
82
83 FUNCTIONS_HAVE_NPLC = (
84 "voltage",
85 "current",
86 "resistance",
87 "resistance 4W",
88 "diode",
89 "temperature",
90 "voltage ratio",
91 )
92
93 FUNCTIONS_HAVE_SAME_APERTURE = FUNCTIONS_HAVE_NPLC
94
95 FUNCTIONS_HAVE_AUTOZERO = FUNCTIONS_HAVE_NPLC
96
97 SCREEN_DISPLAY_SELS = (
98 "HOME",
99 "HOME_LARG",
100 "READ",
101 "HIST",
102 "SWIPE_FUNC",
103 "SWIPE_GRAP",
104 "SWIPE_SEC",
105 "SWIPE_SETT",
106 "SWIPE_STAT",
107 "SWIPE_USER",
108 "SWIPE_CHAN",
109 "SWIPE_NONS",
110 "SWIPE_SCAN",
111 "CHANNEL_CONT",
112 "CHANNEL_SETT",
113 "CHANNEL_SCAN",
114 "PROC",
115 )
116
117
118 @pytest.fixture(scope="module")
119 def dmm6500(connected_device_address):
120 instr = KeithleyDMM6500(connected_device_address)
121 instr.adapter.connection.timeout = 10000
122 return instr
123
124
125 @pytest.fixture
126 def resetted_dmm6500(dmm6500):
127 dmm6500.clear()
128 dmm6500.reset()
129 return dmm6500
130
131
132 def test_correct_model_by_idn(resetted_dmm6500):
133 assert "6500" in resetted_dmm6500.id.lower()
134
135
136 @pytest.mark.parametrize("function_", FUNCTIONS)
137 def test_given_function_when_set_then_function_is_set(resetted_dmm6500, function_):
138 resetted_dmm6500.mode = function_
139 assert len(resetted_dmm6500.check_errors()) == 0
140 assert resetted_dmm6500.mode == function_
141
142
143 @pytest.mark.parametrize("key", FUNCTION_METHODS)
144 def test_given_function_by_measure_xxx(resetted_dmm6500, key):
145 measure_xxx = getattr(resetted_dmm6500, FUNCTION_METHODS[key])
146 if key[-2:] == "ac":
147 measure_xxx(ac=True)
148 elif key[-2:] == "4W":
149 measure_xxx(wires=4)
150 else:
151 measure_xxx()
152
153 assert len(resetted_dmm6500.check_errors()) == 0
154 assert resetted_dmm6500.mode == key
155
156
157 @pytest.mark.parametrize("key", FUNCTION_METHODS)
158 def test_given_function_is_set_then_reading_avaliable(resetted_dmm6500, key):
159 if key[-2:] == "ac":
160 getattr(resetted_dmm6500, FUNCTION_METHODS[key])(ac=True)
161 elif key[-2:] == "4W":
162 getattr(resetted_dmm6500, FUNCTION_METHODS[key])(wires=4)
163 else:
164 getattr(resetted_dmm6500, FUNCTION_METHODS[key])()
165
166 value = getattr(resetted_dmm6500, key.split(" ")[0])
167 assert len(resetted_dmm6500.check_errors()) == 0
168 assert value is not None
169
170
171 @pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
172 def test_given_function_is_set_then_range_available(resetted_dmm6500, function_):
173 resetted_dmm6500.mode = function_
174 assert len(resetted_dmm6500.check_errors()) == 0
175 new = function_ + " range"
176 new = new.replace(" ", "_")
177 range_ = getattr(resetted_dmm6500, new)
178 assert range_ is not None
179
180
181 @pytest.mark.parametrize("key", FUNCTION_METHODS)
182 def test_given_function_set_then_autorange_enabled(resetted_dmm6500, key):
183 if key[-2:] == "ac":
184 getattr(resetted_dmm6500, FUNCTION_METHODS[key])(ac=True)
185 elif key[-2:] == "4W":
186 getattr(resetted_dmm6500, FUNCTION_METHODS[key])(wires=4)
187 else:
188 getattr(resetted_dmm6500, FUNCTION_METHODS[key])()
189
190 # resetted_dmm6500.mode = function_
191 assert len(resetted_dmm6500.check_errors()) == 0
192 assert resetted_dmm6500.auto_range_status() is False
193 resetted_dmm6500.auto_range()
194 if key in FUNCTIONS_HAVE_AUTORANGE:
195 assert resetted_dmm6500.auto_range_status() is True
196 else:
197 assert resetted_dmm6500.auto_range_status() is False
198
199
200 @pytest.mark.parametrize("function_", FUNCTIONS_HAVE_AUTORANGE)
201 def test_given_function_set_then_autorange(resetted_dmm6500, function_):
202 resetted_dmm6500.mode = function_
203 assert len(resetted_dmm6500.check_errors()) == 0
204 assert resetted_dmm6500.autorange_enabled
205 resetted_dmm6500.autorange_enabled = False
206 assert not resetted_dmm6500.autorange_enabled
207 assert len(resetted_dmm6500.check_errors()) == 0
208
209
210 def test_dcv_range_min_def_max(resetted_dmm6500):
211 resetted_dmm6500.measure_voltage()
212 assert len(resetted_dmm6500.check_errors()) == 0
213
214 resetted_dmm6500.range = "MIN"
215 assert len(resetted_dmm6500.check_errors()) == 0
216 assert resetted_dmm6500.range == 0.1
217
218 resetted_dmm6500.range = "MAX"
219 assert len(resetted_dmm6500.check_errors()) == 0
220 assert resetted_dmm6500.range == 1000
221
222 resetted_dmm6500.range = "DEF"
223 assert len(resetted_dmm6500.check_errors()) == 0
224 assert resetted_dmm6500.range == 1000
225
226
227 @pytest.mark.parametrize("function_", FUNCTIONS_HAVE_NPLC)
228 @pytest.mark.parametrize("nplc", [0.0005, 2, 15])
229 def test_nplc(resetted_dmm6500, function_, nplc):
230 resetted_dmm6500.mode = function_
231 resetted_dmm6500.nplc = nplc
232 assert len(resetted_dmm6500.check_errors()) == 0
233 assert resetted_dmm6500.nplc == nplc
234
235
236 @pytest.mark.parametrize("function_", FUNCTIONS_HAVE_SAME_APERTURE)
237 @pytest.mark.parametrize("aperture", ["MIN", "MAX", "DEF", 16.0e-3])
238 def test_general_aperture(resetted_dmm6500, function_, aperture):
239 resetted_dmm6500.mode = function_
240 resetted_dmm6500.aperture = aperture
241 assert len(resetted_dmm6500.check_errors()) == 0
242 expected_value = {"MIN": 8.33e-6, "MAX": 0.25, "DEF": 0.0166667, 16.0e-3: 16.0e-3}
243 assert resetted_dmm6500.aperture == expected_value[aperture]
244
245
246 @pytest.mark.parametrize("function_", ("frequency", "period"))
247 @pytest.mark.parametrize("aperture", ["MIN", "MAX", "DEF", 16.0e-3])
248 def test_freq_period_aperture(resetted_dmm6500, function_, aperture):
249 resetted_dmm6500.mode = function_
250 resetted_dmm6500.aperture = aperture
251 assert len(resetted_dmm6500.check_errors()) == 0
252 expected_value = {"MIN": 2e-3, "MAX": 273e-3, "DEF": 200e-3, 16.0e-3: 16.0e-3}
253 assert resetted_dmm6500.aperture == expected_value[aperture]
254
255
256 @pytest.mark.parametrize("function_", ("voltage ac", "current ac"))
257 @pytest.mark.parametrize("detector_bandwidth", [3, 30, 300])
258 def test_detector_bandwidth(resetted_dmm6500, function_, detector_bandwidth):
259 resetted_dmm6500.mode = function_
260 resetted_dmm6500.detector_bandwidth = detector_bandwidth
261 assert len(resetted_dmm6500.check_errors()) == 0
262 assert resetted_dmm6500.detector_bandwidth == detector_bandwidth
263
264
265 @pytest.mark.parametrize("function_", FUNCTIONS_HAVE_AUTOZERO)
266 @pytest.mark.parametrize("enable", [True, False])
267 def test_autozero(resetted_dmm6500, function_, enable):
268 resetted_dmm6500.mode = function_
269 resetted_dmm6500.autozero_enabled = enable
270 assert len(resetted_dmm6500.check_errors()) == 0
271 assert resetted_dmm6500.autozero_enabled == enable
272
273
274 def test_single_autozero(resetted_dmm6500):
275 resetted_dmm6500.autozero = True
276 resetted_dmm6500.trigger_single_autozero()
277 assert len(resetted_dmm6500.check_errors()) == 0
278 assert not resetted_dmm6500.autozero_enabled
279
280
281 def test_terminals_used(resetted_dmm6500):
282 assert resetted_dmm6500.terminals_used in ["FRONT", "REAR"]
283 assert len(resetted_dmm6500.check_errors()) == 0
284
285
286 @pytest.mark.parametrize("selection", SCREEN_DISPLAY_SELS)
287 def test_display_screen(resetted_dmm6500, selection):
288 resetted_dmm6500.screen_display = selection
289 assert len(resetted_dmm6500.check_errors()) == 0
290
291
292 def test_displayed_text(resetted_dmm6500):
293 resetted_dmm6500.displayed_text("Hello World", "Running test...")
294 assert len(resetted_dmm6500.check_errors()) == 0
295 resetted_dmm6500.displayed_text()
296 assert len(resetted_dmm6500.check_errors()) == 0
297 resetted_dmm6500.displayed_text("", "")
298 assert len(resetted_dmm6500.check_errors()) == 0
299
300
301 def test_beep(resetted_dmm6500): # Ambulance siren
302 for i in range(4):
303 resetted_dmm6500.beep(700, 0.5)
304 resetted_dmm6500.beep(950, 0.5)
305 assert len(resetted_dmm6500.check_errors()) == 0