| 1 |
import pytest |
| 2 |
|
| 3 |
from pymeasure.test import expected_protocol |
| 4 |
from pymeasure.instruments.ametek import Ametek7270 |
| 5 |
|
| 6 |
|
| 7 |
def test_init(): |
| 8 |
with expected_protocol( |
| 9 |
Ametek7270, |
| 10 |
[], |
| 11 |
): |
| 12 |
pass # Verify the expected communication. |
| 13 |
|
| 14 |
|
| 15 |
def test_sensitivity_getter(): |
| 16 |
with expected_protocol( |
| 17 |
Ametek7270, |
| 18 |
[(b'SEN', b'27\n')], |
| 19 |
) as inst: |
| 20 |
assert inst.sensitivity == 1.0 |
| 21 |
|
| 22 |
|
| 23 |
def test_slope_getter(): |
| 24 |
with expected_protocol( |
| 25 |
Ametek7270, |
| 26 |
[(b'SLOPE', b'1\n')], |
| 27 |
) as inst: |
| 28 |
assert inst.slope == 12 |
| 29 |
|
| 30 |
|
| 31 |
def test_time_constant_getter(): |
| 32 |
with expected_protocol( |
| 33 |
Ametek7270, |
| 34 |
[(b'TC', b'30\n')], |
| 35 |
) as inst: |
| 36 |
assert inst.time_constant == 100000.0 |
| 37 |
|
| 38 |
|
| 39 |
def test_x_getter(): |
| 40 |
with expected_protocol( |
| 41 |
Ametek7270, |
| 42 |
[(b'X.', b'0.0E+00\n')], |
| 43 |
) as inst: |
| 44 |
assert inst.x == 0.0 |
| 45 |
|
| 46 |
|
| 47 |
def test_y_getter(): |
| 48 |
with expected_protocol( |
| 49 |
Ametek7270, |
| 50 |
[(b'Y.', b'0.0E+00\n')], |
| 51 |
) as inst: |
| 52 |
assert inst.y == 0.0 |
| 53 |
|
| 54 |
|
| 55 |
def test_xy_getter(): |
| 56 |
with expected_protocol( |
| 57 |
Ametek7270, |
| 58 |
[(b'XY.', b'0.0E+00,0.0E+00\n')], |
| 59 |
) as inst: |
| 60 |
assert inst.xy == [0.0, 0.0] |
| 61 |
|
| 62 |
|
| 63 |
def test_mag_getter(): |
| 64 |
with expected_protocol( |
| 65 |
Ametek7270, |
| 66 |
[(b'MAG.', b'0.0E+00\n')], |
| 67 |
) as inst: |
| 68 |
assert inst.mag == 0.0 |
| 69 |
|
| 70 |
|
| 71 |
def test_theta_getter(): |
| 72 |
with expected_protocol( |
| 73 |
Ametek7270, |
| 74 |
[(b'PHA.', b'-1.8E+02\n')], |
| 75 |
) as inst: |
| 76 |
assert inst.theta == -180.0 |
| 77 |
|
| 78 |
|
| 79 |
@pytest.mark.parametrize("method, command", [('x1', 'X1.'), |
| 80 |
('y1', 'Y1.'), |
| 81 |
('x2', 'X2.'), |
| 82 |
('y2', 'Y2.')]) |
| 83 |
def test_failing_properties(method, command): |
| 84 |
"""in standard single reference mode, these tests should raise a ValueError""" |
| 85 |
with pytest.raises(ValueError): |
| 86 |
with expected_protocol( |
| 87 |
Ametek7270, |
| 88 |
[(f'{command}'.encode(), b'\n')] |
| 89 |
) as inst: |
| 90 |
getattr(inst, method) == 0.0 |
| 91 |
|
| 92 |
|
| 93 |
def test_harmonic_getter(): |
| 94 |
with expected_protocol( |
| 95 |
Ametek7270, |
| 96 |
[(b'REFN', b'7\n')], |
| 97 |
) as inst: |
| 98 |
assert inst.harmonic == 7 |
| 99 |
|
| 100 |
|
| 101 |
def test_phase_getter(): |
| 102 |
with expected_protocol( |
| 103 |
Ametek7270, |
| 104 |
[(b'REFP.', b'2.5E+02\n')], |
| 105 |
) as inst: |
| 106 |
assert inst.phase == 250.0 |
| 107 |
|
| 108 |
|
| 109 |
def test_voltage_getter(): |
| 110 |
with expected_protocol( |
| 111 |
Ametek7270, |
| 112 |
[(b'OA.', b'0.0E+00\n')], |
| 113 |
) as inst: |
| 114 |
assert inst.voltage == 0.0 |
| 115 |
|
| 116 |
|
| 117 |
def test_frequency_getter(): |
| 118 |
with expected_protocol( |
| 119 |
Ametek7270, |
| 120 |
[(b'OF.', b'1.2E+04\n')], |
| 121 |
) as inst: |
| 122 |
assert inst.frequency == 12000.0 |
| 123 |
|
| 124 |
|
| 125 |
def test_dac1_getter(): |
| 126 |
with expected_protocol( |
| 127 |
Ametek7270, |
| 128 |
[(b'DAC. 1', b'7.0E+00\n')], |
| 129 |
) as inst: |
| 130 |
assert inst.dac1 == 7.0 |
| 131 |
|
| 132 |
|
| 133 |
def test_dac2_getter(): |
| 134 |
with expected_protocol( |
| 135 |
Ametek7270, |
| 136 |
[(b'DAC. 2', b'-7.0E+00\n')], |
| 137 |
) as inst: |
| 138 |
assert inst.dac2 == -7.0 |
| 139 |
|
| 140 |
|
| 141 |
def test_dac3_getter(): |
| 142 |
with expected_protocol( |
| 143 |
Ametek7270, |
| 144 |
[(b'DAC. 3', b'2.6E+00\n')], |
| 145 |
) as inst: |
| 146 |
assert inst.dac3 == 2.6 |
| 147 |
|
| 148 |
|
| 149 |
def test_dac4_getter(): |
| 150 |
with expected_protocol( |
| 151 |
Ametek7270, |
| 152 |
[(b'DAC. 4', b'5.5E+00\n')], |
| 153 |
) as inst: |
| 154 |
assert inst.dac4 == 5.5 |
| 155 |
|
| 156 |
|
| 157 |
def test_adc1_getter(): |
| 158 |
with expected_protocol( |
| 159 |
Ametek7270, |
| 160 |
[(b'ADC. 1', b'0.0E+00\n')], |
| 161 |
) as inst: |
| 162 |
assert inst.adc1 == 0.0 |
| 163 |
|
| 164 |
|
| 165 |
def test_adc2_getter(): |
| 166 |
with expected_protocol( |
| 167 |
Ametek7270, |
| 168 |
[(b'ADC. 2', b'0.0E+00\n')], |
| 169 |
) as inst: |
| 170 |
assert inst.adc2 == 0.0 |
| 171 |
|
| 172 |
|
| 173 |
def test_adc3_getter(): |
| 174 |
with expected_protocol( |
| 175 |
Ametek7270, |
| 176 |
[(b'ADC. 3', b'-1.6E-01\n')], |
| 177 |
) as inst: |
| 178 |
assert inst.adc3 == -0.16 |
| 179 |
|
| 180 |
|
| 181 |
def test_adc4_getter(): |
| 182 |
with expected_protocol( |
| 183 |
Ametek7270, |
| 184 |
[(b'ADC. 4', b'-1.64E-01\n')], |
| 185 |
) as inst: |
| 186 |
assert inst.adc4 == -0.164 |
| 187 |
|
| 188 |
|
| 189 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 190 |
([(b'SEN 0', b'')], |
| 191 |
0.0), |
| 192 |
([(b'SEN 1', b'')], |
| 193 |
2e-09), |
| 194 |
([(b'SEN 2', b'')], |
| 195 |
5e-09), |
| 196 |
([(b'SEN 3', b'')], |
| 197 |
1e-08), |
| 198 |
([(b'SEN 4', b'')], |
| 199 |
2e-08), |
| 200 |
([(b'SEN 5', b'')], |
| 201 |
5e-08), |
| 202 |
([(b'SEN 6', b'')], |
| 203 |
1e-07), |
| 204 |
([(b'SEN 7', b'')], |
| 205 |
2e-07), |
| 206 |
([(b'SEN 8', b'')], |
| 207 |
5e-07), |
| 208 |
([(b'SEN 9', b'')], |
| 209 |
1e-06), |
| 210 |
([(b'SEN 10', b'')], |
| 211 |
2e-06), |
| 212 |
([(b'SEN 11', b'')], |
| 213 |
5e-06), |
| 214 |
([(b'SEN 12', b'')], |
| 215 |
1e-05), |
| 216 |
([(b'SEN 13', b'')], |
| 217 |
2e-05), |
| 218 |
([(b'SEN 14', b'')], |
| 219 |
5e-05), |
| 220 |
([(b'SEN 15', b'')], |
| 221 |
0.0001), |
| 222 |
([(b'SEN 16', b'')], |
| 223 |
0.0002), |
| 224 |
([(b'SEN 17', b'')], |
| 225 |
0.0005), |
| 226 |
([(b'SEN 18', b'')], |
| 227 |
0.001), |
| 228 |
([(b'SEN 19', b'')], |
| 229 |
0.002), |
| 230 |
([(b'SEN 20', b'')], |
| 231 |
0.005), |
| 232 |
([(b'SEN 21', b'')], |
| 233 |
0.01), |
| 234 |
([(b'SEN 22', b'')], |
| 235 |
0.02), |
| 236 |
([(b'SEN 23', b'')], |
| 237 |
0.05), |
| 238 |
([(b'SEN 24', b'')], |
| 239 |
0.1), |
| 240 |
([(b'SEN 25', b'')], |
| 241 |
0.2), |
| 242 |
([(b'SEN 26', b'')], |
| 243 |
0.5), |
| 244 |
([(b'SEN 27', b'')], |
| 245 |
1.0), |
| 246 |
)) |
| 247 |
def test_sensitivity_setter(comm_pairs, value): |
| 248 |
with expected_protocol( |
| 249 |
Ametek7270, |
| 250 |
comm_pairs, |
| 251 |
) as inst: |
| 252 |
inst.sensitivity = value |
| 253 |
|
| 254 |
|
| 255 |
def test_slope_setter(): |
| 256 |
with expected_protocol( |
| 257 |
Ametek7270, |
| 258 |
[(b'SLOPE 1', b'')], |
| 259 |
) as inst: |
| 260 |
inst.slope = 12 |
| 261 |
|
| 262 |
|
| 263 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 264 |
([(b'TC 0', b'')], |
| 265 |
1e-05), |
| 266 |
([(b'TC 1', b'')], |
| 267 |
2e-05), |
| 268 |
([(b'TC 2', b'')], |
| 269 |
5e-05), |
| 270 |
([(b'TC 3', b'')], |
| 271 |
0.0001), |
| 272 |
([(b'TC 4', b'')], |
| 273 |
0.0002), |
| 274 |
([(b'TC 5', b'')], |
| 275 |
0.0005), |
| 276 |
([(b'TC 6', b'')], |
| 277 |
0.001), |
| 278 |
([(b'TC 7', b'')], |
| 279 |
0.002), |
| 280 |
([(b'TC 8', b'')], |
| 281 |
0.005), |
| 282 |
([(b'TC 9', b'')], |
| 283 |
0.01), |
| 284 |
([(b'TC 10', b'')], |
| 285 |
0.02), |
| 286 |
([(b'TC 11', b'')], |
| 287 |
0.05), |
| 288 |
([(b'TC 12', b'')], |
| 289 |
0.1), |
| 290 |
([(b'TC 13', b'')], |
| 291 |
0.2), |
| 292 |
([(b'TC 14', b'')], |
| 293 |
0.5), |
| 294 |
([(b'TC 15', b'')], |
| 295 |
1.0), |
| 296 |
([(b'TC 16', b'')], |
| 297 |
2.0), |
| 298 |
([(b'TC 17', b'')], |
| 299 |
5.0), |
| 300 |
([(b'TC 18', b'')], |
| 301 |
10.0), |
| 302 |
([(b'TC 19', b'')], |
| 303 |
20.0), |
| 304 |
([(b'TC 20', b'')], |
| 305 |
50.0), |
| 306 |
([(b'TC 21', b'')], |
| 307 |
100.0), |
| 308 |
([(b'TC 22', b'')], |
| 309 |
200.0), |
| 310 |
([(b'TC 23', b'')], |
| 311 |
500.0), |
| 312 |
([(b'TC 24', b'')], |
| 313 |
1000.0), |
| 314 |
([(b'TC 25', b'')], |
| 315 |
2000.0), |
| 316 |
([(b'TC 26', b'')], |
| 317 |
5000.0), |
| 318 |
([(b'TC 27', b'')], |
| 319 |
10000.0), |
| 320 |
([(b'TC 28', b'')], |
| 321 |
20000.0), |
| 322 |
([(b'TC 29', b'')], |
| 323 |
50000.0), |
| 324 |
([(b'TC 30', b'')], |
| 325 |
100000.0), |
| 326 |
)) |
| 327 |
def test_time_constant_setter(comm_pairs, value): |
| 328 |
with expected_protocol( |
| 329 |
Ametek7270, |
| 330 |
comm_pairs, |
| 331 |
) as inst: |
| 332 |
inst.time_constant = value |
| 333 |
|
| 334 |
|
| 335 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 336 |
([(b'REFN 7', b'')], |
| 337 |
7), |
| 338 |
([(b'REFN 7', b'')], |
| 339 |
7), |
| 340 |
([(b'REFN 7', b'')], |
| 341 |
7), |
| 342 |
([(b'REFN 7', b'')], |
| 343 |
7), |
| 344 |
([(b'REFN 7', b'')], |
| 345 |
7), |
| 346 |
([(b'REFN 7', b'')], |
| 347 |
7), |
| 348 |
)) |
| 349 |
def test_harmonic_setter(comm_pairs, value): |
| 350 |
with expected_protocol( |
| 351 |
Ametek7270, |
| 352 |
comm_pairs, |
| 353 |
) as inst: |
| 354 |
inst.harmonic = value |
| 355 |
|
| 356 |
|
| 357 |
def test_phase_setter(): |
| 358 |
with expected_protocol( |
| 359 |
Ametek7270, |
| 360 |
[(b'REFP. 250', b'')], |
| 361 |
) as inst: |
| 362 |
inst.phase = 250 |
| 363 |
|
| 364 |
|
| 365 |
def test_voltage_setter(): |
| 366 |
with expected_protocol( |
| 367 |
Ametek7270, |
| 368 |
[(b'OA. 2.7', b'')], |
| 369 |
) as inst: |
| 370 |
inst.voltage = 2.7 |
| 371 |
|
| 372 |
|
| 373 |
def test_frequency_setter(): |
| 374 |
with expected_protocol( |
| 375 |
Ametek7270, |
| 376 |
[(b'OF. 12000', b'')], |
| 377 |
) as inst: |
| 378 |
inst.frequency = 12000 |
| 379 |
|
| 380 |
|
| 381 |
def test_dac1_setter(): |
| 382 |
with expected_protocol( |
| 383 |
Ametek7270, |
| 384 |
[(b'DAC. 1 7', b'')], |
| 385 |
) as inst: |
| 386 |
inst.dac1 = 7 |
| 387 |
|
| 388 |
|
| 389 |
def test_dac2_setter(): |
| 390 |
with expected_protocol( |
| 391 |
Ametek7270, |
| 392 |
[(b'DAC. 2 -7', b'')], |
| 393 |
) as inst: |
| 394 |
inst.dac2 = -7 |
| 395 |
|
| 396 |
|
| 397 |
def test_dac3_setter(): |
| 398 |
with expected_protocol( |
| 399 |
Ametek7270, |
| 400 |
[(b'DAC. 3 2.6', b'')], |
| 401 |
) as inst: |
| 402 |
inst.dac3 = 2.6 |
| 403 |
|
| 404 |
|
| 405 |
def test_dac4_setter(): |
| 406 |
with expected_protocol( |
| 407 |
Ametek7270, |
| 408 |
[(b'DAC. 4 5.5', b'')], |
| 409 |
) as inst: |
| 410 |
inst.dac4 = 5.5 |
| 411 |
|
| 412 |
|
| 413 |
@pytest.mark.parametrize("comm_pairs, value", ( |
| 414 |
([], |
| 415 |
True), |
| 416 |
([], |
| 417 |
False), |
| 418 |
)) |
| 419 |
def test_autogain_setter(comm_pairs, value): |
| 420 |
with expected_protocol( |
| 421 |
Ametek7270, |
| 422 |
comm_pairs, |
| 423 |
) as inst: |
| 424 |
inst.autogain = value |
| 425 |
|
| 426 |
|
| 427 |
def test_set_voltage_mode(): |
| 428 |
with expected_protocol( |
| 429 |
Ametek7270, |
| 430 |
[(b'IMODE 0', b'')], |
| 431 |
) as inst: |
| 432 |
assert inst.set_voltage_mode() is None |
| 433 |
|
| 434 |
|
| 435 |
def test_set_differential_mode(): |
| 436 |
with expected_protocol( |
| 437 |
Ametek7270, |
| 438 |
[(b'VMODE 3', b''), |
| 439 |
(b'LF 3 0', b'')], |
| 440 |
) as inst: |
| 441 |
assert inst.set_differential_mode() is None |
| 442 |
|
| 443 |
|
| 444 |
@pytest.mark.parametrize("comm_pairs, args, kwargs, value", ( |
| 445 |
([(b'IMODE 1', b'')], |
| 446 |
(), {'low_noise': False}, None), |
| 447 |
([(b'IMODE 2', b'')], |
| 448 |
(), {'low_noise': True}, None), |
| 449 |
)) |
| 450 |
def test_set_current_mode(comm_pairs, args, kwargs, value): |
| 451 |
with expected_protocol( |
| 452 |
Ametek7270, |
| 453 |
comm_pairs, |
| 454 |
) as inst: |
| 455 |
assert inst.set_current_mode(*args, **kwargs) == value |
| 456 |
|
| 457 |
|
| 458 |
def test_set_channel_A_mode(): |
| 459 |
with expected_protocol( |
| 460 |
Ametek7270, |
| 461 |
[(b'VMODE 1', b'')], |
| 462 |
) as inst: |
| 463 |
assert inst.set_channel_A_mode() is None |
| 464 |
|
| 465 |
|
| 466 |
def test_id(): |
| 467 |
with expected_protocol( |
| 468 |
Ametek7270, |
| 469 |
[(b'ID', b'7270\n'), |
| 470 |
(b'VER', b'2.11\n')], |
| 471 |
) as inst: |
| 472 |
assert inst.id == '7270/2.11' |
| 473 |
|
| 474 |
|
| 475 |
def test_shutdown(): |
| 476 |
with expected_protocol( |
| 477 |
Ametek7270, |
| 478 |
[(b'OA. 0', b'')], |
| 479 |
) as inst: |
| 480 |
assert inst.shutdown() is None |