From aa1f061ef33275e211b0620d59fa9ad34a6626e7 Mon Sep 17 00:00:00 2001 From: Michi <michi.hostettler@cern.ch> Date: Fri, 17 Jan 2025 19:43:25 +0100 Subject: [PATCH 1/2] mockito 5 workaround (specifically for SET) --- pyjapc/tests/conftest.py | 11 +++++++++++ pyjapc/tests/test_getNextParamValue.py | 15 +++++++-------- pyjapc/tests/test_subscribeParam.py | 7 ++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pyjapc/tests/conftest.py b/pyjapc/tests/conftest.py index 09230ed..a655ad1 100644 --- a/pyjapc/tests/conftest.py +++ b/pyjapc/tests/conftest.py @@ -118,3 +118,14 @@ def japc_mock(jvm) -> typing.Generator[typing.Type["cern.japc.ext.mockito.JapcMo yield mock mock.resetToDefault() mock.mockNoService() + +@pytest.fixture +def japc_set(jvm): + cern = jp.JPackage('cern') + JapcUtils = cern.japc.core.util.JapcUtils + def setter(param, selector, value): + result = JapcUtils.setValuesAsync({param: value}, selector) + exception = result.values().iterator().next().getException() + if exception is not None: + raise RuntimeError(exception.getMessage()) + return setter diff --git a/pyjapc/tests/test_getNextParamValue.py b/pyjapc/tests/test_getNextParamValue.py index 970cbae..f8a570b 100644 --- a/pyjapc/tests/test_getNextParamValue.py +++ b/pyjapc/tests/test_getNextParamValue.py @@ -3,12 +3,12 @@ import time import pytest +from pyjapc.tests.conftest import japc_set WAIT_TIME = 0.05 -@pytest.mark.skip(reason="Unhandled problem with mockito 5") -def test_simple_case(japc, japc_mock): +def test_simple_case(japc, japc_mock, japc_set): param_name = 'TEST/TestProperty' param = japc_mock.mockParameter(param_name) japc_mock.whenGetValueThen( @@ -18,7 +18,7 @@ def test_simple_case(japc, japc_mock): japc.getNextParamValue(param_name, timeout=0.25) def set_value(): - param.setValue(japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) + japc_set(param, japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) threading.Timer(WAIT_TIME, set_value).start() result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST") @@ -30,19 +30,18 @@ def test_simple_case(japc, japc_mock): assert 'isFirstUpdate' in result[1] -@pytest.mark.skip(reason="Unhandled problem with mockito 5") -def test_n_values(japc, japc_mock): +def test_n_values(japc, japc_mock, japc_set): param_name = 'TEST/TestProperty' param = japc_mock.mockParameter(param_name) japc_mock.whenGetValueThen( param, japc_mock.sel('LHC.USER.TEST'), japc_mock.acqVal(param_name, 42, 0)) def set_several_values(): - param.setValue(japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) + japc_set(param, japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) time.sleep(WAIT_TIME) - param.setValue(japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(113)) + japc_set(param, japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(113)) time.sleep(WAIT_TIME) - param.setValue(japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(-1)) + japc_set(param, japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(-1)) threading.Timer(WAIT_TIME, set_several_values).start() result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST", n_values=3) diff --git a/pyjapc/tests/test_subscribeParam.py b/pyjapc/tests/test_subscribeParam.py index 19d3f4c..71c6fde 100644 --- a/pyjapc/tests/test_subscribeParam.py +++ b/pyjapc/tests/test_subscribeParam.py @@ -2,13 +2,10 @@ import logging import time from unittest import mock -import pytest - SMALL_WAIT = 0.1 -@pytest.mark.xfail(reason="Unhandled problem with mockito 5") -def test_subscription_integration(japc, japc_mock): +def test_subscription_integration(japc, japc_mock, japc_set): param_name = "TEST/TestProperty" param = japc_mock.mockParameter(param_name) japc_mock.whenGetValueThen( @@ -36,7 +33,7 @@ def test_subscription_integration(japc, japc_mock): callback.reset_mock() # Check that a new value is sent. - param.setValue(japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) + japc_set(param, japc_mock.sel("LHC.USER.TEST"), japc_mock.spv(112)) time.sleep(SMALL_WAIT) assert callback.call_args[0][:2] == (param_name, 112) assert callback.call_args[0][2]['isFirstUpdate'] is False -- GitLab From c39d82626eed4144a9275f96495b33b722e3d9db Mon Sep 17 00:00:00 2001 From: Michi <michi.hostettler@cern.ch> Date: Mon, 20 Jan 2025 09:43:24 +0100 Subject: [PATCH 2/2] fix imports --- pyjapc/tests/test_getNextParamValue.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyjapc/tests/test_getNextParamValue.py b/pyjapc/tests/test_getNextParamValue.py index f8a570b..92d9e2a 100644 --- a/pyjapc/tests/test_getNextParamValue.py +++ b/pyjapc/tests/test_getNextParamValue.py @@ -3,8 +3,6 @@ import time import pytest -from pyjapc.tests.conftest import japc_set - WAIT_TIME = 0.05 -- GitLab