Debian Codegraph @

tests/instruments/texio/test_texioPSW360L30_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 import time
25
26 import pytest
27 from pymeasure.instruments.texio.texioPSW360L30 import TexioPSW360L30
28
29
30 pytest.skip('Only work with connected hardware', allow_module_level=True)
31
32
33 class TestTexioPSW360L30:
34 """
35 Unit tests for TEXIO PSW-360L30 class.
36
37 This test suite, needs the following setup to work properly:
38 - A TEXIO PSW-360L30 device should be connected to the computer;
39 - The device's address must be set in the RESOURCE constant;
40 """
41
42 ##################################################
43 # TEXIO PSW-360L30 device address goes here:
44 RESOURCE = "TCPIP::192.168.10.119::2268::SOCKET"
45 ##################################################
46
47 INSTR = TexioPSW360L30(RESOURCE)
48
49 #########################
50 # PARAMETRIZATION CASES #
51 #########################
52
53 CURRENT_LIMIT = [0.1, 0.5, 1]
54 VOLTAGE_SETPOINT = [1, 2, 3, 4, 5]
55
56 @pytest.fixture
57 def instr(self):
58 self.INSTR.reset()
59 return self.INSTR
60
61 @pytest.mark.parametrize("case", CURRENT_LIMIT)
62 def test_current_limit_no_output(self, instr, case):
63 instr.current_limit = case
64 assert instr.current_limit == case
65
66 @pytest.mark.parametrize("case", VOLTAGE_SETPOINT)
67 def test_voltage_setpoint_no_output(self, instr, case):
68 instr.voltage_setpoint = case
69 assert instr.voltage_setpoint == case
70
71 @pytest.mark.parametrize("voltage_setpoint", VOLTAGE_SETPOINT)
72 @pytest.mark.parametrize("current_limit", CURRENT_LIMIT)
73 def test_everything_without_apply(self, instr, voltage_setpoint, current_limit):
74 instr.current_limit = current_limit
75 instr.voltage_setpoint = voltage_setpoint
76 instr.output_enabled = True
77 time.sleep(1)
78 assert instr.output_enabled is True
79 assert instr.voltage_setpoint == voltage_setpoint
80 assert instr.current_limit == current_limit
81 assert instr.voltage == pytest.approx(voltage_setpoint, abs=0.1)
82 assert instr.current == pytest.approx(0, abs=0.1)
83 assert instr.power == pytest.approx(0, abs=0.1)
84 instr.output_enabled = False
85 assert instr.output_enabled is False
86
87 @pytest.mark.parametrize("voltage_setpoint", VOLTAGE_SETPOINT)
88 @pytest.mark.parametrize("current_limit", CURRENT_LIMIT)
89 def test_everything_with_apply(self, instr, voltage_setpoint, current_limit):
90 instr.applied = (voltage_setpoint, current_limit)
91 instr.output_enabled = True
92 time.sleep(1)
93 assert instr.output_enabled is True
94 assert instr.voltage_setpoint == voltage_setpoint
95 assert instr.current_limit == current_limit
96 assert instr.voltage == pytest.approx(voltage_setpoint, abs=0.1)
97 assert instr.current == pytest.approx(0, abs=0.1)
98 assert instr.power == pytest.approx(0, abs=0.1)
99 instr.output_enabled = False
100 assert instr.output_enabled is False