Debian Codegraph @

tests/instruments/tcpowerconversion/test_cxn.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2022 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 pytest
25
26 from pymeasure.test import expected_protocol
27 from pymeasure.instruments.tcpowerconversion import CXN
28
29
30 def test_id():
31 """Verify the communication of the id property."""
32 with expected_protocol(
33 CXN,
34 [
35 (
36 b"C\x00Gi\x00\x01\x00\x00\x00\xf4",
37 b"\x2aR\x00\x00\x10\x00\x01AG 0313 GTC \x00\x03\x10",
38 ),
39 ],
40 ) as inst:
41 assert inst.id == "AG 0313 GTC"
42
43
44 def test_power():
45 """Verify processing the power measurement."""
46 with expected_protocol(
47 CXN,
48 [
49 (
50 b"C\x00GP\x00\x00\x00\x00\x00\xda",
51 b"\x2aR\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x58",
52 ),
53 ],
54 ) as inst:
55 assert inst.power == (0.0, 0.0, 0.0)
56
57
58 def test_temperature():
59 """Verify processing the temperature measurement."""
60 with expected_protocol(
61 CXN,
62 [
63 (
64 b"C\x00GS\x00\x00\x00\x00\x00\xdd",
65 b"\x2aR\x00\x00\x08\x00\x10\x00\xdd\x00\x04\x00\x03\x01\x4e",
66 ),
67 ],
68 ) as inst:
69 assert inst.temperature == pytest.approx(22.1)
70
71
72 def test_status():
73 """Verify processing the status IntFlag."""
74 with expected_protocol(
75 CXN,
76 [
77 (
78 b"C\x00GS\x00\x00\x00\x00\x00\xdd",
79 b"\x2aR\x00\x00\x08\x00\x11\x00\xdd\x00\x04\x00\x03\x01\x4f",
80 ),
81 ],
82 ) as inst:
83 status = inst.status
84 assert CXN.Status.EXTERNAL_RFSOURCE in status
85 assert CXN.Status.RF_ENABLED in status
86 assert CXN.Status.RF_ENABLED | CXN.Status.EXTERNAL_RFSOURCE == status
87
88
89 def test_power_limit():
90 """Verify processing the power limit property"""
91 with expected_protocol(
92 CXN,
93 [
94 (
95 b"C\x00Gp\x00\x00\x00\x00\x00\xfa",
96 b"\x2aR\x00\x00\x144\xf8\x0b\xb8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
97 b"4\xf8\x02\xbc\x10\x33",
98 ),
99 ],
100 ) as inst:
101 assert inst.power_limit == pytest.approx(300.0)
102
103
104 def test_manual_mode():
105 """Verify processing the manual mode property"""
106 with expected_protocol(
107 CXN,
108 [
109 (
110 b"C\x00GT\x00\x00\x00\x00\x00\xde",
111 b"\x2aR\x00\x00\n\x00\x01\x01\xa9\x02v\x00\x00\x00\x00\x01\x7f",
112 ),
113 ],
114 ) as inst:
115 assert inst.manual_mode is True
116
117
118 @pytest.mark.parametrize("channel", range(1, 10))
119 def test_load_capacity_preset(channel):
120 """Verify processing the load capacity propert via a Channel"""
121 # here we use '%' for formatting since encoding from strings makes troubles
122 # with some values (e.g. \xff)
123 cmd = b"C\x00GU\x00%c\x00\x00" % (channel)
124 cmd += CXN._checksum(cmd)
125 response = b"R\x00\x00\n\x00%c\x00\x32\x00\x32\xff\xff\xff\xff" % (channel)
126 response += CXN._checksum(response)
127 with expected_protocol(
128 CXN,
129 [
130 (cmd, b"\x2a" + response),
131 ],
132 ) as inst:
133 assert inst.channels[channel].load_capacity == 50