Debian Codegraph @

tests/instruments/thyracont/test_smartline_v1.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.thyracont import SmartlineV1
28 from pymeasure.instruments.thyracont.smartline_v1 import calculate_checksum
29
30
31 def test_calculate_checksum_basics():
32 for i in range(0, 64):
33 assert (i + 64) == ord(calculate_checksum(chr(i)))
34 for i in range(64, 128):
35 assert i == ord(calculate_checksum(chr(i)))
36
37
38 @pytest.mark.parametrize("msg, chksum", (
39 ("001T", "e"), # command from SmartlineV1
40 ("001M982122", "V"), # msg from SmartlineV1
41 ("0010MV00", "D"), # command from SmartlineV2
42 ("0011MV079.734e2", "h"), # msg from SmartlineV2
43 ))
44 def test_calculate_checksum(msg, chksum):
45 assert chksum == calculate_checksum(msg)
46
47
48 def test_pressure():
49 """Verify the communication of the pressure getter."""
50 with expected_protocol(
51 SmartlineV1,
52 [("001M^", "001M982122V"), ],
53 ) as inst:
54 assert inst.pressure == pytest.approx(982.1)
55
56
57 def test_device_type():
58 """Verify the communication of the Instruments type getter."""
59 with expected_protocol(
60 SmartlineV1,
61 [("001Te", "001TVSM207t"), ],
62 ) as inst:
63 assert inst.device_type == "VSM207"
64
65
66 def test_cathode_enable():
67 """Verify the communication of the hot/cold cathode control."""
68 with expected_protocol(
69 SmartlineV1,
70 [("001IZ", "001I1K"), ],
71 ) as inst:
72 assert inst.cathode_enabled is True
73
74
75 def test_cathode_enable_error():
76 """Verify the raised error in case of a set error."""
77 with expected_protocol(
78 SmartlineV1,
79 [("001i0j", "001NO_DEF\\"), ],
80 ) as inst:
81 with pytest.raises(ConnectionError):
82 inst.cathode_enabled = False
83
84
85 def test_display_unit():
86 """Verify the communication of the unit property."""
87 with expected_protocol(
88 SmartlineV1,
89 [("001Uf", "001U000000F"), ],
90 ) as inst:
91 assert inst.display_unit == "mbar"