Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_socket_number_attribute():
with nimodinst.Session('') as session:
assert len(session) > 0, 'Must have hardware for ModInst tests to be valid.'
assert isinstance(session.devices[0].socket_number, int)
def test_cannot_add_properties_to_session_get(self):
with nimodinst.Session('') as session:
try:
session.non_existent_property
assert False
except AttributeError as e:
assert str(e) == "'Session' object has no attribute 'non_existent_property'"
def test_int_attribute_warning(self):
warning_code = 1234
error_string = 'Error'
self.patched_library.niModInst_GetInstalledDeviceAttributeViInt32.side_effect = self.side_effects_helper.niModInst_GetInstalledDeviceAttributeViInt32
self.side_effects_helper['GetInstalledDeviceAttributeViInt32']['attributeValue'] = -1
self.side_effects_helper['GetInstalledDeviceAttributeViInt32']['return'] = warning_code
self.patched_library.niModInst_GetExtendedErrorInfo.side_effect = self.side_effects_helper.niModInst_GetExtendedErrorInfo
self.side_effects_helper['GetExtendedErrorInfo']['errorInfo'] = error_string
with nimodinst.Session('') as session:
with warnings.catch_warnings(record=True) as w:
session.devices[0].chassis_number
assert len(w) == 1
assert issubclass(w[0].category, nimodinst.DriverWarning)
assert error_string in str(w[0].message)
def test_max_pciexpress_link_width_attribute():
with nimodinst.Session('') as session:
assert len(session) > 0, 'Must have hardware for ModInst tests to be valid.'
assert isinstance(session.devices[0].max_pciexpress_link_width, int)
def test_string_attribute_error_on_non_existant_device():
with nimodinst.Session('') as session:
device = len(session) + 1
try:
session.devices[device].slot_number
assert False
except IndexError:
pass
def test_get_attribute_vi_string_for_loop_index(self):
self.patched_library.niModInst_GetInstalledDeviceAttributeViString.side_effect = self.niModInst_GetInstalledDeviceAttributeViString_looping
self.side_effects_helper['OpenInstalledDevicesSession']['deviceCount'] = self.num_string_devices_looping
index = 0
with nimodinst.Session('') as session:
attr_int = session.devices[index].device_name
index += 1
assert(attr_int == self.string_vals_device_looping[self.iteration_device_looping - 1]) # Have to subtract once since it was already incremented in the callback function
def test_get_attribute_vi_int32_for_loop_multiple_devices(self):
self.patched_library.niModInst_GetInstalledDeviceAttributeViInt32.side_effect = self.niModInst_GetInstalledDeviceAttributeViInt32_looping
self.side_effects_helper['OpenInstalledDevicesSession']['deviceCount'] = self.num_int_devices_looping
with nimodinst.Session('') as session:
for d in session:
attr_int = d.chassis_number
assert(attr_int == self.int_vals_device_looping[self.iteration_device_looping - 1]) # Have to subtract once since it was already incremented in the callback function
def test_serial_number_attribute():
with nimodinst.Session('') as session:
assert len(session) > 0, 'Must have hardware for ModInst tests to be valid.'
pattern = r'^[0-9A-F]+$'
assert isinstance(session.devices[0].serial_number, six.text_type)
assert (len(session.devices[0].serial_number) == 0) | (re.search(pattern, session.devices[0].serial_number) is not None) # NI Serial numbers hex unless it is simulated than it is 0
def example():
with nimodinst.Session('') as session:
if len(session) > 0:
print("%d items" % len(session))
print("{: >20} {: >15} {: >10}".format('Name', 'Model', 'S/N'))
for d in session:
print("{: >20} {: >15} {: >10}".format(d.device_name, d.device_model, d.serial_number))