| 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.instruments.teledyne.teledyne_oscilloscope import sanitize_source |
| 28 |
from pymeasure.instruments.teledyne.teledyneMAUI import TeledyneMAUI |
| 29 |
from pymeasure.test import expected_protocol |
| 30 |
|
| 31 |
INVALID_CHANNELS = ["INVALID_SOURCE", "C1 C2", "C1 MATH", "C1234567", "CHANNEL"] |
| 32 |
VALID_CHANNELS = [('C1', 'C1'), ('CHANNEL2', 'C2'), ('ch 3', 'C3'), ('chan 4', 'C4'), |
| 33 |
('\tC3\t', 'C3'), (' math ', 'MATH')] |
| 34 |
|
| 35 |
|
| 36 |
def test_init(): |
| 37 |
with expected_protocol( |
| 38 |
TeledyneMAUI, |
| 39 |
[(b"CHDR OFF", None)] |
| 40 |
): |
| 41 |
pass # Verify the expected communication. |
| 42 |
|
| 43 |
|
| 44 |
def test_removed_property(): |
| 45 |
"""Verify that certain inherited properties are removed successfully. |
| 46 |
|
| 47 |
Some actions from the base class are not valid for this one. |
| 48 |
""" |
| 49 |
with expected_protocol(TeledyneMAUI, [(b'CHDR OFF', None)]) as instr: |
| 50 |
props = ["timebase_hor_magnify"] |
| 51 |
for prop in props: |
| 52 |
with pytest.raises(AttributeError): |
| 53 |
_ = getattr(instr, prop) |
| 54 |
|
| 55 |
ch_props = ["trigger_level2", "skew_factor", "unit", "invert"] |
| 56 |
for prop in ch_props: |
| 57 |
with pytest.raises(AttributeError): |
| 58 |
_ = getattr(instr.ch(1), prop) |
| 59 |
|
| 60 |
|
| 61 |
@pytest.mark.parametrize("channel", INVALID_CHANNELS) |
| 62 |
def test_invalid_source(channel): |
| 63 |
with pytest.raises(ValueError): |
| 64 |
sanitize_source(channel) |
| 65 |
|
| 66 |
|
| 67 |
@pytest.mark.parametrize("channel", VALID_CHANNELS) |
| 68 |
def test_sanitize_valid_source(channel): |
| 69 |
assert sanitize_source(channel[0]) == channel[1] |
| 70 |
|
| 71 |
|
| 72 |
def test_bwlimit(): |
| 73 |
with expected_protocol( |
| 74 |
TeledyneMAUI, |
| 75 |
[(b"CHDR OFF", None), |
| 76 |
(b"BWL C1,OFF", None), |
| 77 |
(b"BWL?", b"C1,OFF"), |
| 78 |
(b"BWL C1,200MHZ", None), |
| 79 |
(b"BWL?", b"C1,200MHZ"), |
| 80 |
(b"BWL C1,ON", None), |
| 81 |
(b"BWL?", b"C1,ON"), |
| 82 |
] |
| 83 |
) as instr: |
| 84 |
instr.ch_1.bwlimit = "OFF" |
| 85 |
assert instr.bwlimit["C1"] == "OFF" |
| 86 |
instr.ch_1.bwlimit = "200MHZ" |
| 87 |
assert instr.bwlimit["C1"] == "200MHZ" |
| 88 |
instr.ch_1.bwlimit = "ON" |
| 89 |
assert instr.bwlimit["C1"] == "ON" |
| 90 |
|
| 91 |
|
| 92 |
def test_offset(): |
| 93 |
with expected_protocol( |
| 94 |
TeledyneMAUI, |
| 95 |
[(b"CHDR OFF", None), |
| 96 |
(b"C1:OFST 1.00E+00V", None), |
| 97 |
(b"C1:OFST?", b"1.00E+00") |
| 98 |
] |
| 99 |
) as instr: |
| 100 |
instr.ch_1.offset = 1. |
| 101 |
assert instr.ch_1.offset == 1. |
| 102 |
|
| 103 |
|
| 104 |
def test_attenuation(): |
| 105 |
with expected_protocol( |
| 106 |
TeledyneMAUI, |
| 107 |
[(b"CHDR OFF", None), |
| 108 |
(b"C1:ATTN 100", None), |
| 109 |
(b"C1:ATTN?", b"100"), |
| 110 |
(b"C1:ATTN 0.1", None), |
| 111 |
(b"C1:ATTN?", b"0.1") |
| 112 |
] |
| 113 |
) as instr: |
| 114 |
instr.ch_1.probe_attenuation = 100 |
| 115 |
assert instr.ch_1.probe_attenuation == 100 |
| 116 |
instr.ch_1.probe_attenuation = 0.1 |
| 117 |
assert instr.ch_1.probe_attenuation == 0.1 |
| 118 |
|
| 119 |
|
| 120 |
if __name__ == '__main__': |
| 121 |
pytest.main() |