def test_scope_connection(self, make_reseted_cleared_scope):
     bad_resource = "USB0::10893::45848::MY12345678::0::INSTR"
     # The pure python VISA library (pyvisa-py) raises a ValueError while the PyVISA library raises a VisaIOError.
     with pytest.raises((ValueError, VisaIOError)):
         scope = KeysightDSOX1102G(bad_resource)
class TestKeysightDSOX1102G:
    """
    Unit tests for KeysightDSOX1102G class.

    This test suite, needs the following setup to work properly:
        - A KeysightDSOX1102G device should be connected to the computer;
        - The device's address must be set in the RESOURCE constant;
        - A probe on Channel 1 must be connected to the Demo output of the oscilloscope.
    """

    ##################################################
    # KeysightDSOX1102G device address goes here:
    RESOURCE = "USB0::10893::6039::CN57266430::INSTR"
    ##################################################

    #########################
    # PARAMETRIZATION CASES #
    #########################

    BOOLEANS = [False, True]
    CHANNEL_COUPLINGS = ["ac", "dc"]
    CHANNEL_LABELS = [["label", "LABEL"], ["quite long label", "QUITE LONG"],
                      [12345, "12345"]]
    TIMEBASE_MODES = ["main", "window", "xy", "roll"]
    ACQUISITION_TYPES = ["normal", "average", "hresolution", "peak"]
    ACQUISITION_MODES = ["realtime", "segmented"]
    DIGITIZE_SOURCES = ["channel1", "channel2", "function", "math", "fft",
                        "abus", "ext"]
    WAVEFORM_POINTS_MODES = ["normal", "maximum", "raw"]
    WAVEFORM_POINTS = [100, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000,
                       62500]
    WAVEFORM_SOURCES = ["channel1", "channel2", "function", "fft", "wmemory1",
                        "wmemory2", "ext"]
    WAVEFORM_FORMATS = ["ascii", "word", "byte"]
    DOWNLOAD_SOURCES = ["channel1", "channel2", "function", "fft", "ext"]
    CHANNELS = [1, 2]

    SCOPE = KeysightDSOX1102G(RESOURCE)

    ############
    # FIXTURES #
    ############

    @pytest.fixture
    def make_reseted_cleared_scope(self):
        self.SCOPE.reset()
        self.SCOPE.clear_status()
        return self.SCOPE

    #########
    # TESTS #
    #########

    def test_scope_connection(self, make_reseted_cleared_scope):
        bad_resource = "USB0::10893::45848::MY12345678::0::INSTR"
        # The pure python VISA library (pyvisa-py) raises a ValueError while the PyVISA library raises a VisaIOError.
        with pytest.raises((ValueError, VisaIOError)):
            scope = KeysightDSOX1102G(bad_resource)

    def test_autoscale(self, make_reseted_cleared_scope):
        scope = make_reseted_cleared_scope
        scope.write(":timebase:position 1")
        # Autoscale should turn off the zoomed (delayed) time mode
        assert scope.ask(":timebase:position?") == "+1.000000000000E+00\n"
        scope.autoscale()
        assert scope.ask(":timebase:position?") != "+1.000000000000E+00\n"

    # Channel
    def test_ch_current_configuration(self, make_reseted_cleared_scope):
        scope = make_reseted_cleared_scope
        expected = {"OFFS": 0.0, "COUP": "DC", "IMP": "ONEM", "DISP": True,
                    "BWL": False, "INV": False, "UNIT": "VOLT", "PROB": 10.0,
                    "PROB:SKEW": 0.0, "STYP": "SING", "CHAN": 1, "RANG": 40.0}
        actual = scope.ch(1).current_configuration
        assert actual == expected

    @pytest.mark.parametrize("ch_number", CHANNELS)
    @pytest.mark.parametrize("case", BOOLEANS)
    def test_ch_bwlimit(self, make_reseted_cleared_scope, ch_number, case):
        scope = make_reseted_cleared_scope
        scope.ch(ch_number).bwlimit = case
        assert scope.ch(ch_number).bwlimit == case

    @pytest.mark.parametrize("ch_number", CHANNELS)
    @pytest.mark.parametrize("case", CHANNEL_COUPLINGS)
    def test_ch_coupling(self, make_reseted_cleared_scope, ch_number, case):
        scope = make_reseted_cleared_scope
        scope.ch(ch_number).coupling = case
        assert scope.ch(ch_number).coupling == case

    @pytest.mark.parametrize("ch_number", CHANNELS)
    @pytest.mark.parametrize("case", BOOLEANS)
    def test_ch_display(self, make_reseted_cleared_scope, ch_number, case):
        scope = make_reseted_cleared_scope
        scope.ch(ch_number).display = case
        assert scope.ch(ch_number).display == case

    @pytest.mark.parametrize("ch_number", CHANNELS)
    @pytest.mark.parametrize("case", BOOLEANS)
    def test_ch_invert(self, make_reseted_cleared_scope, ch_number, case):
        scope = make_reseted_cleared_scope
        scope.ch(ch_number).invert = case
        assert scope.ch(ch_number).invert == case

    @pytest.mark.parametrize("ch_number", CHANNELS)
    @pytest.mark.parametrize("case, expected", CHANNEL_LABELS)
    def test_ch_label(self, make_reseted_cleared_scope, ch_number, case, expected):
        scope = make_reseted_cleared_scope
        scope.ch(ch_number).label = case
        assert scope.ch(ch_number).label == expected