Debian Codegraph @

tests/instruments/rohdeschwarz/test_hmp_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 from time import sleep
26
27 import pytest
28
29 from pymeasure.instruments.rohdeschwarz.hmp import HMP4040
30
31
32 @pytest.fixture(scope="module")
33 def hmp4040(connected_device_address):
34 """Return a HMP4040 instrument."""
35 hmp4040 = HMP4040(connected_device_address)
36 return hmp4040
37
38
39 @pytest.fixture
40 def resetted_hmp4040(hmp4040):
41 """Return a HMP4040 instrument with resetted state."""
42 hmp4040.reset()
43 return hmp4040
44
45
46 def test_beep(resetted_hmp4040):
47 """Test emission of a beep from the instrument."""
48 resetted_hmp4040.beep()
49
50
51 def test_voltage_limits(resetted_hmp4040):
52 """Test minimum and maximum voltages."""
53 resetted_hmp4040.voltage_to_min()
54 assert resetted_hmp4040.voltage == resetted_hmp4040.min_voltage
55 resetted_hmp4040.voltage_to_max()
56 assert resetted_hmp4040.voltage == resetted_hmp4040.max_voltage
57
58
59 def test_voltage_stepping(resetted_hmp4040):
60 """Test stepping voltages up and down."""
61 resetted_hmp4040.voltage = 0.0
62 resetted_hmp4040.step_voltage_up()
63 assert resetted_hmp4040.voltage == resetted_hmp4040.voltage_step
64 resetted_hmp4040.step_voltage_down()
65 assert resetted_hmp4040.voltage == 0.0
66
67
68 def test_channel_state(resetted_hmp4040):
69 """Test activation and deactivation of channels."""
70 resetted_hmp4040.selected_channel = 1
71 assert resetted_hmp4040.selected_channel == 1
72
73 resetted_hmp4040.set_channel_state(2, True)
74 # check that the selected channel is reset to 2.
75 assert resetted_hmp4040.selected_channel == 1
76
77
78 def test_sequence(resetted_hmp4040):
79 """Test sequence execution."""
80 # NOTE: There are actually no assertions in this test. But it is possible to check the sequence
81 # execution by looking at display of the instrument.
82 resetted_hmp4040.selected_channel == 1
83 resetted_hmp4040.voltage = 0.0
84 resetted_hmp4040.sequence = [1.0, 1.0, 1.0, 2.0, 2.0, 1.0]
85 resetted_hmp4040.repetitions = 0
86 resetted_hmp4040.transfer_sequence(1)
87 resetted_hmp4040.output_enabled = True
88 resetted_hmp4040.selected_channel_active = True
89 resetted_hmp4040.start_sequence(1)
90 sleep(4)
91 resetted_hmp4040.stop_sequence(1)
92 resetted_hmp4040.output_enabled = False
93 resetted_hmp4040.clear_sequence(1)