Debian Codegraph @

tests/instruments/keysight/test_keysightE3631A_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 import pytest
26 from pymeasure.instruments.keysight.keysightE3631A import KeysightE3631A
27
28
29 @pytest.fixture(scope="module")
30 def power_supply(connected_device_address):
31 instr = KeysightE3631A(connected_device_address)
32 instr.reset()
33 return instr
34
35
36 class TestKeysightE3631A:
37 """
38 Unit tests for KeysightE3631A class.
39
40 This test suite, needs the following setup to work properly:
41 - A KeysightE3631A device should be connected to the computer;
42 - The device's address must be set in the RESOURCE constant;
43 """
44
45 #########################
46 # PARAMETRIZATION CASES #
47 #########################
48
49 BOOLEANS = [False, True]
50 CHANNELS = [1, 2, 3]
51
52 #########
53 # TESTS #
54 #########
55
56 @pytest.mark.parametrize("case", BOOLEANS)
57 def test_output_enabled(self, power_supply, case):
58 assert not power_supply.output_enabled
59 power_supply.output_enabled = case
60 assert power_supply.output_enabled == case
61
62 @pytest.mark.parametrize("case", BOOLEANS)
63 def test_tracking_enabled(self, power_supply, case):
64 assert not power_supply.tracking_enabled
65 power_supply.tracking_enabled = case
66 assert power_supply.tracking_enabled == case
67
68 @pytest.mark.parametrize("chn, i_limit", [(1, 0), (1, 5), (2, 0), (2, 1), (3, 0), (3, 1)],)
69 def test_current_limit(self, power_supply, chn, i_limit):
70 power_supply.channels[chn].current_limit = i_limit
71
72 @pytest.mark.parametrize("chn, i_limit", [(1, -1), (1, 6), (2, -1), (2, 2), (3, -1), (3, 2)],)
73 def test_current_limit_out_of_range(self, power_supply, chn, i_limit):
74 with pytest.raises(ValueError, match=f"Value of {i_limit} is not in range"):
75 power_supply.channels[chn].current_limit = i_limit
76
77 @pytest.mark.parametrize("chn, voltage", [(1, 0), (1, 6), (2, 0), (2, 25), (3, 0), (3, -25)],)
78 def test_voltage_setpoint(self, power_supply, chn, voltage):
79 power_supply.channels[chn].voltage_setpoint = voltage
80 assert power_supply.channels[chn].voltage_setpoint == voltage
81
82 @pytest.mark.parametrize("chn, voltage",
83 [(1, -1), (1, 7), (2, -1), (2, 26), (3, 1), (3, -26)],)
84 def test_voltage_setpoint_out_of_range(self, power_supply, chn, voltage):
85 with pytest.raises(ValueError, match=f"Value of {voltage} is not in range"):
86 power_supply.channels[chn].voltage_setpoint = voltage
87
88 @pytest.mark.parametrize("chn", CHANNELS)
89 def test_measure_voltage(self, power_supply, chn):
90 assert isinstance(power_supply.channels[chn].voltage, float)
91
92 @pytest.mark.parametrize("chn", CHANNELS)
93 def test_measure_current(self, power_supply, chn):
94 assert isinstance(power_supply.channels[chn].current, float)