1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import pytest
import time
import logging
from pymeasure.instruments.hp.hp34401A import HP34401A
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
FUNCTIONS = ["DCV", "DCV_RATIO", "ACV", "DCI", "ACI", "R2W",
"R4W", "FREQ", "PERIOD", "CONTINUITY", "DIODE"]
FUNCTIONS_WITH_RANGE = ["DCV", "ACV", "DCI", "ACI",
"R2W", "R4W", "FREQ", "PERIOD"]
TEST_RANGES = {
"DCV": [0.1, 1, 10], "ACV": [0.1, 1, 10], "DCI": [0.1, 1, 3],
"ACI": [1, 3], "R2W": [100, 1e3, 10e3], "R4W": [100, 1e3, 10e3],
"FREQ": [0.1, 1, 10], "PERIOD": [0.1, 1, 10]}
@pytest.fixture(scope="module")
def hp34401a(connected_device_address):
instr = HP34401A(connected_device_address)
return instr
@pytest.fixture
def resetted_hp34401a(hp34401a):
hp34401a.clear()
hp34401a.write("*RST")
return hp34401a
def test_correct_model_by_idn(resetted_hp34401a):
assert "34401a" in resetted_hp34401a.id.lower()
@pytest.mark.parametrize("function_", FUNCTIONS)
def test_given_function_when_set_then_function_is_set(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.function_ == function_
@pytest.mark.parametrize("function_", FUNCTIONS)
def test_given_function_is_set_then_reading_avaliable(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.reading is not None
@pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
def test_given_function_is_set_then_range_avaliable(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.range_ is not None
@pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
def test_given_function_set_then_autorange_enabled(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.autorange is True
@pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
def test_given_range_set_then_range_correct(resetted_hp34401a, function_):
for range in TEST_RANGES[function_]:
resetted_hp34401a.function_ = function_
resetted_hp34401a.range_ = range
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.range_ == range
@pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
def test_autorange_enable(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
resetted_hp34401a.autorange = True
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.autorange is True
@pytest.mark.parametrize("function_", FUNCTIONS_WITH_RANGE)
def test_autorange_disable(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
resetted_hp34401a.autorange = False
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.autorange is False
def test_dcv_range_min_max(resetted_hp34401a):
resetted_hp34401a.function_ = "DCV"
resetted_hp34401a.range_ = "MIN"
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.range_ == 0.1
resetted_hp34401a.range_ = "MAX"
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.range_ == 1000
@pytest.mark.parametrize("enabled", [True, False])
def test_display_enabled(resetted_hp34401a, enabled):
resetted_hp34401a.display_enabled = enabled
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.display_enabled == enabled
@pytest.mark.parametrize("function_", ["DCV", "ACV", "DCI", "R2W"])
def test_resolution(resetted_hp34401a, function_):
resetted_hp34401a.function_ = function_
resetted_hp34401a.range_ = 1
resetted_hp34401a.resolution = 0.0001
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.resolution == 0.0001
@pytest.mark.parametrize("function_", ["DCV", "DCI", "R2W"])
@pytest.mark.parametrize("nplc", [0.02, 1, 100])
def test_nplc(resetted_hp34401a, function_, nplc):
resetted_hp34401a.function_ = function_
resetted_hp34401a.nplc = nplc
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.nplc == nplc
@pytest.mark.parametrize("function_", ["FREQ", "PERIOD"])
@pytest.mark.parametrize("gate_time", [0.01, 0.01, 1])
def test_gate_time(resetted_hp34401a, function_, gate_time):
resetted_hp34401a.function_ = function_
resetted_hp34401a.gate_time = gate_time
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.gate_time == gate_time
@pytest.mark.parametrize("detector_bandwidth", [3, 20, 200])
def test_detector_bandwidth(resetted_hp34401a, detector_bandwidth):
resetted_hp34401a.function_ = "FREQ"
resetted_hp34401a.detector_bandwidth = detector_bandwidth
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.detector_bandwidth == detector_bandwidth
@pytest.mark.parametrize("enable", [True, False])
def test_autozero(resetted_hp34401a, enable):
resetted_hp34401a.autozero_enabled = enable
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.autozero_enabled == enable
def test_single_autozero(resetted_hp34401a):
resetted_hp34401a.autozero_enabled = True
resetted_hp34401a.trigger_single_autozero()
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.autozero_enabled is False
def test_auto_input_impedance(resetted_hp34401a):
resetted_hp34401a.auto_input_impedance_enabled = True
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.auto_input_impedance_enabled is True
resetted_hp34401a.auto_input_impedance_enabled = False
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.auto_input_impedance_enabled is False
def test_terminals_used(resetted_hp34401a):
assert resetted_hp34401a.terminals_used in ["FRONT", "REAR"]
assert len(resetted_hp34401a.check_errors()) == 0
def test_when_init_trigger_called_then_no_error(resetted_hp34401a):
resetted_hp34401a.init_trigger()
assert len(resetted_hp34401a.check_errors()) == 0
@pytest.mark.parametrize("trigger_source", ["IMM", "BUS", "EXT"])
def test_trigger_source(resetted_hp34401a, trigger_source):
resetted_hp34401a.trigger_source = trigger_source
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.trigger_source == trigger_source
def test_trigger_delay(resetted_hp34401a):
resetted_hp34401a.trigger_delay = 10.5
trigger_delay = resetted_hp34401a.trigger_delay
assert len(resetted_hp34401a.check_errors()) == 0
assert trigger_delay == 10.5
@pytest.mark.parametrize("enabled", [True, False])
def test_trigger_auto_delay_enabled(resetted_hp34401a, enabled):
resetted_hp34401a.trigger_auto_delay_enabled = enabled
trigger_auto_delay_enabled = resetted_hp34401a.trigger_auto_delay_enabled
assert len(resetted_hp34401a.check_errors()) == 0
assert trigger_auto_delay_enabled == enabled
def test_sample_count(resetted_hp34401a):
resetted_hp34401a.sample_count = 10
assert resetted_hp34401a.sample_count == 10
assert len(resetted_hp34401a.check_errors()) == 0
def test_trigger_count(resetted_hp34401a):
resetted_hp34401a.trigger_count = 10
assert len(resetted_hp34401a.check_errors()) == 0
assert resetted_hp34401a.trigger_count == 10
def test_read_stored_reading_multiple_readings(resetted_hp34401a):
resetted_hp34401a: HP34401A = resetted_hp34401a
resetted_hp34401a.sample_count = 10
resetted_hp34401a.trigger_source = "IMM"
resetted_hp34401a.nplc = 0.02
resetted_hp34401a.init_trigger()
resetted_hp34401a.complete
readings = resetted_hp34401a.stored_reading
print(readings)
assert len(resetted_hp34401a.check_errors()) == 0
assert len(readings) == 10
def test_displayed_text(resetted_hp34401a):
resetted_hp34401a.displayed_text = "Hello World"
assert resetted_hp34401a.displayed_text == "Hello World"
assert len(resetted_hp34401a.check_errors()) == 0
def test_beep(resetted_hp34401a):
resetted_hp34401a.beep()
assert len(resetted_hp34401a.check_errors()) == 0
@pytest.mark.parametrize("enabled", [True, False])
def test_beeper_enabled(resetted_hp34401a, enabled):
resetted_hp34401a.beeper_enabled = enabled
assert resetted_hp34401a.beeper_enabled == enabled
assert len(resetted_hp34401a.check_errors()) == 0
def test_scpi_version(resetted_hp34401a):
assert len(str(resetted_hp34401a.scpi_version)) > 0
assert len(resetted_hp34401a.check_errors()) == 0
def test_stored_readings_count(resetted_hp34401a):
resetted_hp34401a.nplc = 0.02
resetted_hp34401a.sample_count = 10
resetted_hp34401a.trigger_source = "IMM"
resetted_hp34401a.init_trigger()
time.sleep(1)
assert resetted_hp34401a.stored_readings_count == 10
assert len(resetted_hp34401a.check_errors()) == 0
def test_self_test_result(resetted_hp34401a):
resetted_hp34401a.adapter.connection.timeout = 60000
assert resetted_hp34401a.self_test_result in [True, False]
assert len(resetted_hp34401a.check_errors()) == 0
|