Skip to content

Commit 9b5cc3a

Browse files
authored
Raise error if library not found, before attempting to load it (#1992)
* Raise error if library not found, before attempting to load it * add test_get_uninstalled_driver_library_raises_driver_not_installed_error * Update changelog * rename test
1 parent 8b2b8d0 commit 9b5cc3a

File tree

14 files changed

+59
-11
lines changed

14 files changed

+59
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ All notable changes to this project will be documented in this file.
3636
* ### ALL
3737
* #### Added
3838
* #### Changed
39+
* Fix [#1970](https://github.com/ni/nimi-python/issues/1970): Incorrect error when driver runtime not installed.
3940
* #### Removed
4041
* Support for Python 3.7
4142
* ### `nidcpower` (NI-DCPower)

build/templates/_library_singleton.py.mako

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ _library_info = ${helper.get_dictionary_snippet(config['library_info'], indent=1
2323

2424
def _get_library_name():
2525
try:
26-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
26+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
27+
if lib_name is None:
28+
raise errors.DriverNotInstalledError()
29+
return lib_name
2730
except KeyError:
2831
raise errors.UnsupportedConfigurationError
2932

generated/nidcpower/nidcpower/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

generated/nidigital/nidigital/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

generated/nidmm/nidmm/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

generated/nifake/nifake/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import nifake
2+
import pytest
3+
4+
5+
def test_driver_runtime_not_installed_raises_driver_not_installed_error():
6+
with pytest.raises(nifake.errors.DriverNotInstalledError):
7+
nifake._library_singleton.get()

generated/nifgen/nifgen/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

generated/nimodinst/nimodinst/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

generated/niscope/niscope/_library_singleton.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
def _get_library_name():
2121
try:
22-
return ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
22+
lib_name = ctypes.util.find_library(_library_info[platform.system()][platform.architecture()[0]]['name']) # We find and return full path to the DLL
23+
if lib_name is None:
24+
raise errors.DriverNotInstalledError()
25+
return lib_name
2326
except KeyError:
2427
raise errors.UnsupportedConfigurationError
2528

0 commit comments

Comments
 (0)