From a0a387c0452b73b6288e03338fcb24886c3fca8c Mon Sep 17 00:00:00 2001 From: Jay Fitzgerald <34140133+ni-jfitzger@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:30:18 -0500 Subject: [PATCH] Use simulated 5433 for all nifgen system tests (#2010) * reimplement PR#1598 - Stop using DAQmx-based simulated device in nifgen system tests * Fix test_get_self_cal_last_date_and_time failure * Fix test_create_advanced_arb_sequence failure * Fix flake8 failures --- src/nifgen/system_tests/test_system_nifgen.py | 62 ++++++------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/src/nifgen/system_tests/test_system_nifgen.py b/src/nifgen/system_tests/test_system_nifgen.py index 20e9c24f6..8c8a1ce22 100644 --- a/src/nifgen/system_tests/test_system_nifgen.py +++ b/src/nifgen/system_tests/test_system_nifgen.py @@ -4,7 +4,6 @@ import tempfile import warnings -import fasteners import grpc import hightime import numpy @@ -16,20 +15,9 @@ import system_test_utilities # noqa: E402 -# Set up some global information we need +# Set up global information we need test_files_base_dir = os.path.join(os.path.dirname(__file__)) -# We need a lock file so multiple tests aren't hitting the db at the same time -# Trying to create simulated DAQmx devices at the same time (which can happen when running -# tox with --parallel N, or when two different drivers are being tested at the same time on -# the same machine, can result in an internal error: -# -2147220733: MAX: (Hex 0x80040303) Internal error: The requested object was not found in -# the configuration database. Please note the steps you performed that led to this error and -# contact technical support at http://ni.com/support. -# This is filed as internal bug 255545 -daqmx_sim_db_lock_file = os.path.join(tempfile.gettempdir(), 'daqmx_db.lock') -daqmx_sim_db_lock = fasteners.InterProcessLock(daqmx_sim_db_lock_file) - def get_test_file_path(file_name): return os.path.join(test_files_base_dir, file_name) @@ -48,14 +36,6 @@ def session(self, session_creation_kwargs): with nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe', **session_creation_kwargs) as simulated_session: yield simulated_session - @pytest.fixture(scope='function') - def session_5421(self, session_creation_kwargs): - with daqmx_sim_db_lock: - simulated_session = nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI', **session_creation_kwargs) - yield simulated_session - with daqmx_sim_db_lock: - simulated_session.close() - def test_self_test(self, session): # We should not get an assert if self_test passes session.self_test() @@ -91,13 +71,13 @@ def test_get_error(self, session): def test_method_get_self_cal_supported(self, session): assert session.get_self_cal_supported() in [True, False] - # TODO(sbethur): When internal bug# 999932 is fixed, update the test to use PXIe-5433 (Tracked on GitHub by #1375) - def test_get_self_cal_last_date_and_time(self, session_5421): - try: - session_5421.get_self_cal_last_date_and_time() - assert False - except nifgen.Error as e: - assert e.code == -1074118632 # This operation is not supported for simulated device + def test_get_self_cal_last_date_and_time(self, session): + before = hightime.datetime.now() + # Returned cal time does not have sub-minute info + before = before.replace(second=0, microsecond=0) + last_cal_time = session.get_self_cal_last_date_and_time() + after = hightime.datetime.now() + assert before <= last_cal_time <= after def test_self_cal(self, session): session.self_cal() @@ -247,20 +227,19 @@ def test_create_arb_sequence(self, session): assert 0 == session.create_arb_sequence(waveform_handles_array, [10]) assert 1 == session.create_arb_sequence(waveform_handles_array, [10]) - # TODO(sbethur): When internal bug# 227842 is fixed, update the test to use PXIe-5433 (Tracked on GitHub by #1376) - def test_create_advanced_arb_sequence(self, session_5421): - seq_handle_base = 100000 # This is not necessary on 5433 because handles start at 0. + def test_create_advanced_arb_sequence(self, session): + seq_handle_base = 0 # On 5433, handles start at 0. waveform_data = [x * (1.0 / 256.0) for x in range(256)] - waveform_handles_array = [session_5421.create_waveform(waveform_data), session_5421.create_waveform(waveform_data), session_5421.create_waveform(waveform_data)] + waveform_handles_array = [session.create_waveform(waveform_data), session.create_waveform(waveform_data), session.create_waveform(waveform_data)] marker_location_array = [0, 16, 32] sample_counts_array = [256, 128, 64] loop_counts_array = [10, 20, 30] - session_5421.output_mode = nifgen.OutputMode.SEQ + session.output_mode = nifgen.OutputMode.SEQ # Test relies on value of sequence handles starting at a known value and incrementing sequentially. Hardly ideal. - assert ([], seq_handle_base + 0) == session_5421.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array) - assert ([], seq_handle_base + 1) == session_5421.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array) - assert (marker_location_array, seq_handle_base + 2) == session_5421.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array) - assert (marker_location_array, seq_handle_base + 3) == session_5421.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array, marker_location_array=marker_location_array) + assert ([], seq_handle_base + 0) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array) + assert ([], seq_handle_base + 1) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array) + assert (marker_location_array, seq_handle_base + 2) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array) + assert (marker_location_array, seq_handle_base + 3) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array, marker_location_array=marker_location_array) def test_arb_script(self, session): waveform_data = [x * (1.0 / 256.0) for x in range(256)] @@ -469,16 +448,15 @@ def test_create_waveform_wrong_type(self, session): except (TypeError, ValueError): pass - # TODO(sbethur): When internal bug# 227842 is fixed, update the test to use PXIe-5433 (Tracked on GitHub by #1376) - def test_create_advanced_arb_sequence_wrong_size(self, session_5421): + def test_create_advanced_arb_sequence_wrong_size(self, session): waveform_data = [x * (1.0 / 256.0) for x in range(256)] - waveform_handles_array = [session_5421.create_waveform(waveform_data), session_5421.create_waveform(waveform_data), session_5421.create_waveform(waveform_data)] + waveform_handles_array = [session.create_waveform(waveform_data), session.create_waveform(waveform_data), session.create_waveform(waveform_data)] marker_location_array = [0, 16] loop_counts_array = [10, 20, 30] - session_5421.output_mode = nifgen.OutputMode.SEQ + session.output_mode = nifgen.OutputMode.SEQ # Test relies on value of sequence handles starting at a known value and incrementing sequentially. Hardly ideal. with pytest.raises(ValueError) as exc_info: - session_5421.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array) + session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array) assert exc_info.value.args[0] == 'Length of marker_location_array and waveform_handles_array parameters do not match.' assert str(exc_info.value) == 'Length of marker_location_array and waveform_handles_array parameters do not match.'