def run_py_as_rtseq(toplevelfunc, rtseq_params={}): """ Runs a Python function as an RT sequence in the VeriStand Engine. Args: toplevelfunc: the Python function to run. rtseq_params (Dict[str, niveristand.clientapi._datatypes.rtprimitives.DoubleValue]): the parameters to be passed to the RT sequence. Returns: Union[float, None]: The numeric value returned by the real-time sequence execution. Raises: :any:`TranslateError`: if the function is not successfully translated. :any:`RunAbortedError`: if this function calls :any:`generate_error` with an action of Abort or Stop. :any:`RunFailedError`: if this function calls :any:`generate_error` with a Continue action. """ from niveristand.clientapi import RealTimeSequence seq = RealTimeSequence(toplevelfunc) result_state = seq.run(rtseq_params) result_state.wait_for_result() result_state.session.undeploy() if result_state.last_error: raise RunError.RunErrorFactory(result_state.last_error) return result_state.ret_val
def test_realtimesequence_channel_reference_param(): desired_rpm = ChannelReference('Aliases/DesiredRPM') desired_rpm.value = 100.101 rtseq = RealTimeSequence(func1) actual = rtseq.run({"p": desired_rpm}) actual.wait_for_result() assert actual.ret_val == 100.101
def run_py_as_rtseq(toplevelfunc, timeout_within_each_step=100000): """ Runs a Python function as an RT sequence in the VeriStand Engine. Args: toplevelfunc: the Python function to run. timeout_within_each_step (Optional[int]): time, in milliseconds, each step can take before execution is aborted. Returns: The numeric value returned by the real-time sequence execution. Raises: :any:`TranslateError`: if the function is not successfully translated. :any:`RunAbortedError`: if this function calls :any:`generate_error` with an action of Abort or Stop. :any:`RunFailedError`: if this function calls :any:`generate_error` with a Continue action. """ from niveristand.clientapi import RealTimeSequence seq = RealTimeSequence(toplevelfunc) result_state = seq.run(timeout_within_each_step=timeout_within_each_step) result_state.wait_for_result() result_state.session.Undeploy() if result_state.last_error: raise RunError.RunErrorFactory(result_state.last_error) return result_state.ret_val
def test_not_wait_to_complete(): seq = RealTimeSequence(return_var) result_state = seq.run() assert result_state.ret_val is None result_state.wait_for_result() assert result_state.ret_val == 5
def test_realtimesequence_wrong_parameter_data_type(): rtseq = RealTimeSequence(func2) with pytest.raises(VeristandError): rtseq.run({"p": DoubleValue(2.3)})
def test_realtimesequence_missing_by_value_parameter(): rtseq = RealTimeSequence(func2) actual = rtseq.run({}) actual.wait_for_result() assert actual.ret_val == 1.2
def test_realtimesequence_missing_by_ref_parameter(): rtseq = RealTimeSequence(func1) with pytest.raises(VeristandError): rtseq.run({})
def test_realtimesequence_invalid_extra_parameter(): rtseq = RealTimeSequence(func1) with pytest.raises(VeristandError): rtseq.run({"p": DoubleValue(2.3), "pp": DoubleValue(3.4)})
def test_realtimesequence_numeric_param(): rtseq = RealTimeSequence(func1) actual = rtseq.run({"p": DoubleValue(2.3)}) actual.wait_for_result() assert actual.ret_val == 2.3