Debian Codegraph @

tests/instruments/mksinst/test_mks937b.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 pytest
25
26 from pymeasure.test import expected_protocol
27 from pymeasure.instruments.mksinst.mks937b import MKS937B, Unit
28
29
30 def test_pressure():
31 """Verify the communication of the pressure getter."""
32 with expected_protocol(
33 MKS937B,
34 [("@253PR1?", "@253ACK1.10e-9"),
35 (None, b"FF")],
36 ) as inst:
37 assert inst.ch_1.pressure == pytest.approx(1.1e-9)
38
39
40 def test_ion_gauge_status():
41 """Verify the communication of the ion gauge status getter."""
42 with expected_protocol(
43 MKS937B,
44 [("@253T1?", "@253ACKG"),
45 (None, b"FF")],
46 ) as inst:
47 assert inst.ch_1.ion_gauge_status == "Good"
48
49
50 def test_ion_gauge_status_invalid_channel():
51 """Ion gauge status does not exist on all channels."""
52 with expected_protocol(
53 MKS937B,
54 [],
55 ) as inst:
56 with pytest.raises(AttributeError):
57 inst.ch_2.ion_gauge_status
58
59
60 def test_unit_setter():
61 """Verify the communication of the unit setter."""
62 with expected_protocol(
63 MKS937B,
64 [("@253U!MICRON", "@253ACKMICRON"),
65 (None, b"FF")],
66 ) as inst:
67 inst.unit = Unit.uHg
68
69
70 def test_unit_getter():
71 """Verify the communication of the unit getter."""
72 with expected_protocol(
73 MKS937B,
74 [("@253U?", "@253ACKTORR"),
75 (None, b"FF")],
76 ) as inst:
77 assert inst.unit == Unit.Torr
78
79
80 def test_power_enabled():
81 """Verify the communication of the channel power getter."""
82 with expected_protocol(
83 MKS937B,
84 [("@253CP1?", "@253ACKON"),
85 (None, b"FF")],
86 ) as inst:
87 assert inst.ch_1.power_enabled is True
88
89
90 def test_relay_value():
91 """Verify the communication of the relay setpoint getter."""
92 with expected_protocol(
93 MKS937B,
94 [("@253SP10?", "@253ACK2.00E+0"),
95 (None, b"FF")],
96 ) as inst:
97 assert inst.relay_10.setpoint == pytest.approx(2.00e0)
98
99
100 def test_relay_direction():
101 """Verify the communication of the relay direction."""
102 with expected_protocol(
103 MKS937B,
104 [("@253SD3?", "@253ACKABOVE"),
105 (None, b"FF")],
106 ) as inst:
107 assert inst.relay_3.direction == "ABOVE"
108
109
110 def test_relay_enabled():
111 """Verify the communication of the relay enabled property."""
112 with expected_protocol(
113 MKS937B,
114 [("@253EN6?", "@253ACKENABLE"),
115 (None, b"FF")],
116 ) as inst:
117 assert inst.relay_6.enabled is True