| 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 |
from pymeasure.adapters import ProtocolAdapter |
| 29 |
from pymeasure.instruments.generic_types import SCPIMixin, SCPIUnknownMixin |
| 30 |
from pymeasure.instruments import Instrument |
| 31 |
|
| 32 |
|
| 33 |
class Test_SCPIMixin: |
| 34 |
class SCPIInstrument(SCPIMixin, Instrument): |
| 35 |
pass |
| 36 |
|
| 37 |
def test_init(self): |
| 38 |
inst = self.SCPIInstrument(ProtocolAdapter(), "test") |
| 39 |
assert inst.SCPI is False # should not be set by the new init |
| 40 |
|
| 41 |
@pytest.mark.parametrize("method, write, reply", ( |
| 42 |
("id", "*IDN?", "xyz, abc"), |
| 43 |
("complete", "*OPC?", "1"), |
| 44 |
("status", "*STB?", "189"), |
| 45 |
("options", "*OPT?", "a9"), |
| 46 |
)) |
| 47 |
def test_SCPI_properties(self, method, write, reply): |
| 48 |
with expected_protocol( |
| 49 |
self.SCPIInstrument, |
| 50 |
[(write, reply)], |
| 51 |
name="test") as inst: |
| 52 |
assert getattr(inst, method) == reply |
| 53 |
|
| 54 |
def test_next_error(self): |
| 55 |
with expected_protocol( |
| 56 |
self.SCPIInstrument, |
| 57 |
[("SYST:ERR?", '-100,"Command error"')], |
| 58 |
name="test") as inst: |
| 59 |
assert inst.next_error == [-100, '"Command error"'] |
| 60 |
|
| 61 |
@pytest.mark.parametrize("method, write", (("clear", "*CLS"), |
| 62 |
("reset", "*RST"), |
| 63 |
)) |
| 64 |
def test_SCPI_write_commands(self, method, write): |
| 65 |
with expected_protocol( |
| 66 |
self.SCPIInstrument, |
| 67 |
[(write, None)], |
| 68 |
name="test") as inst: |
| 69 |
getattr(inst, method)() |
| 70 |
|
| 71 |
def test_check_errors(self): |
| 72 |
with expected_protocol( |
| 73 |
self.SCPIInstrument, |
| 74 |
[("SYST:ERR?", '-100,"Command error"'), |
| 75 |
("SYST:ERR?", '-222,"Data out of range"'), |
| 76 |
("SYST:ERR?", '0,"No error"'), |
| 77 |
], |
| 78 |
name="test") as inst: |
| 79 |
assert inst.check_errors() == [[-100, '"Command error"'], |
| 80 |
[-222, '"Data out of range"']] |
| 81 |
|
| 82 |
|
| 83 |
def test_SCPIunknownMixin(): |
| 84 |
class SCPIunknownInstrument(SCPIUnknownMixin, Instrument): |
| 85 |
pass |
| 86 |
|
| 87 |
with pytest.warns(FutureWarning): |
| 88 |
inst = SCPIunknownInstrument(ProtocolAdapter(), "test") |
| 89 |
assert inst.SCPI is False |