| 1 |
import pytest |
| 2 |
|
| 3 |
from pymeasure.test import expected_protocol |
| 4 |
from pymeasure.instruments.hp import HP33120A |
| 5 |
|
| 6 |
|
| 7 |
def test_init(): |
| 8 |
with expected_protocol( |
| 9 |
HP33120A, |
| 10 |
[(b'SOUR:VOLT:UNIT VPP', None)], |
| 11 |
): |
| 12 |
pass # Verify the expected communication. |
| 13 |
|
| 14 |
|
| 15 |
def test_amplitude_setter(): |
| 16 |
with expected_protocol( |
| 17 |
HP33120A, |
| 18 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 19 |
(b'SOUR:VOLT 4', None)], |
| 20 |
) as inst: |
| 21 |
inst.amplitude = 4 |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 25 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 26 |
(b'SOUR:VOLT?', b'+4.00000E+00')], |
| 27 |
4.0), |
| 28 |
)) |
| 29 |
def test_amplitude_getter(comm_pairs, value): |
| 30 |
with expected_protocol( |
| 31 |
HP33120A, |
| 32 |
comm_pairs, |
| 33 |
) as inst: |
| 34 |
assert inst.amplitude == value |
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 38 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 39 |
(b'SOUR:VOLT:UNIT?', b'VPP')], |
| 40 |
'Vpp'), |
| 41 |
)) |
| 42 |
def test_amplitude_units_getter(comm_pairs, value): |
| 43 |
with expected_protocol( |
| 44 |
HP33120A, |
| 45 |
comm_pairs, |
| 46 |
) as inst: |
| 47 |
assert inst.amplitude_units == value |
| 48 |
|
| 49 |
|
| 50 |
def test_burst_count_setter(): |
| 51 |
with expected_protocol( |
| 52 |
HP33120A, |
| 53 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 54 |
(b'BM:NCYC 500', None)], |
| 55 |
) as inst: |
| 56 |
inst.burst_count = 500 |
| 57 |
|
| 58 |
|
| 59 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 60 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 61 |
(b'BM:NCYC?', b'+1.00000E+00')], |
| 62 |
1.0), |
| 63 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 64 |
(b'BM:NCYC?', b'+5.00000E+02')], |
| 65 |
500.0), |
| 66 |
)) |
| 67 |
def test_burst_count_getter(comm_pairs, value): |
| 68 |
with expected_protocol( |
| 69 |
HP33120A, |
| 70 |
comm_pairs, |
| 71 |
) as inst: |
| 72 |
assert inst.burst_count == value |
| 73 |
|
| 74 |
|
| 75 |
def test_burst_enabled_setter(): |
| 76 |
with expected_protocol( |
| 77 |
HP33120A, |
| 78 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 79 |
(b'BM:STATE 1', None)], |
| 80 |
) as inst: |
| 81 |
inst.burst_enabled = True |
| 82 |
|
| 83 |
|
| 84 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 85 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 86 |
(b'BM:STATE?', b'1')], |
| 87 |
True), |
| 88 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 89 |
(b'BM:STATE?', b'0')], |
| 90 |
False), |
| 91 |
)) |
| 92 |
def test_burst_enabled_getter(comm_pairs, value): |
| 93 |
with expected_protocol( |
| 94 |
HP33120A, |
| 95 |
comm_pairs, |
| 96 |
) as inst: |
| 97 |
assert inst.burst_enabled == value |
| 98 |
|
| 99 |
|
| 100 |
def test_burst_phase_setter(): |
| 101 |
with expected_protocol( |
| 102 |
HP33120A, |
| 103 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 104 |
(b'BM:PHAS 20', None)], |
| 105 |
) as inst: |
| 106 |
inst.burst_phase = 20 |
| 107 |
|
| 108 |
|
| 109 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 110 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 111 |
(b'BM:PHAS?', b'+0.00000E+00')], |
| 112 |
0.0), |
| 113 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 114 |
(b'BM:PHAS?', b'+2.00000E+01')], |
| 115 |
20.0), |
| 116 |
)) |
| 117 |
def test_burst_phase_getter(comm_pairs, value): |
| 118 |
with expected_protocol( |
| 119 |
HP33120A, |
| 120 |
comm_pairs, |
| 121 |
) as inst: |
| 122 |
assert inst.burst_phase == value |
| 123 |
|
| 124 |
|
| 125 |
def test_burst_rate_setter(): |
| 126 |
with expected_protocol( |
| 127 |
HP33120A, |
| 128 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 129 |
(b'BM:INT:RATE 250', None)], |
| 130 |
) as inst: |
| 131 |
inst.burst_rate = 250 |
| 132 |
|
| 133 |
|
| 134 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 135 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 136 |
(b'BM:INT:RATE?', b'+1.00000E+02')], |
| 137 |
100.0), |
| 138 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 139 |
(b'BM:INT:RATE?', b'+2.50000E+02')], |
| 140 |
250.0), |
| 141 |
)) |
| 142 |
def test_burst_rate_getter(comm_pairs, value): |
| 143 |
with expected_protocol( |
| 144 |
HP33120A, |
| 145 |
comm_pairs, |
| 146 |
) as inst: |
| 147 |
assert inst.burst_rate == value |
| 148 |
|
| 149 |
|
| 150 |
def test_burst_source_setter(): |
| 151 |
with expected_protocol( |
| 152 |
HP33120A, |
| 153 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 154 |
(b'BM:SOURCE INT', None)], |
| 155 |
) as inst: |
| 156 |
inst.burst_source = 'INT' |
| 157 |
|
| 158 |
|
| 159 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 160 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 161 |
(b'BM:SOURCE?', b'INT')], |
| 162 |
'INT'), |
| 163 |
)) |
| 164 |
def test_burst_source_getter(comm_pairs, value): |
| 165 |
with expected_protocol( |
| 166 |
HP33120A, |
| 167 |
comm_pairs, |
| 168 |
) as inst: |
| 169 |
assert inst.burst_source == value |
| 170 |
|
| 171 |
|
| 172 |
def test_frequency_setter(): |
| 173 |
with expected_protocol( |
| 174 |
HP33120A, |
| 175 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 176 |
(b'SOUR:FREQ 2000', None)], |
| 177 |
) as inst: |
| 178 |
inst.frequency = 2000.0 |
| 179 |
|
| 180 |
|
| 181 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 182 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 183 |
(b'SOUR:FREQ?', b'+2.00000000000E+03')], |
| 184 |
2000.0), |
| 185 |
([(b'SOUR:VOLT:UNIT VPP', None), |
| 186 |
(b'SOUR:FREQ?', b'+2.00000000000E+03')], |
| 187 |
2000.0), |
| 188 |
)) |
| 189 |
def test_frequency_getter(comm_pairs, value): |
| 190 |
with expected_protocol( |
| 191 |
HP33120A, |
| 192 |
comm_pairs, |
| 193 |
) as inst: |
| 194 |
assert inst.frequency == value |
| 195 |
|
| 196 |
|
| 197 |
def test_offset_getter(): |
| 198 |
with expected_protocol( |
| 199 |
HP33120A, |
| 200 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 201 |
(b'SOUR:VOLT:OFFS?', b'+0.00000E+00')], |
| 202 |
) as inst: |
| 203 |
assert inst.offset == 0.0 |
| 204 |
|
| 205 |
|
| 206 |
def test_shape_getter(): |
| 207 |
with expected_protocol( |
| 208 |
HP33120A, |
| 209 |
[(b'SOUR:VOLT:UNIT VPP', None), |
| 210 |
(b'SOUR:FUNC:SHAP?', b'SIN')], |
| 211 |
) as inst: |
| 212 |
assert inst.shape == 'sinusoid' |