From c959ccecd566d54768b014e89ac7cdb5f9e1130a Mon Sep 17 00:00:00 2001 From: Steven Casagrande Date: Mon, 11 Feb 2019 13:21:28 -0500 Subject: [PATCH 1/2] Fix bug with SCPIFunctionGenerator.function, add tests --- .../generic_scpi/scpi_function_generator.py | 4 +- .../test_scpi_function_generator.py | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 instruments/tests/test_generic_scpi/test_scpi_function_generator.py diff --git a/instruments/generic_scpi/scpi_function_generator.py b/instruments/generic_scpi/scpi_function_generator.py index 4877168ae..3e610ca85 100644 --- a/instruments/generic_scpi/scpi_function_generator.py +++ b/instruments/generic_scpi/scpi_function_generator.py @@ -87,7 +87,7 @@ def _set_amplitude_(self, magnitude, units): function = enum_property( command="FUNC", - enum=lambda: Function, # pylint: disable=undefined-variable + enum=FunctionGenerator.Function, # pylint: disable=undefined-variable doc=""" Gets/sets the output function of the function generator @@ -103,7 +103,7 @@ def _set_amplitude_(self, magnitude, units): Set value should be within correct bounds of instrument. - :units: As specified (if a `~quntities.quantity.Quantity`) or assumed + :units: As specified (if a `~quantities.quantity.Quantity`) or assumed to be of units volts. :type: `~quantities.quantity.Quantity` with units volts. """ diff --git a/instruments/tests/test_generic_scpi/test_scpi_function_generator.py b/instruments/tests/test_generic_scpi/test_scpi_function_generator.py new file mode 100644 index 000000000..b88b6b286 --- /dev/null +++ b/instruments/tests/test_generic_scpi/test_scpi_function_generator.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Module containing tests for generic SCPI function generator instruments +""" + +# IMPORTS #################################################################### + +from __future__ import absolute_import + +import quantities as pq + +import instruments as ik +from instruments.tests import expected_protocol, make_name_test, unit_eq + +# TESTS ###################################################################### + +test_scpi_func_gen_name = make_name_test(ik.generic_scpi.SCPIFunctionGenerator) + + +def test_scpi_func_gen_amplitude(): + with expected_protocol( + ik.generic_scpi.SCPIFunctionGenerator, + [ + "VOLT:UNIT?", + "VOLT?", + "VOLT:UNIT VPP", + "VOLT 2.0", + "VOLT:UNIT DBM", + "VOLT 1.5" + ], [ + "VPP", + "+1.000000E+00" + ] + ) as fg: + assert fg.amplitude == (1 * pq.V, fg.VoltageMode.peak_to_peak) + fg.amplitude = 2 * pq.V + fg.amplitude = (1.5 * pq.V, fg.VoltageMode.dBm) + + +def test_scpi_func_gen_frequency(): + with expected_protocol( + ik.generic_scpi.SCPIFunctionGenerator, + [ + "FREQ?", + "FREQ 1.005000e+02" + ], [ + "+1.234000E+03" + ] + ) as fg: + assert fg.frequency == 1234 * pq.Hz + fg.frequency = 100.5 * pq.Hz + + +def test_scpi_func_gen_function(): + with expected_protocol( + ik.generic_scpi.SCPIFunctionGenerator, + [ + "FUNC?", + "FUNC SQU" + ], [ + "SIN" + ] + ) as fg: + assert fg.function == fg.Function.sinusoid + fg.function = fg.Function.square + + +def test_scpi_func_gen_offset(): + with expected_protocol( + ik.generic_scpi.SCPIFunctionGenerator, + [ + "VOLT:OFFS?", + "VOLT:OFFS 4.321000e-01" + ], [ + "+1.234000E+01", + ] + ) as fg: + assert fg.offset == 12.34 * pq.V + fg.offset = 0.4321 * pq.V From b033accac4d2ec0dc7d0ff1dd50c671900560ed7 Mon Sep 17 00:00:00 2001 From: Steven Casagrande Date: Mon, 11 Feb 2019 13:25:51 -0500 Subject: [PATCH 2/2] Fix linting --- instruments/generic_scpi/scpi_function_generator.py | 2 +- .../tests/test_generic_scpi/test_scpi_function_generator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instruments/generic_scpi/scpi_function_generator.py b/instruments/generic_scpi/scpi_function_generator.py index 3e610ca85..122d29894 100644 --- a/instruments/generic_scpi/scpi_function_generator.py +++ b/instruments/generic_scpi/scpi_function_generator.py @@ -87,7 +87,7 @@ def _set_amplitude_(self, magnitude, units): function = enum_property( command="FUNC", - enum=FunctionGenerator.Function, # pylint: disable=undefined-variable + enum=FunctionGenerator.Function, doc=""" Gets/sets the output function of the function generator diff --git a/instruments/tests/test_generic_scpi/test_scpi_function_generator.py b/instruments/tests/test_generic_scpi/test_scpi_function_generator.py index b88b6b286..6920a3f4b 100644 --- a/instruments/tests/test_generic_scpi/test_scpi_function_generator.py +++ b/instruments/tests/test_generic_scpi/test_scpi_function_generator.py @@ -11,7 +11,7 @@ import quantities as pq import instruments as ik -from instruments.tests import expected_protocol, make_name_test, unit_eq +from instruments.tests import expected_protocol, make_name_test # TESTS ######################################################################