| 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 time import sleep |
| 28 |
|
| 29 |
from pymeasure.instruments.teledyne import TeledyneMAUI |
| 30 |
|
| 31 |
|
| 32 |
class TestTeledyneMAUI: |
| 33 |
""" |
| 34 |
Unit tests for TeledyneMAUI class. |
| 35 |
|
| 36 |
This test suite needs an actual device connected, compatible with the MAUI interface. |
| 37 |
Use the ``--device-address`` flag for pytest to define your device. |
| 38 |
""" |
| 39 |
|
| 40 |
######################### |
| 41 |
# PARAMETRIZATION CASES # |
| 42 |
######################### |
| 43 |
|
| 44 |
BOOLEANS = [False, True] |
| 45 |
BANDWIDTH_LIMITS = ["OFF", "ON", "200MHZ"] |
| 46 |
CHANNEL_COUPLINGS = ["ac 1M", "dc 1M", "ground"] |
| 47 |
ACQUISITION_TYPES = ["normal", "average", "peak", "highres"] |
| 48 |
TRIGGER_LEVELS = [0.125, 0.150, 0.175] |
| 49 |
TRIGGER_SLOPES = ["negative", "positive"] |
| 50 |
ACQUISITION_AVERAGE = [4, 16, 32, 64, 128, 256] |
| 51 |
WAVEFORM_POINTS = [100, 1000, 10000] |
| 52 |
WAVEFORM_SOURCES = ["C1", "C2", "C3", "C4"] |
| 53 |
CHANNELS = [1, 2, 3, 4] |
| 54 |
|
| 55 |
############ |
| 56 |
# FIXTURES # |
| 57 |
############ |
| 58 |
|
| 59 |
@pytest.fixture(scope="module") |
| 60 |
def instrument(self, connected_device_address): |
| 61 |
return TeledyneMAUI(connected_device_address) |
| 62 |
|
| 63 |
@pytest.fixture |
| 64 |
def resetted_instrument(self, instrument): |
| 65 |
instrument.reset() |
| 66 |
sleep(7) |
| 67 |
return instrument |
| 68 |
|
| 69 |
@pytest.fixture |
| 70 |
def autoscaled_instrument(self, instrument): |
| 71 |
instrument.reset() |
| 72 |
sleep(7) |
| 73 |
instrument.autoscale() |
| 74 |
sleep(7) |
| 75 |
return instrument |
| 76 |
|
| 77 |
######### |
| 78 |
# TESTS # |
| 79 |
######### |
| 80 |
|
| 81 |
def test_instrument_connection(self, connected_device_address): |
| 82 |
instrument = TeledyneMAUI(connected_device_address) |
| 83 |
channel = instrument.ch(1) |
| 84 |
assert channel is not None |
| 85 |
|
| 86 |
def test_channel_autoset(self, instrument): |
| 87 |
instrument.ch(1).autoscale() |
| 88 |
sleep(0.1) |
| 89 |
|
| 90 |
def test_channel_measure_parameter(self, instrument): |
| 91 |
instrument.ch(1).measure_parameter("RMS") |
| 92 |
sleep(0.1) |
| 93 |
|
| 94 |
# Channel |
| 95 |
def test_ch_current_configuration(self, autoscaled_instrument): |
| 96 |
autoscaled_instrument.ch_1.offset = 0 |
| 97 |
autoscaled_instrument.ch_1.trigger_level = 0 |
| 98 |
expected = { |
| 99 |
"channel": 1, |
| 100 |
"attenuation": 1.0, |
| 101 |
"bandwidth_limit": "OFF", |
| 102 |
"coupling": "dc 1M", |
| 103 |
"offset": 0.0, |
| 104 |
"display": True, |
| 105 |
"volts_div": 0.05, |
| 106 |
"trigger_coupling": "dc", |
| 107 |
"trigger_level": 0.0, |
| 108 |
"trigger_slope": "positive", |
| 109 |
} |
| 110 |
actual = autoscaled_instrument.ch(1).current_configuration |
| 111 |
assert actual == expected |
| 112 |
|
| 113 |
@pytest.mark.parametrize("case", BANDWIDTH_LIMITS) |
| 114 |
def test_ch_bwlimit(self, instrument, case): |
| 115 |
instrument.bwlimit = case |
| 116 |
expected = {ch: case for ch in self.WAVEFORM_SOURCES} |
| 117 |
assert instrument.bwlimit == expected |
| 118 |
|
| 119 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 120 |
@pytest.mark.parametrize("case", BANDWIDTH_LIMITS) |
| 121 |
def test_ch_bwlimit_channel(self, instrument, ch_number, case): |
| 122 |
instrument.ch(ch_number).bwlimit = case |
| 123 |
assert instrument.bwlimit[f"C{ch_number}"] == case |
| 124 |
|
| 125 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 126 |
@pytest.mark.parametrize("case", CHANNEL_COUPLINGS) |
| 127 |
def test_ch_coupling(self, instrument, ch_number, case): |
| 128 |
instrument.ch(ch_number).coupling = case |
| 129 |
assert instrument.ch(ch_number).coupling == case |
| 130 |
|
| 131 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 132 |
@pytest.mark.parametrize("case", BOOLEANS) |
| 133 |
def test_ch_display(self, instrument, ch_number, case): |
| 134 |
instrument.ch(ch_number).display = case |
| 135 |
assert instrument.ch(ch_number).display == case |
| 136 |
|
| 137 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 138 |
def test_ch_offset(self, instrument, ch_number): |
| 139 |
instrument.ch(ch_number).offset = 1 |
| 140 |
assert instrument.ch(ch_number).offset == 1 |
| 141 |
|
| 142 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 143 |
def test_ch_probe_attenuation(self, instrument, ch_number): |
| 144 |
instrument.ch(ch_number).probe_attenuation = 10 |
| 145 |
assert instrument.ch(ch_number).probe_attenuation == 10 |
| 146 |
|
| 147 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 148 |
def test_ch_scale(self, instrument, ch_number): |
| 149 |
instrument.ch(ch_number).scale = 1 |
| 150 |
assert instrument.ch(ch_number).scale == 1 |
| 151 |
|
| 152 |
def test_ch_trigger_level(self, autoscaled_instrument): |
| 153 |
for case in self.TRIGGER_LEVELS: |
| 154 |
autoscaled_instrument.ch_1.trigger_level = case |
| 155 |
assert autoscaled_instrument.ch_1.trigger_level == case |
| 156 |
|
| 157 |
def test_ch_trigger_slope(self, autoscaled_instrument): |
| 158 |
with pytest.raises(ValueError): |
| 159 |
autoscaled_instrument.ch_1.trigger_slope = "abcd" |
| 160 |
autoscaled_instrument.trigger_select = ("edge", "c1", "off") |
| 161 |
for case in self.TRIGGER_SLOPES: |
| 162 |
autoscaled_instrument.ch_1.trigger_slope = case |
| 163 |
assert autoscaled_instrument.ch_1.trigger_slope == case |
| 164 |
|
| 165 |
# Timebase |
| 166 |
|
| 167 |
def test_timebase(self, autoscaled_instrument): |
| 168 |
autoscaled_instrument.timebase_scale = 5e-4 |
| 169 |
autoscaled_instrument.timebase_offset = 0 |
| 170 |
expected = { |
| 171 |
"timebase_scale": 5e-4, |
| 172 |
"timebase_offset": 0.0, |
| 173 |
} |
| 174 |
actual = autoscaled_instrument.timebase |
| 175 |
for key, val in actual.items(): |
| 176 |
assert pytest.approx(val, 0.1) == expected[key] |
| 177 |
|
| 178 |
def test_timebase_scale(self, resetted_instrument): |
| 179 |
resetted_instrument.timebase_scale = 1e-3 |
| 180 |
assert resetted_instrument.timebase_scale == 1e-3 |
| 181 |
|
| 182 |
def test_timebase_offset(self, instrument): |
| 183 |
instrument.timebase_offset = 1e-3 |
| 184 |
assert instrument.timebase_offset == 1e-3 |
| 185 |
|
| 186 |
# Acquisition |
| 187 |
|
| 188 |
@pytest.mark.parametrize("case", WAVEFORM_POINTS) |
| 189 |
def test_waveform_points(self, instrument, case): |
| 190 |
instrument.waveform_points = case |
| 191 |
assert instrument.waveform_points == case |
| 192 |
|
| 193 |
def test_waveform_preamble(self, autoscaled_instrument): |
| 194 |
autoscaled_instrument.ch_1.offset = 0 |
| 195 |
autoscaled_instrument.waveform_points = 0 |
| 196 |
autoscaled_instrument.waveform_first_point = 0 |
| 197 |
autoscaled_instrument.waveform_sparsing = 1 |
| 198 |
autoscaled_instrument.waveform_source = "C1" |
| 199 |
expected_preamble = { |
| 200 |
"sparsing": 1.0, |
| 201 |
"requested_points": 0.0, |
| 202 |
"memory_size": 2.5e6, |
| 203 |
"transmitted_points": None, |
| 204 |
"first_point": 0.0, |
| 205 |
"source": "C1", |
| 206 |
"grid_number": 14, |
| 207 |
"xdiv": 1e-6, |
| 208 |
"xoffset": 0.0, |
| 209 |
"ydiv": 0.05, |
| 210 |
"yoffset": 0.0, |
| 211 |
} |
| 212 |
preamble = autoscaled_instrument.waveform_preamble |
| 213 |
assert preamble == expected_preamble |
| 214 |
|
| 215 |
# Setup methods |
| 216 |
|
| 217 |
@pytest.mark.parametrize("ch_number", CHANNELS) |
| 218 |
def test_channel_setup(self, instrument, ch_number): |
| 219 |
# Only autoscale on the first channel |
| 220 |
instrument = instrument |
| 221 |
if ch_number == self.CHANNELS[0]: |
| 222 |
instrument.reset() |
| 223 |
sleep(7) |
| 224 |
instrument.autoscale() |
| 225 |
sleep(7) |
| 226 |
|
| 227 |
# Not testing the actual values assignment since different combinations of |
| 228 |
# parameters can play off each other. |
| 229 |
expected = instrument.ch(ch_number).current_configuration |
| 230 |
instrument.ch(ch_number).setup() |
| 231 |
assert instrument.ch(ch_number).current_configuration == expected |
| 232 |
with pytest.raises(AttributeError): |
| 233 |
instrument.ch(5) |
| 234 |
instrument.ch(ch_number).setup( |
| 235 |
bwlimit="ON", |
| 236 |
coupling="dc 1M", |
| 237 |
display=True, |
| 238 |
offset=0.0, |
| 239 |
probe_attenuation=1.0, |
| 240 |
scale=0.05, |
| 241 |
trigger_coupling="dc", |
| 242 |
trigger_level=0.150, |
| 243 |
trigger_slope="positive", |
| 244 |
) |
| 245 |
expected = { |
| 246 |
"channel": ch_number, |
| 247 |
"attenuation": 1.0, |
| 248 |
"bandwidth_limit": "ON", |
| 249 |
"coupling": "dc 1M", |
| 250 |
"offset": 0.0, |
| 251 |
"display": True, |
| 252 |
"volts_div": 0.05, |
| 253 |
"trigger_coupling": "dc", |
| 254 |
"trigger_level": 0.150, |
| 255 |
"trigger_slope": "positive", |
| 256 |
} |
| 257 |
actual = instrument.ch(ch_number).current_configuration |
| 258 |
assert actual == expected |
| 259 |
|
| 260 |
def test_timebase_setup(self, resetted_instrument): |
| 261 |
expected = resetted_instrument.timebase |
| 262 |
resetted_instrument.timebase_setup() |
| 263 |
assert resetted_instrument.timebase == expected |
| 264 |
|
| 265 |
# Download methods |
| 266 |
|
| 267 |
def test_hardcopy_setup(self, instrument): |
| 268 |
|
| 269 |
instrument.hardcopy_setup( |
| 270 |
device="BMP", format="PORTRAIT", background="Std", destination="FILE", |
| 271 |
area="GRIDONLY", directory="D:\\Waveforms\\temp" |
| 272 |
) |
| 273 |
config_expected = { |
| 274 |
"DEV": "BMP", "FORMAT": "PORTRAIT", "BCKG": "Std", "DEST": "FILE", |
| 275 |
"DIR": '"D:\\WAVEFORMS\\TEMP"', "AREA": "GRIDAREAONLY", |
| 276 |
} |
| 277 |
config = instrument.hardcopy_setup_current |
| 278 |
assert config_expected.items() <= config.items() |
| 279 |
|
| 280 |
def test_download_image_default_arguments(self, autoscaled_instrument): |
| 281 |
"""Note: the path specified here must exist on the device already!""" |
| 282 |
img = autoscaled_instrument.download_image() |
| 283 |
assert type(img) is bytearray |
| 284 |
assert pytest.approx(len(img), 0.1) == 2734135 |
| 285 |
|
| 286 |
# Trigger |
| 287 |
|
| 288 |
def test_trigger_select(self, resetted_instrument): |
| 289 |
with pytest.raises(ValueError): |
| 290 |
resetted_instrument.trigger_select = "edge" |
| 291 |
with pytest.raises(ValueError): |
| 292 |
resetted_instrument.trigger_select = ("edge", "c2") |
| 293 |
with pytest.raises(ValueError): |
| 294 |
resetted_instrument.trigger_select = ("edge", "c2", "time") |
| 295 |
with pytest.raises(ValueError): |
| 296 |
resetted_instrument.trigger_select = ("ABCD", "c1", "time", 0) |
| 297 |
with pytest.raises(ValueError): |
| 298 |
resetted_instrument.trigger_select = ("edge", "c1", "time", 1000) |
| 299 |
with pytest.raises(ValueError): |
| 300 |
resetted_instrument.trigger_select = ("edge", "c1", "time", 0, 1) |
| 301 |
resetted_instrument.trigger_select = ("edge", "c1", "off") |
| 302 |
resetted_instrument.trigger_select = ("EDGE", "C1", "OFF") |
| 303 |
assert resetted_instrument.trigger_select == ["edge", "c1", "off"] |
| 304 |
resetted_instrument.trigger_select = ("glit", "c1", "p2", 1e-3, 2e-3) |
| 305 |
assert resetted_instrument.trigger_select == ["glit", "c1", "p2", 1e-3, 2e-3] |
| 306 |
|
| 307 |
def test_trigger_setup(self, resetted_instrument): |
| 308 |
expected = resetted_instrument.trigger |
| 309 |
resetted_instrument.trigger_setup(**expected) |
| 310 |
assert resetted_instrument.trigger == expected |
| 311 |
|
| 312 |
|
| 313 |
if __name__ == "__main__": |
| 314 |
pytest.main() |