Debian Codegraph @

tests/instruments/pendulum/test_cnt91.py

raw
1 import pytest
2
3 from pymeasure.instruments.pendulum import CNT91
4 from pymeasure.test import expected_protocol
5
6
7 def test_init():
8 with expected_protocol(
9 CNT91,
10 [],
11 ):
12 pass # Verify the expected communication.
13
14
15 def test_batch_size_getter():
16 with expected_protocol(
17 CNT91,
18 [(b"FORM:SMAX?", b"10000\n")],
19 ) as inst:
20 assert inst.batch_size == 10000
21
22
23 @pytest.mark.parametrize(
24 "comm_pairs, value",
25 (
26 ([(b"INIT:CONT 1.0", None)], True),
27 ([(b"INIT:CONT 0.0", None)], False),
28 ),
29 )
30 def test_continuous_setter(comm_pairs, value):
31 with expected_protocol(
32 CNT91,
33 comm_pairs,
34 ) as inst:
35 inst.continuous = value
36
37
38 @pytest.mark.parametrize(
39 "comm_pairs, value",
40 (
41 ([(b"INIT:CONT?", b"1\n")], True),
42 ([(b"INIT:CONT?", b"0\n")], False),
43 ),
44 )
45 def test_continuous_getter(comm_pairs, value):
46 with expected_protocol(
47 CNT91,
48 comm_pairs,
49 ) as inst:
50 assert inst.continuous == value
51
52
53 @pytest.mark.parametrize(
54 "comm_pairs, value",
55 (
56 ([(b"ARM:SLOP NEG", None)], "NEG"),
57 ([(b"ARM:SLOP POS", None)], "POS"),
58 ),
59 )
60 def test_external_arming_start_slope_setter(comm_pairs, value):
61 with expected_protocol(
62 CNT91,
63 comm_pairs,
64 ) as inst:
65 inst.external_arming_start_slope = value
66
67
68 @pytest.mark.parametrize(
69 "comm_pairs, value",
70 (
71 ([(b"ARM:SLOP?", b"NEG\n")], "NEG"),
72 ([(b"ARM:SLOP?", b"POS\n")], "POS"),
73 ),
74 )
75 def test_external_arming_start_slope_getter(comm_pairs, value):
76 with expected_protocol(
77 CNT91,
78 comm_pairs,
79 ) as inst:
80 assert inst.external_arming_start_slope == value
81
82
83 @pytest.mark.parametrize(
84 "comm_pairs, value",
85 (
86 ([(b"ARM:SOUR EXT1", None)], "A"),
87 ([(b"ARM:SOUR IMM", None)], "IMM"),
88 ),
89 )
90 def test_external_start_arming_source_setter(comm_pairs, value):
91 with expected_protocol(
92 CNT91,
93 comm_pairs,
94 ) as inst:
95 inst.external_start_arming_source = value
96
97
98 @pytest.mark.parametrize(
99 "comm_pairs, value",
100 (
101 ([(b"ARM:SOUR?", b"EXT1\n")], "A"),
102 ([(b"ARM:SOUR?", b"IMM\n")], "IMM"),
103 ),
104 )
105 def test_external_start_arming_source_getter(comm_pairs, value):
106 with expected_protocol(
107 CNT91,
108 comm_pairs,
109 ) as inst:
110 assert inst.external_start_arming_source == value
111
112
113 @pytest.mark.parametrize(
114 "comm_pairs, value",
115 (
116 ([(b"FORM REAL", None)], "REAL"),
117 ([(b"FORM ASC", None)], "ASCII"),
118 ),
119 )
120 def test_format_setter(comm_pairs, value):
121 with expected_protocol(
122 CNT91,
123 comm_pairs,
124 ) as inst:
125 inst.format = value
126
127
128 @pytest.mark.parametrize(
129 "comm_pairs, value",
130 (
131 ([(b"FORM?", b"REAL\n")], "REAL"),
132 ([(b"FORM?", b"ASC\n")], "ASCII"),
133 ),
134 )
135 def test_format_getter(comm_pairs, value):
136 with expected_protocol(
137 CNT91,
138 comm_pairs,
139 ) as inst:
140 assert inst.format == value
141
142
143 @pytest.mark.parametrize(
144 "comm_pairs, value",
145 (
146 ([(b":ACQ:APER 1000", None)], 1000),
147 ([(b":ACQ:APER 1", None)], 1),
148 ([(b":ACQ:APER 2e-08", None)], 2e-08),
149 ),
150 )
151 def test_gate_time_setter(comm_pairs, value):
152 with expected_protocol(
153 CNT91,
154 comm_pairs,
155 ) as inst:
156 inst.gate_time = value
157
158
159 @pytest.mark.parametrize(
160 "comm_pairs, value",
161 (
162 ([(b":ACQ:APER?", b"+1.0000000000000E+03\n")], 1000.0),
163 ([(b":ACQ:APER?", b"+1.0000000000000E+00\n")], 1.0),
164 ([(b":ACQ:APER?", b"+2.0000000000000E-08\n")], 2e-08),
165 ),
166 )
167 def test_gate_time_getter(comm_pairs, value):
168 with expected_protocol(
169 CNT91,
170 comm_pairs,
171 ) as inst:
172 assert inst.gate_time == value
173
174
175 def test_buffer_frequency_time_series():
176 with expected_protocol(
177 CNT91,
178 [
179 (b"*CLS", None),
180 (b"FORM ASC", None),
181 (b":CONF:ARR:FREQ:BTB 10,(@1)", None),
182 (b"INIT:CONT 0.0", None),
183 (b":ACQ:APER 0.1", None),
184 (b":INIT", None),
185 ],
186 ) as inst:
187 assert inst.buffer_frequency_time_series(*("A", 10), **{"gate_time": 0.1}) is None
188
189
190 @pytest.mark.parametrize(
191 "comm_pairs, args, kwargs, value",
192 (
193 (
194 [
195 (b"*OPC?", b"1\n"),
196 (
197 b":FETC:ARR? 7",
198 b"+9.999992027E+06,+9.999991980E+06,+9.999992043E+06,+9.999992031E+06,+9.999992042E+06,+9.999992041E+06,+9.999992004E+06\n", # noqa: E501
199 ),
200 ],
201 (7,),
202 {},
203 [
204 9999992.027,
205 9999991.98,
206 9999992.043,
207 9999992.031,
208 9999992.042,
209 9999992.041,
210 9999992.004,
211 ],
212 ),
213 (
214 [
215 (b"*OPC?", b"1\n"),
216 (b":FETC:ARR? MAX", b"+9.999992030E+06,+9.999992000E+06,+9.999992043E+06\n"),
217 ],
218 (),
219 {},
220 [9999992.03, 9999992.0, 9999992.043],
221 ),
222 ),
223 )
224 def test_read_buffer(comm_pairs, args, kwargs, value):
225 with expected_protocol(
226 CNT91,
227 comm_pairs,
228 ) as inst:
229 assert inst.read_buffer(*args, **kwargs) == value