Debian Codegraph @

tests/instruments/keithley/test_keithley2000.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.keithley.keithley2000 import Keithley2000
28
29
30 def test_voltage_read():
31 with expected_protocol(
32 Keithley2000,
33 [(":READ?", "3.1415")],
34 ) as inst:
35 assert inst.voltage == pytest.approx(3.1415)
36
37
38 def test_voltage_range():
39 with expected_protocol(
40 Keithley2000,
41 [(":SENS:VOLT:RANG?", "955"),
42 (":SENS:VOLT:RANG:AUTO 0;:SENS:VOLT:RANG 234", None)
43 ],
44 ) as inst:
45 assert inst.voltage_range == 955
46 inst.voltage_range = 234
47
48
49 def test_voltage_range_trunc():
50 with expected_protocol(
51 Keithley2000,
52 [(":SENS:VOLT:RANG:AUTO 0;:SENS:VOLT:RANG 1010", None),
53 (":SENS:VOLT:RANG?", "1010"),
54 ],
55 ) as inst:
56 inst.voltage_range = 3333 # too large, gets truncated
57 assert inst.voltage_range == 1010
58
59
60 def test_mode():
61 "Confirm that mode string mapping works correctly"
62 with expected_protocol(
63 Keithley2000,
64 [(":CONF?", "VOLT:AC"),
65 (":CONF:FRES", None),
66 ],
67 ) as inst:
68 assert inst.mode == 'voltage ac'
69 inst.mode = 'resistance 4W'
70
71
72 def test_measure_voltage():
73 with expected_protocol(
74 Keithley2000,
75 [(":CONF:VOLT:AC", None),
76 (":SENS:VOLT:RANG:AUTO 0;:SENS:VOLT:AC:RANG 300", None),
77 ],
78 ) as inst:
79 inst.measure_voltage(max_voltage=300, ac=True)