Skip to content

feat: add login & logout support - #615

Open
jhenlely1 wants to merge 7 commits into
tektronix:mainfrom
jhenlely1:add-login-logout-support
Open

jhenlely1 wants to merge 7 commits into
tektronix:mainfrom
jhenlely1:add-login-logout-support

Conversation

@jhenlely1

@jhenlely1 jhenlely1 commented Jul 30, 2026 •

Copy link
Copy Markdown

Proposed changes

Added support for a user-specified login_command and logout_command in device config. These commands (e.g. login my_password and logout) will get sent after initial device connection and before device connection closing respectively.

This enables using tm_devices with instruments that are password protected.

Addresses #614

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Functionality update (non-breaking change which updates or changes existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • CI/CD update (an update to the CI/CD workflows, scripts, and/or configurations)
  • Documentation update (an update to enhance the user experience when reading through the docs)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have followed the guidelines in the CONTRIBUTING document
  • I have signed the CLA
  • I have checked to ensure there aren't other open Pull Requests for the same update/change
  • I have created (or updated) an Issue to track the status of this update/change and updated the link in this PR description (see above in the Proposed changes section) using the wording Addresses #<issue_number>
  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • Basic linting passes locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added necessary documentation (if appropriate)
  • I have updated the Changelog with a brief description of my changes

@CLAassistant

CLAassistant commented Jul 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jhenlely1 jhenlely1 changed the title Add login & logout support feat: add login & logout support Jul 31, 2026
Comment thread src/tm_devices/device_manager.py Resolved
@ldantek

ldantek commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I am concerned with expecting users to put raw passwords in the config file or their add_device function calls.

Comment thread src/tm_devices/device_manager.py Resolved
Comment thread src/tm_devices/drivers/device.py Resolved
Comment thread CHANGELOG.md Resolved
@nfelt14
nfelt14 force-pushed the add-login-logout-support branch from 0feef78 to c6e4f18 Compare August 12, 2026 20:16
Comment thread src/tm_devices/device_manager.py Resolved
Comment thread src/tm_devices/device_manager.py Resolved
@nfelt14

nfelt14 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

You need to sign all of your commits

@jhenlely1
jhenlely1 force-pushed the add-login-logout-support branch 3 times, most recently from 3eb5523 to eaec63d Compare August 13, 2026 21:47
@jhenlely1
jhenlely1 requested a review from nfelt14 August 18, 2026 12:43
@nfelt14

nfelt14 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

This branch needs to be rebased on main

@jhenlely1
jhenlely1 force-pushed the add-login-logout-support branch from eaec63d to c74cb60 Compare August 19, 2026 18:13
Comment thread src/tm_devices/device_manager.py Resolved
@codecov

codecov Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.69%. Comparing base (d55e839) to head (3110ada).

Files with missing lines Patch % Lines
src/tm_devices/device_manager.py 75.00% 2 Missing and 2 partials ⚠️
...devices/driver_mixins/device_control/pi_control.py 42.85% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #615      +/-   ##
===========================================
- Coverage   100.00%   98.69%   -1.31%     
===========================================
  Files          166      166              
  Lines         4866     4887      +21     
  Branches       437      441       +4     
===========================================
- Hits          4866     4823      -43     
- Misses           0       60      +60     
- Partials         0        4       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhenlely1
jhenlely1 force-pushed the add-login-logout-support branch from 15e5ed2 to c6a45ba Compare August 21, 2026 16:00
@jhenlely1
jhenlely1 force-pushed the add-login-logout-support branch from c6a45ba to 3110ada Compare September 8, 2026 12:58
@nfelt14
nfelt14 requested review from ldantek and nfelt14 September 8, 2026 15:40
@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Breaking API Changes

src/tm_devices/helpers/constants_and_dataclasses.py:0: DeviceConfigEntry.__init__(gpib_board_number):
Positional parameter was moved
  Details: position: from 9 to 11 (+2)

Link to workflow run

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Test Results (macos)

path passed failed subtotal
tests/test_abstract_device_expect_esr.py 1 1
tests/test_afgs.py 2 2
tests/test_alias_dict.py 1 1
tests/test_all_device_drivers.py 112 112
tests/test_alternative_connection_addresses.py 19 19
tests/test_awgs.py 4 4
tests/test_config_parser.py 50 50
tests/test_device_manager.py 20 20
tests/test_devices_legacy_tsp_ieee_cmds.py 3 3
tests/test_extension_mixin.py 1 1
tests/test_generate_waveform.py 6 6
tests/test_helpers.py 94 94
tests/test_ieee_scpi_cmds.py 1 1
tests/test_logging.py 5 5
tests/test_mainframe.py 13 13
tests/test_margin_testers.py 5 5
tests/test_pi_device.py 1 1
tests/test_psu.py 1 1
tests/test_rest_api_device.py 10 10
tests/test_schema.py 7 7
tests/test_scopes.py 10 10
tests/test_singleton.py 1 1
tests/test_smu.py 3 1 4
tests/test_ss.py 1 1
tests/test_tm_devices.py 471 471
tests/test_unsupported_device_type.py 1 1
tests/test_verification_functions.py 13 13
TOTAL 856 1 857
tests/test_smu.py
device_manager = <tm_devices.device_manager.DeviceManager object at 0x11babc980>
capsys = <_pytest.capture.CaptureFixture object at 0x11d080520>
caplog = <_pytest.logging.LogCaptureFixture object at 0x11c03d810>

    def test_smu(  # noqa: PLR0915
        device_manager: DeviceManager,
        capsys: pytest.CaptureFixture[str],
        caplog: pytest.LogCaptureFixture,
    ) -> None:
        """Test the SMU driver and TSP's IEEE commands.
    
        Args:
            device_manager: The DeviceManager object.
            capsys: The captured stdout and stderr.
            caplog: The captured log messages.
        """
        smu: SMU2601B = device_manager.add_smu("smu2601b-hostname", alias="smu-device")
        assert id(device_manager.get_smu(number_or_alias="smu-device")) == id(smu)
        assert id(device_manager.get_smu(number_or_alias=smu.device_number)) == id(smu)
    
        assert smu.manufacturer == "Keithley Instruments Inc."
        assert smu.model == "Model 2601B"
        assert smu.serial == "4498311"
        assert smu.sw_version == Version("3.3.5")
    
        with smu.command_syntax():
            assert smu.commands.status.node_enable == "status.node_enable"
    
        _ = capsys.readouterr()  # throw away any stdout
        with smu.command_verification():
            smu.commands.status.node_enable = 1
            stdout = capsys.readouterr().out
            assert "Write" in stdout
            assert "Query" in stdout
    
        smu.load_script(
            "loadfuncs",
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            run_script=True,
            to_nv_memory=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
        smu.load_script(
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            script_name="tsp_function",
        )
        stdout = capsys.readouterr().out
        assert "loadscript tsp_function" in stdout
        assert "if tsp_function ~= nil then script.delete('tsp_function') end" in stdout
        assert "endscript" in stdout
        assert "tsp_function.save()" not in stdout
        assert "tsp_function()" not in stdout
        smu.expect_esr(0)
        smu.load_script(
            script_name="loadfuncs",
            script_body=(Path(os.path.realpath(__file__)).parent / "samples" / "tsp_script.tsp")
            .read_text()
            .strip(),
            run_script=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" not in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
    
        with mock.patch("pyvisa.highlevel.VisaLibraryBase.clear", mock.MagicMock(return_value=None)):
            assert smu.query_expect_timeout("INVALID?", timeout_ms=1) == ""
        with (
            mock.patch(
                "pyvisa.resources.messagebased.MessageBasedResource.query",
                mock.MagicMock(side_effect=visa.errors.Error("custom error")),
            ),
            pytest.raises(visa.errors.Error),
        ):
            smu.query_expect_timeout("INVALID?", timeout_ms=1)
        assert smu.expect_esr(32, ("Command error", "No Error"))
    
        with pytest.raises(AssertionError):
            smu.expect_esr(32, ("ERROR",))
    
        tspieee = smu._ieee_cmds  # noqa: SLF001
    
        # Currently there is no way to unit test the cls function. Called to get full coverage.
        tspieee.cls()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.ese(300)
        assert tspieee.ese(1) == "1"
        assert tspieee.ese() == "1"
        assert tspieee.esr() == "0"
        assert tspieee.opc(True) == ""
        assert tspieee.opc() == "1"
        # Currently there is no way to unit test the rst function. Called to get full coverage.
        tspieee.rst()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.sre(300)
        assert tspieee.sre(1) == "1"
        assert tspieee.sre() == "1"
        assert tspieee.stb() == "1"
        assert tspieee.tst() == "0"
        # Currently there is no way to unit test the wai function. Called to get full coverage.
        tspieee.wai()
        smu.expect_esr(0)
    
        # Test some generic device functionality
        capsys.readouterr()  # clear the buffer
        cmd_arg_constants_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at "
            f"{str(smu.command_argument_constants).split(' at ', maxsplit=1)[-1]}"
        )
        cmds_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at "
            f"{str(smu.commands).split(' at ', maxsplit=1)[-1]}"
        )
        print(smu)  # noqa: T201
        expected_stdout = f"""{"=" * 45} SMU {smu.device_number} {"=" * 45}
      <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at {id(smu)}
        address='SMU2601B-HOSTNAME'
        alias='SMU-DEVICE'
        all_channel_names_list=('a',)
        command_argument_constants={cmd_arg_constants_repr}
        command_syntax_enabled=False
        command_verification_enabled=False
        commands={cmds_repr}
        config_entry={smu.config_entry!r}
        connection_type='TCPIP'
        default_visa_timeout={UNIT_TEST_TIMEOUT}
        device_number={smu.device_number}
        device_type='SMU'
        enable_verification=True
        hostname='SMU2601B-HOSTNAME'
        idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
        ieee_cmds={smu.ieee_cmds!r}
        ip_address=''
        is_open=True
        login_command=None
        logout_command=None
        manufacturer='Keithley Instruments Inc.'
        model='Model 2601B'
        name='SMU {smu.device_number}'
        name_and_alias='SMU {smu.device_number} "SMU-DEVICE"'
        port=None
        resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
        serial='4498311'
        series='SMU2601B'
        sw_version=<Version('3.3.5')>
        total_channels=1
        verbose=True
        visa_backend='{smu.visa_backend}'
        visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
        visa_timeout={UNIT_TEST_TIMEOUT}
    {"=" * (97 + len(str(smu.device_number)) - 1)}
    """
        stdout = capsys.readouterr().out
>       assert stdout == expected_stdout
E       assert '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 4767680464\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x11c8e7620>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x11c2d0910>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x11d07b700>\n    ip_address=\'\'\n    is_open=True\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n' == '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 4767680464\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x11c8e7620>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x11c2d0910>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x11d07b700>\n    ip_address=\'\'\n    is_open=True\n    login_command=None\n    logout_command=None\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n'
E         
E           ============================================= SMU 49 =============================================
E             <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at 4767680464
E               address='SMU2601B-HOSTNAME'
E               alias='SMU-DEVICE'
E               all_channel_names_list=('a',)
E               command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x11c8e7620>
E               command_syntax_enabled=False
E               command_verification_enabled=False
E               commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x11c2d0910>
E               config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: 'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)
E               connection_type='TCPIP'
E               default_visa_timeout=50
E               device_number=49
E               device_type='SMU'
E               enable_verification=True
E               hostname='SMU2601B-HOSTNAME'
E               idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
E               ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x11d07b700>
E               ip_address=''
E               is_open=True
E         -     login_command=None
E         -     logout_command=None
E               manufacturer='Keithley Instruments Inc.'
E               model='Model 2601B'
E               name='SMU 49'
E               name_and_alias='SMU 49 "SMU-DEVICE"'
E               port=None
E               resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
E               serial='4498311'
E               series='SMU2601B'
E               sw_version=<Version('3.3.5')>
E               total_channels=1
E               verbose=True
E               visa_backend='PyVISA-sim'
E               visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
E               visa_timeout=50
E           ==================================================================================================

_          = CaptureResult(out='2026-09-08 15:42:05.000564 - Creating Connection to SMU 49 "SMU-DEVICE"\n2026-09-08 15:42:05.000564 - SMU "SMU-DEVICE" VISA timeout set to: 50.000ms\n2026-09-08 15:42:05.000565 - (SMU 49 "SMU-DEVICE") Query >>  \'*IDN?\'\n2026-09-08 15:42:05.000565 - Response from \'*IDN?\' >>  \'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n', err='')
caplog     = <_pytest.logging.LogCaptureFixture object at 0x11c03d810>
capsys     = <_pytest.capture.CaptureFixture object at 0x11d080520>
cmd_arg_constants_repr = ('<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at '
 '0x11c8e7620>')
cmds_repr  = '<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x11c2d0910>'
device_manager = <tm_devices.device_manager.DeviceManager object at 0x11babc980>
expected_stdout = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 4767680464\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x11c8e7620>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x11c2d0910>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x11d07b700>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 '    login_command=None\n'
 '    logout_command=None\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
smu        = <tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B object at 0x11c2d07d0>
stdout     = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 4767680464\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x11c8e7620>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x11c2d0910>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x11d07b700>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
tspieee    = <tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x11d07b700>

tests/test_smu.py:187: AssertionError

Link to workflow run

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Test Results (ubuntu)

path passed failed subtotal
tests/test_abstract_device_expect_esr.py 1 1
tests/test_afgs.py 2 2
tests/test_alias_dict.py 1 1
tests/test_all_device_drivers.py 112 112
tests/test_alternative_connection_addresses.py 19 19
tests/test_awgs.py 4 4
tests/test_config_parser.py 50 50
tests/test_device_manager.py 20 20
tests/test_devices_legacy_tsp_ieee_cmds.py 3 3
tests/test_extension_mixin.py 1 1
tests/test_generate_waveform.py 6 6
tests/test_helpers.py 94 94
tests/test_ieee_scpi_cmds.py 1 1
tests/test_logging.py 5 5
tests/test_mainframe.py 13 13
tests/test_margin_testers.py 5 5
tests/test_pi_device.py 1 1
tests/test_psu.py 1 1
tests/test_rest_api_device.py 10 10
tests/test_schema.py 7 7
tests/test_scopes.py 10 10
tests/test_singleton.py 1 1
tests/test_smu.py 3 1 4
tests/test_ss.py 1 1
tests/test_tm_devices.py 471 471
tests/test_unsupported_device_type.py 1 1
tests/test_verification_functions.py 13 13
TOTAL 856 1 857
tests/test_smu.py
device_manager = <tm_devices.device_manager.DeviceManager object at 0x7fbf226b5e80>
capsys = <_pytest.capture.CaptureFixture object at 0x7fbf209599c0>
caplog = <_pytest.logging.LogCaptureFixture object at 0x7fbf20ff3490>

    def test_smu(  # noqa: PLR0915
        device_manager: DeviceManager,
        capsys: pytest.CaptureFixture[str],
        caplog: pytest.LogCaptureFixture,
    ) -> None:
        """Test the SMU driver and TSP's IEEE commands.
    
        Args:
            device_manager: The DeviceManager object.
            capsys: The captured stdout and stderr.
            caplog: The captured log messages.
        """
        smu: SMU2601B = device_manager.add_smu("smu2601b-hostname", alias="smu-device")
        assert id(device_manager.get_smu(number_or_alias="smu-device")) == id(smu)
        assert id(device_manager.get_smu(number_or_alias=smu.device_number)) == id(smu)
    
        assert smu.manufacturer == "Keithley Instruments Inc."
        assert smu.model == "Model 2601B"
        assert smu.serial == "4498311"
        assert smu.sw_version == Version("3.3.5")
    
        with smu.command_syntax():
            assert smu.commands.status.node_enable == "status.node_enable"
    
        _ = capsys.readouterr()  # throw away any stdout
        with smu.command_verification():
            smu.commands.status.node_enable = 1
            stdout = capsys.readouterr().out
            assert "Write" in stdout
            assert "Query" in stdout
    
        smu.load_script(
            "loadfuncs",
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            run_script=True,
            to_nv_memory=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
        smu.load_script(
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            script_name="tsp_function",
        )
        stdout = capsys.readouterr().out
        assert "loadscript tsp_function" in stdout
        assert "if tsp_function ~= nil then script.delete('tsp_function') end" in stdout
        assert "endscript" in stdout
        assert "tsp_function.save()" not in stdout
        assert "tsp_function()" not in stdout
        smu.expect_esr(0)
        smu.load_script(
            script_name="loadfuncs",
            script_body=(Path(os.path.realpath(__file__)).parent / "samples" / "tsp_script.tsp")
            .read_text()
            .strip(),
            run_script=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" not in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
    
        with mock.patch("pyvisa.highlevel.VisaLibraryBase.clear", mock.MagicMock(return_value=None)):
            assert smu.query_expect_timeout("INVALID?", timeout_ms=1) == ""
        with (
            mock.patch(
                "pyvisa.resources.messagebased.MessageBasedResource.query",
                mock.MagicMock(side_effect=visa.errors.Error("custom error")),
            ),
            pytest.raises(visa.errors.Error),
        ):
            smu.query_expect_timeout("INVALID?", timeout_ms=1)
        assert smu.expect_esr(32, ("Command error", "No Error"))
    
        with pytest.raises(AssertionError):
            smu.expect_esr(32, ("ERROR",))
    
        tspieee = smu._ieee_cmds  # noqa: SLF001
    
        # Currently there is no way to unit test the cls function. Called to get full coverage.
        tspieee.cls()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.ese(300)
        assert tspieee.ese(1) == "1"
        assert tspieee.ese() == "1"
        assert tspieee.esr() == "0"
        assert tspieee.opc(True) == ""
        assert tspieee.opc() == "1"
        # Currently there is no way to unit test the rst function. Called to get full coverage.
        tspieee.rst()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.sre(300)
        assert tspieee.sre(1) == "1"
        assert tspieee.sre() == "1"
        assert tspieee.stb() == "1"
        assert tspieee.tst() == "0"
        # Currently there is no way to unit test the wai function. Called to get full coverage.
        tspieee.wai()
        smu.expect_esr(0)
    
        # Test some generic device functionality
        capsys.readouterr()  # clear the buffer
        cmd_arg_constants_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at "
            f"{str(smu.command_argument_constants).split(' at ', maxsplit=1)[-1]}"
        )
        cmds_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at "
            f"{str(smu.commands).split(' at ', maxsplit=1)[-1]}"
        )
        print(smu)  # noqa: T201
        expected_stdout = f"""{"=" * 45} SMU {smu.device_number} {"=" * 45}
      <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at {id(smu)}
        address='SMU2601B-HOSTNAME'
        alias='SMU-DEVICE'
        all_channel_names_list=('a',)
        command_argument_constants={cmd_arg_constants_repr}
        command_syntax_enabled=False
        command_verification_enabled=False
        commands={cmds_repr}
        config_entry={smu.config_entry!r}
        connection_type='TCPIP'
        default_visa_timeout={UNIT_TEST_TIMEOUT}
        device_number={smu.device_number}
        device_type='SMU'
        enable_verification=True
        hostname='SMU2601B-HOSTNAME'
        idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
        ieee_cmds={smu.ieee_cmds!r}
        ip_address=''
        is_open=True
        login_command=None
        logout_command=None
        manufacturer='Keithley Instruments Inc.'
        model='Model 2601B'
        name='SMU {smu.device_number}'
        name_and_alias='SMU {smu.device_number} "SMU-DEVICE"'
        port=None
        resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
        serial='4498311'
        series='SMU2601B'
        sw_version=<Version('3.3.5')>
        total_channels=1
        verbose=True
        visa_backend='{smu.visa_backend}'
        visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
        visa_timeout={UNIT_TEST_TIMEOUT}
    {"=" * (97 + len(str(smu.device_number)) - 1)}
    """
        stdout = capsys.readouterr().out
>       assert stdout == expected_stdout
E       assert '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 140458858088400\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x7fbf20f9ef90>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x7fbf2057bed0>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x7fbf1bfe2b70>\n    ip_address=\'\'\n    is_open=True\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n' == '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 140458858088400\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x7fbf20f9ef90>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x7fbf2057bed0>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x7fbf1bfe2b70>\n    ip_address=\'\'\n    is_open=True\n    login_command=None\n    logout_command=None\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n'
E         
E           ============================================= SMU 49 =============================================
E             <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at 140458858088400
E               address='SMU2601B-HOSTNAME'
E               alias='SMU-DEVICE'
E               all_channel_names_list=('a',)
E               command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x7fbf20f9ef90>
E               command_syntax_enabled=False
E               command_verification_enabled=False
E               commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x7fbf2057bed0>
E               config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: 'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)
E               connection_type='TCPIP'
E               default_visa_timeout=50
E               device_number=49
E               device_type='SMU'
E               enable_verification=True
E               hostname='SMU2601B-HOSTNAME'
E               idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
E               ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x7fbf1bfe2b70>
E               ip_address=''
E               is_open=True
E         -     login_command=None
E         -     logout_command=None
E               manufacturer='Keithley Instruments Inc.'
E               model='Model 2601B'
E               name='SMU 49'
E               name_and_alias='SMU 49 "SMU-DEVICE"'
E               port=None
E               resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
E               serial='4498311'
E               series='SMU2601B'
E               sw_version=<Version('3.3.5')>
E               total_channels=1
E               verbose=True
E               visa_backend='PyVISA-sim'
E               visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
E               visa_timeout=50
E           ==================================================================================================

_          = CaptureResult(out='2026-09-08 15:42:21.000633 - Creating Connection to SMU 49 "SMU-DEVICE"\n2026-09-08 15:42:21.000633 - SMU "SMU-DEVICE" VISA timeout set to: 50.000ms\n2026-09-08 15:42:21.000633 - (SMU 49 "SMU-DEVICE") Query >>  \'*IDN?\'\n2026-09-08 15:42:21.000634 - Response from \'*IDN?\' >>  \'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n', err='')
caplog     = <_pytest.logging.LogCaptureFixture object at 0x7fbf20ff3490>
capsys     = <_pytest.capture.CaptureFixture object at 0x7fbf209599c0>
cmd_arg_constants_repr = ('<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at '
 '0x7fbf20f9ef90>')
cmds_repr  = ('<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at '
 '0x7fbf2057bed0>')
device_manager = <tm_devices.device_manager.DeviceManager object at 0x7fbf226b5e80>
expected_stdout = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 140458858088400\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x7fbf20f9ef90>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x7fbf2057bed0>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x7fbf1bfe2b70>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 '    login_command=None\n'
 '    logout_command=None\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
smu        = <tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B object at 0x7fbf205787d0>
stdout     = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 140458858088400\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x7fbf20f9ef90>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x7fbf2057bed0>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x7fbf1bfe2b70>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
tspieee    = <tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x7fbf1bfe2b70>

tests/test_smu.py:187: AssertionError

Link to workflow run

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Test Results (windows)

path passed failed subtotal
tests\test_abstract_device_expect_esr.py 1 1
tests\test_afgs.py 2 2
tests\test_alias_dict.py 1 1
tests\test_all_device_drivers.py 112 112
tests\test_alternative_connection_addresses.py 19 19
tests\test_awgs.py 4 4
tests\test_config_parser.py 50 50
tests\test_device_manager.py 20 20
tests\test_devices_legacy_tsp_ieee_cmds.py 3 3
tests\test_extension_mixin.py 1 1
tests\test_generate_waveform.py 6 6
tests\test_helpers.py 94 94
tests\test_ieee_scpi_cmds.py 1 1
tests\test_logging.py 5 5
tests\test_mainframe.py 13 13
tests\test_margin_testers.py 5 5
tests\test_pi_device.py 1 1
tests\test_psu.py 1 1
tests\test_rest_api_device.py 10 10
tests\test_schema.py 7 7
tests\test_scopes.py 10 10
tests\test_singleton.py 1 1
tests\test_smu.py 3 1 4
tests\test_ss.py 1 1
tests\test_tm_devices.py 471 471
tests\test_unsupported_device_type.py 1 1
tests\test_verification_functions.py 13 13
TOTAL 856 1 857
tests\test_smu.py
device_manager = <tm_devices.device_manager.DeviceManager object at 0x000001ACD7E4B0E0>
capsys = <_pytest.capture.CaptureFixture object at 0x000001ACDA2D9910>
caplog = <_pytest.logging.LogCaptureFixture object at 0x000001ACD886BCE0>

    def test_smu(  # noqa: PLR0915
        device_manager: DeviceManager,
        capsys: pytest.CaptureFixture[str],
        caplog: pytest.LogCaptureFixture,
    ) -> None:
        """Test the SMU driver and TSP's IEEE commands.
    
        Args:
            device_manager: The DeviceManager object.
            capsys: The captured stdout and stderr.
            caplog: The captured log messages.
        """
        smu: SMU2601B = device_manager.add_smu("smu2601b-hostname", alias="smu-device")
        assert id(device_manager.get_smu(number_or_alias="smu-device")) == id(smu)
        assert id(device_manager.get_smu(number_or_alias=smu.device_number)) == id(smu)
    
        assert smu.manufacturer == "Keithley Instruments Inc."
        assert smu.model == "Model 2601B"
        assert smu.serial == "4498311"
        assert smu.sw_version == Version("3.3.5")
    
        with smu.command_syntax():
            assert smu.commands.status.node_enable == "status.node_enable"
    
        _ = capsys.readouterr()  # throw away any stdout
        with smu.command_verification():
            smu.commands.status.node_enable = 1
            stdout = capsys.readouterr().out
            assert "Write" in stdout
            assert "Query" in stdout
    
        smu.load_script(
            "loadfuncs",
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            run_script=True,
            to_nv_memory=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
        smu.load_script(
            file_path=f"{Path(os.path.realpath(__file__)).parent}/samples/tsp_script.tsp",
            script_name="tsp_function",
        )
        stdout = capsys.readouterr().out
        assert "loadscript tsp_function" in stdout
        assert "if tsp_function ~= nil then script.delete('tsp_function') end" in stdout
        assert "endscript" in stdout
        assert "tsp_function.save()" not in stdout
        assert "tsp_function()" not in stdout
        smu.expect_esr(0)
        smu.load_script(
            script_name="loadfuncs",
            script_body=(Path(os.path.realpath(__file__)).parent / "samples" / "tsp_script.tsp")
            .read_text()
            .strip(),
            run_script=True,
        )
        stdout = capsys.readouterr().out
        assert "loadscript loadfuncs" in stdout
        assert "if loadfuncs ~= nil then script.delete('loadfuncs') end" in stdout
        assert "endscript" in stdout
        assert "loadfuncs.save()" not in stdout
        assert "loadfuncs()" in stdout
        smu.expect_esr(0)
    
        with mock.patch("pyvisa.highlevel.VisaLibraryBase.clear", mock.MagicMock(return_value=None)):
            assert smu.query_expect_timeout("INVALID?", timeout_ms=1) == ""
        with (
            mock.patch(
                "pyvisa.resources.messagebased.MessageBasedResource.query",
                mock.MagicMock(side_effect=visa.errors.Error("custom error")),
            ),
            pytest.raises(visa.errors.Error),
        ):
            smu.query_expect_timeout("INVALID?", timeout_ms=1)
        assert smu.expect_esr(32, ("Command error", "No Error"))
    
        with pytest.raises(AssertionError):
            smu.expect_esr(32, ("ERROR",))
    
        tspieee = smu._ieee_cmds  # noqa: SLF001
    
        # Currently there is no way to unit test the cls function. Called to get full coverage.
        tspieee.cls()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.ese(300)
        assert tspieee.ese(1) == "1"
        assert tspieee.ese() == "1"
        assert tspieee.esr() == "0"
        assert tspieee.opc(True) == ""
        assert tspieee.opc() == "1"
        # Currently there is no way to unit test the rst function. Called to get full coverage.
        tspieee.rst()
        with pytest.raises(
            ValueError, match=r"value=300 is not a valid value\. The value must be between 0 and 255\."
        ):
            tspieee.sre(300)
        assert tspieee.sre(1) == "1"
        assert tspieee.sre() == "1"
        assert tspieee.stb() == "1"
        assert tspieee.tst() == "0"
        # Currently there is no way to unit test the wai function. Called to get full coverage.
        tspieee.wai()
        smu.expect_esr(0)
    
        # Test some generic device functionality
        capsys.readouterr()  # clear the buffer
        cmd_arg_constants_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at "
            f"{str(smu.command_argument_constants).split(' at ', maxsplit=1)[-1]}"
        )
        cmds_repr = (
            f"<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at "
            f"{str(smu.commands).split(' at ', maxsplit=1)[-1]}"
        )
        print(smu)  # noqa: T201
        expected_stdout = f"""{"=" * 45} SMU {smu.device_number} {"=" * 45}
      <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at {id(smu)}
        address='SMU2601B-HOSTNAME'
        alias='SMU-DEVICE'
        all_channel_names_list=('a',)
        command_argument_constants={cmd_arg_constants_repr}
        command_syntax_enabled=False
        command_verification_enabled=False
        commands={cmds_repr}
        config_entry={smu.config_entry!r}
        connection_type='TCPIP'
        default_visa_timeout={UNIT_TEST_TIMEOUT}
        device_number={smu.device_number}
        device_type='SMU'
        enable_verification=True
        hostname='SMU2601B-HOSTNAME'
        idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
        ieee_cmds={smu.ieee_cmds!r}
        ip_address=''
        is_open=True
        login_command=None
        logout_command=None
        manufacturer='Keithley Instruments Inc.'
        model='Model 2601B'
        name='SMU {smu.device_number}'
        name_and_alias='SMU {smu.device_number} "SMU-DEVICE"'
        port=None
        resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
        serial='4498311'
        series='SMU2601B'
        sw_version=<Version('3.3.5')>
        total_channels=1
        verbose=True
        visa_backend='{smu.visa_backend}'
        visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
        visa_timeout={UNIT_TEST_TIMEOUT}
    {"=" * (97 + len(str(smu.device_number)) - 1)}
    """
        stdout = capsys.readouterr().out
>       assert stdout == expected_stdout
E       assert '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 1841903629520\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x000001ACD859BB60>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x000001ACDA02F610>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x000001ACD9AE9270>\n    ip_address=\'\'\n    is_open=True\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n' == '============================================= SMU 49 =============================================\n  <class \'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B\'> object at 1841903629520\n    address=\'SMU2601B-HOSTNAME\'\n    alias=\'SMU-DEVICE\'\n    all_channel_names_list=(\'a\',)\n    command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x000001ACD859BB60>\n    command_syntax_enabled=False\n    command_verification_enabled=False\n    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x000001ACDA02F610>\n    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: \'SMU\'>, address=\'SMU2601B-HOSTNAME\', connection_type=<ConnectionTypes.TCPIP: \'TCPIP\'>, alias=\'SMU-DEVICE\', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)\n    connection_type=\'TCPIP\'\n    default_visa_timeout=50\n    device_number=49\n    device_type=\'SMU\'\n    enable_verification=True\n    hostname=\'SMU2601B-HOSTNAME\'\n    idn_string=\'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n    ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x000001ACD9AE9270>\n    ip_address=\'\'\n    is_open=True\n    login_command=None\n    logout_command=None\n    manufacturer=\'Keithley Instruments Inc.\'\n    model=\'Model 2601B\'\n    name=\'SMU 49\'\n    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n    port=None\n    resource_expression=\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\'\n    serial=\'4498311\'\n    series=\'SMU2601B\'\n    sw_version=<Version(\'3.3.5\')>\n    total_channels=1\n    verbose=True\n    visa_backend=\'PyVISA-sim\'\n    visa_resource=<\'TCPIPInstrument\'(\'TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR\')>\n    visa_timeout=50\n==================================================================================================\n'
E         
E           ============================================= SMU 49 =============================================
E             <class 'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object at 1841903629520
E               address='SMU2601B-HOSTNAME'
E               alias='SMU-DEVICE'
E               all_channel_names_list=('a',)
E               command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at 0x000001ACD859BB60>
E               command_syntax_enabled=False
E               command_verification_enabled=False
E               commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at 0x000001ACDA02F610>
E               config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: 'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, serial_config=None, device_driver=None, login_command=None, logout_command=None, gpib_board_number=None)
E               connection_type='TCPIP'
E               default_visa_timeout=50
E               device_number=49
E               device_type='SMU'
E               enable_verification=True
E               hostname='SMU2601B-HOSTNAME'
E               idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'
E               ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x000001ACD9AE9270>
E               ip_address=''
E               is_open=True
E         -     login_command=None
E         -     logout_command=None
E               manufacturer='Keithley Instruments Inc.'
E               model='Model 2601B'
E               name='SMU 49'
E               name_and_alias='SMU 49 "SMU-DEVICE"'
E               port=None
E               resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'
E               serial='4498311'
E               series='SMU2601B'
E               sw_version=<Version('3.3.5')>
E               total_channels=1
E               verbose=True
E               visa_backend='PyVISA-sim'
E               visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>
E               visa_timeout=50
E           ==================================================================================================

_          = CaptureResult(out='2026-09-08 15:43:07.000452 - Creating Connection to SMU 49 "SMU-DEVICE"\n2026-09-08 15:43:07.000453 - SMU "SMU-DEVICE" VISA timeout set to: 50.000ms\n2026-09-08 15:43:07.000453 - (SMU 49 "SMU-DEVICE") Query >>  \'*IDN?\'\n2026-09-08 15:43:07.000454 - Response from \'*IDN?\' >>  \'Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5\'\n', err='')
caplog     = <_pytest.logging.LogCaptureFixture object at 0x000001ACD886BCE0>
capsys     = <_pytest.capture.CaptureFixture object at 0x000001ACDA2D9910>
cmd_arg_constants_repr = ('<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants object at '
 '0x000001ACD859BB60>')
cmds_repr  = ('<tm_devices.commands.smu2601b_commands.SMU2601BCommands object at '
 '0x000001ACDA02F610>')
device_manager = <tm_devices.device_manager.DeviceManager object at 0x000001ACD7E4B0E0>
expected_stdout = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 1841903629520\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x000001ACD859BB60>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x000001ACDA02F610>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x000001ACD9AE9270>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 '    login_command=None\n'
 '    logout_command=None\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
smu        = <tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B object at 0x000001ACDA02F4D0>
stdout     = ('============================================= SMU 49 '
 '=============================================\n'
 '  <class '
 "'tm_devices.drivers.source_measure_units.smu26xx.smu2601b.SMU2601B'> object "
 'at 1841903629520\n'
 "    address='SMU2601B-HOSTNAME'\n"
 "    alias='SMU-DEVICE'\n"
 "    all_channel_names_list=('a',)\n"
 '    '
 'command_argument_constants=<tm_devices.commands.smu2601b_commands.SMU2601BCommandConstants '
 'object at 0x000001ACD859BB60>\n'
 '    command_syntax_enabled=False\n'
 '    command_verification_enabled=False\n'
 '    commands=<tm_devices.commands.smu2601b_commands.SMU2601BCommands object '
 'at 0x000001ACDA02F610>\n'
 "    config_entry=DeviceConfigEntry(device_type=<DeviceTypes.SMU: 'SMU'>, "
 "address='SMU2601B-HOSTNAME', connection_type=<ConnectionTypes.TCPIP: "
 "'TCPIP'>, alias='SMU-DEVICE', lan_port=None, lan_device_endpoint=None, "
 'serial_config=None, device_driver=None, login_command=None, '
 'logout_command=None, gpib_board_number=None)\n'
 "    connection_type='TCPIP'\n"
 '    default_visa_timeout=50\n'
 '    device_number=49\n'
 "    device_type='SMU'\n"
 '    enable_verification=True\n'
 "    hostname='SMU2601B-HOSTNAME'\n"
 "    idn_string='Keithley Instruments Inc., Model 2601B, 4498311, 3.3.5'\n"
 '    '
 'ieee_cmds=<tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands '
 'object at 0x000001ACD9AE9270>\n'
 "    ip_address=''\n"
 '    is_open=True\n'
 "    manufacturer='Keithley Instruments Inc.'\n"
 "    model='Model 2601B'\n"
 "    name='SMU 49'\n"
 '    name_and_alias=\'SMU 49 "SMU-DEVICE"\'\n'
 '    port=None\n'
 "    resource_expression='TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR'\n"
 "    serial='4498311'\n"
 "    series='SMU2601B'\n"
 "    sw_version=<Version('3.3.5')>\n"
 '    total_channels=1\n'
 '    verbose=True\n'
 "    visa_backend='PyVISA-sim'\n"
 '    '
 "visa_resource=<'TCPIPInstrument'('TCPIP0::SMU2601B-HOSTNAME::inst0::INSTR')>\n"
 '    visa_timeout=50\n'
 '==================================================================================================\n')
tspieee    = <tm_devices.driver_mixins.shared_implementations.ieee488_2_commands.TSPIEEE4882Commands object at 0x000001ACD9AE9270>

tests\test_smu.py:187: AssertionError

Link to workflow run

visa_resource.read.return_value = idn_response
visa_resource.query.return_value = idn_response
visa_resource.timeout = 5000
visa_resource.resource_info.resource_name = "TCPIP0::AFG3252C-HOSTNAME::inst0::INSTR"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this device type actually have an option to use login commands? just making sure our examples are realistic since they are often referenced.

@nfelt14

nfelt14 commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

@jhenlely1, are you going to make the changes necessary to get this ready for merge?

This branch was previously deployed

1 inactive deployment
package-build — 3110ada1 Deployed Sep 8, 2026 by jhenlely1 via package-build / Build package #1921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants