ni / nimi-python

Python bindings for NI Modular Instrument drivers.
Other
112 stars 84 forks source link

Incorrect error when driver runtime not installed #1970

Closed marcoskirsch closed 1 year ago

marcoskirsch commented 1 year ago

Description of issue

I wrote a simple Python script that uses niswitch but forgot to install the NI-SWITCH driver runtime. I got the following error:

C:\Users\mkirsch>python ceip_test.py
Traceback (most recent call last):
  File "C:\Users\mkirsch\ceip_test.py", line 44, in <module>
    with niswitch.Session(resource_name="2510") as s:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkirsch\AppData\Local\Programs\Python\Python311\Lib\site-packages\niswitch\session.py", line 1362, in __init__
    interpreter = _library_interpreter.LibraryInterpreter(encoding='windows-1251')
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkirsch\AppData\Local\Programs\Python\Python311\Lib\site-packages\niswitch\_library_interpreter.py", line 58, in __init__
    self._library = _library_singleton.get()
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkirsch\AppData\Local\Programs\Python\Python311\Lib\site-packages\niswitch\_library_singleton.py", line 50, in get
    ctypes_library = ctypes.CDLL(_get_library_name())
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkirsch\AppData\Local\Programs\Python\Python311\Lib\ctypes\__init__.py", line 366, in __init__
    if '/' in name or '\\' in name:
       ^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

I expected DriverNotInstalledError

It's not good if we broke this and our automated testing (unit testing in this case) didn't catch it.

System report

C:\Users\mkirsch>python -c "import niswitch; niswitch.print_diagnostic_information()"
OS:
    Name:      Windows
    Version:   10.0.22000
    Bits:      64
Driver:
    Name:      NI-SWITCH
    Version:   Unknown
Module:
    Name:      niswitch
    Version:   1.4.4
Python:
    Version:   3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]
    Bits:      64
    Is_Venv:   False
    Installed Packages:
        setuptools==65.5.0
        pip==22.3.1
        nidcpower==1.4.4
        nidmm==1.4.4
        niswitch==1.4.4
        hightime==0.2.1

Steps to reproduce issue

On a system in which NI-SWITCH driver runtime is not installed, run the following script:

import niswitch

with niswitch.Session(resource_name="2510") as s:
    pass