Debian Codegraph @

tests/instruments/signalrecovery/test_dspbase.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 from pymeasure.instruments.signalrecovery.dsp_base import DSPBase
30
31
32 @pytest.mark.parametrize("index, reference", [(idx, i) for idx, i in enumerate(DSPBase.REFERENCES)])
33 def test_reference(index, reference):
34 with expected_protocol(
35 DSPBase,
36 [(f"IE {index}", None)],
37 ) as instr:
38 instr.reference = reference
39
40
41 @pytest.mark.parametrize("index, imode", [(idx, i) for idx, i in enumerate(DSPBase.IMODES)])
42 def test_imode(index, imode):
43 with expected_protocol(
44 DSPBase,
45 [(f"IMODE {index}", None)],
46 ) as instr:
47 instr.imode = imode
48
49
50 @pytest.mark.parametrize("reading, value",
51 [(b"-12\x00", -12), (b"0\x00", 0), (b"5", 5), (b"12", 12)])
52 def test_dac1(reading, value):
53 with expected_protocol(
54 DSPBase,
55 [("DAC. 1", reading)],
56 ) as instr:
57 assert instr.dac1 == value
58
59
60 @pytest.mark.parametrize("reading, value",
61 [(b'-2.14E-07\r\n', -2.14e-07),
62 (b'-0.0E+00\x00\r\n', 0.0),
63 (b'1.2E-07\r\n', 1.2e-07),
64 (b'6.44E-07\r\n', 6.44e-07),
65 ])
66 def test_x(reading, value):
67 with expected_protocol(
68 DSPBase,
69 [('X.', reading)],
70 ) as instr:
71 assert instr.x == value