Debian Codegraph @

tests/instruments/hcp/test_tc038.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
27 from pymeasure.test import expected_protocol
28
29
30 from pymeasure.instruments.hcp import TC038
31
32
33 def test_setpoint():
34 with expected_protocol(
35 TC038,
36 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
37 (b"\x0201010WRDD0120,01\x03", b"\x020101OK00C8\x03")]
38 ) as inst:
39 assert inst.setpoint == 20
40
41
42 def test_setpoint_setter():
43 # Communication from manual.
44 with expected_protocol(
45 TC038,
46 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
47 (b"\x0201010WWRD0120,01,00C8\x03", b"\x020101OK\x03")]
48 ) as inst:
49 inst.setpoint = 20
50
51
52 def test_setpoint_error():
53 with expected_protocol(
54 TC038,
55 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
56 (b"\x0201010WWRD0120,01,00C8\x03", b"\x020101ER0401\x03")]
57 ) as inst:
58 with pytest.raises(ConnectionError, match="Out of setpoint range"):
59 inst.setpoint = 20
60
61
62 def test_temperature():
63 # Communication from manual.
64 with expected_protocol(
65 TC038,
66 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
67 (b"\x0201010WRDD0002,01\x03", b"\x020101OK00C8\x03")]
68 ) as inst:
69 assert 20 == inst.temperature
70
71
72 def test_monitored():
73 # Communication from manual.
74 with expected_protocol(
75 TC038,
76 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
77 (b"\x0201010WRM\x03", b"\x020101OK00C8\x03")]
78 ) as inst:
79 assert 20 == inst.monitored_value
80
81
82 def test_monitored_error():
83 with expected_protocol(
84 TC038,
85 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
86 (b"\x0201010WRM\x03", b"\x020101ER0600\x03")]
87 ) as inst:
88 with pytest.raises(ConnectionError, match="monitor"):
89 inst.monitored_value
90
91
92 def test_set_monitored():
93 # Communication from manual.
94 with expected_protocol(
95 TC038,
96 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03")]
97 ):
98 pass # Instantiation calls set_monitored_quantity()
99
100
101 def test_set_monitored_wrong_input():
102 with expected_protocol(
103 TC038,
104 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03")]
105 ) as inst:
106 with pytest.raises(KeyError):
107 inst.set_monitored_quantity("temper")
108
109
110 def test_information():
111 # Communication from manual.
112 with expected_protocol(
113 TC038,
114 [(b"\x0201010WRS01D0002\x03", b"\x020101OK\x03"),
115 (b"\x0201010INF6\x03",
116 b"\x020101OKUT150333 V01.R001111222233334444\x03")]
117 ) as inst:
118 value = inst.information
119 assert value == "UT150333 V01.R001111222233334444"