Debian Codegraph @

tests/instruments/toptica/test_ibeamsmart.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
30 from pymeasure.instruments.toptica import IBeamSmart
31
32 # Note: This communication does not contain the first two device responses, as they are
33 # ignored due to `adapter.flush_read_buffer()`.
34 # The device communication depends on previous commands and whether the device power cycled.
35 init_comm = [("echo off", None), ("prom off", None), ("talk usual", ""), (None, "[OK]")]
36
37
38 def test_init():
39 with expected_protocol(IBeamSmart,
40 init_comm,
41 ):
42 pass # verify init
43
44
45 def test_version():
46 with expected_protocol(
47 IBeamSmart,
48 init_comm + [("ver", ""), (None, "iBPs-001A01-05"), (None, "[OK]")],
49 ) as inst:
50 assert inst.version == "iBPs-001A01-05"
51
52
53 def test_power():
54 with expected_protocol(
55 IBeamSmart,
56 init_comm + [("sh pow", ""), (None, "PIC = 000001 uW "), (None, "[OK]")],
57 ) as inst:
58 assert inst.power == 1
59
60
61 def test_disable_emission():
62 with expected_protocol(
63 IBeamSmart,
64 init_comm + [("la off", ""), (None, "[OK]")],
65 ) as inst:
66 inst.emission = False
67
68
69 def test_setting_failed():
70 with expected_protocol(
71 IBeamSmart,
72 init_comm + [("la off", ""), (None, "abc"), (None, "[OK]")],
73 ) as inst:
74 with pytest.raises(ValueError):
75 inst.laser_enabled = False
76
77
78 def test_enable_channel():
79 with expected_protocol(
80 IBeamSmart,
81 init_comm + [("en 3", ""), (None, "[OK]"),
82 ("sta ch 3", ""), (None, "ON"), (None, "[OK]"),
83 ("di 2", ""), (None, "[OK]"),
84 ("sta ch 2", ""), (None, "OFF"), (None, "[OK]"),
85 ]
86 ) as inst:
87 inst.ch_3.enabled = True
88 assert inst.ch_3.enabled is True
89 inst.ch_2.enabled = False
90 assert inst.ch_2.enabled is False
91
92
93 def test_channel1_enabled_getter():
94 with expected_protocol(
95 IBeamSmart,
96 init_comm + [("sta ch 1", ""), (None, "ON"), (None, "[OK]")],
97 ) as inst:
98 with pytest.warns(FutureWarning):
99 assert inst.channel1_enabled is True
100
101
102 def test_channel1_enabled_setter():
103 with expected_protocol(
104 IBeamSmart,
105 init_comm + [("en 1", ""), (None, "[OK]")],
106 ) as inst:
107 with pytest.warns(FutureWarning):
108 inst.channel1_enabled = True
109
110
111 def test_channel_power():
112 with expected_protocol(
113 IBeamSmart,
114 init_comm + [("ch 2 pow 100.000000 mic", ""), (None, "[OK]")]
115 ) as inst:
116 inst.ch_2.power = 100
117
118
119 def test_shutdown():
120 with expected_protocol(
121 IBeamSmart,
122 init_comm + [("di 0", ""), (None, "[OK]"), ("la off", ""), (None, "[OK]")]
123 ) as inst:
124 inst.shutdown()
125 assert inst.isShutdown is True