| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2023 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 |
import pytest |
| 25 |
|
| 26 |
from pymeasure.test import expected_protocol |
| 27 |
|
| 28 |
from pymeasure.instruments.hp import HP437B |
| 29 |
from pymeasure.instruments.hp.hp437b import SensorType |
| 30 |
|
| 31 |
|
| 32 |
def test_calibrate(): |
| 33 |
with expected_protocol( |
| 34 |
HP437B, |
| 35 |
[("CL99.9PCT", None)], |
| 36 |
) as instr: |
| 37 |
instr.calibrate(99.9) |
| 38 |
|
| 39 |
|
| 40 |
def test_calibration_factor(): |
| 41 |
with expected_protocol( |
| 42 |
HP437B, |
| 43 |
[("KB99.9PCT", None), |
| 44 |
("ERR?", "000")], |
| 45 |
) as instr: |
| 46 |
instr.calibration_factor = 99.9 |
| 47 |
|
| 48 |
|
| 49 |
def test_display_user_message(): |
| 50 |
with expected_protocol( |
| 51 |
HP437B, |
| 52 |
[("DU TEST ", None)], |
| 53 |
) as instr: |
| 54 |
instr.display_user_message = "TEST" |
| 55 |
|
| 56 |
|
| 57 |
def test_duty_cycle_enabled(): |
| 58 |
with expected_protocol( |
| 59 |
HP437B, |
| 60 |
[("DC1", None), |
| 61 |
("ERR?", "000"), |
| 62 |
("SM", "AAaaBBCCccDDddEFGHIJKLMN1P")], |
| 63 |
) as instr: |
| 64 |
instr.duty_cycle_enabled = True |
| 65 |
assert instr.duty_cycle_enabled is True |
| 66 |
|
| 67 |
|
| 68 |
def test_duty_cycle(): |
| 69 |
with expected_protocol( |
| 70 |
HP437B, |
| 71 |
[("DY99.999PCT", None), |
| 72 |
("ERR?", "000")], |
| 73 |
) as instr: |
| 74 |
instr.duty_cycle = 0.99999 |
| 75 |
|
| 76 |
|
| 77 |
def test_frequency(): |
| 78 |
with expected_protocol( |
| 79 |
HP437B, |
| 80 |
[("FR099.9000GZ", None), |
| 81 |
("ERR?", "000")], |
| 82 |
) as instr: |
| 83 |
instr.frequency = 99.9e9 |
| 84 |
|
| 85 |
|
| 86 |
@pytest.mark.parametrize('resolution', [(1, 1), (0.1, 2), (0.01, 3)]) |
| 87 |
def test_resolution_linear(resolution): |
| 88 |
value, code = resolution |
| 89 |
with expected_protocol( |
| 90 |
HP437B, |
| 91 |
[("SM", "000000110017000A0002000000"), |
| 92 |
("RE%dEN" % code, None), |
| 93 |
("ERR?", "000")], |
| 94 |
) as instr: |
| 95 |
instr.resolution = value |
| 96 |
|
| 97 |
|
| 98 |
@pytest.mark.parametrize('resolution', [(0.1, 1), (0.01, 2), (0.001, 3)]) |
| 99 |
def test_resolution_logarithmic(resolution): |
| 100 |
value, code = resolution |
| 101 |
with expected_protocol( |
| 102 |
HP437B, |
| 103 |
[("SM", "000000110017001A0002000001"), |
| 104 |
("RE%dEN" % code, None), |
| 105 |
("ERR?", "000")], |
| 106 |
) as instr: |
| 107 |
instr.resolution = value |
| 108 |
|
| 109 |
|
| 110 |
@pytest.mark.parametrize('sensor_type', [e for e in SensorType]) |
| 111 |
def test_sensor_type(sensor_type): |
| 112 |
with expected_protocol( |
| 113 |
HP437B, |
| 114 |
[("SE%dEN" % int(sensor_type.value), None), |
| 115 |
("ERR?", "000")], |
| 116 |
) as instr: |
| 117 |
instr.sensor_type = sensor_type |