Skip to content
Snippets Groups Projects
Commit c47e93c6 authored by Philip Elson's avatar Philip Elson :snake:
Browse files

Merge branch 'feature/mockito-5-workaround' into 'master'

mockito 5 workaround

See merge request !112
parents f5344c0d c39d8262
No related branches found
No related tags found
1 merge request!112mockito 5 workaround
Pipeline #11971717 running
...@@ -118,3 +118,14 @@ def japc_mock(jvm) -> typing.Generator[typing.Type["cern.japc.ext.mockito.JapcMo ...@@ -118,3 +118,14 @@ def japc_mock(jvm) -> typing.Generator[typing.Type["cern.japc.ext.mockito.JapcMo
yield mock yield mock
mock.resetToDefault() mock.resetToDefault()
mock.mockNoService() 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
...@@ -3,12 +3,10 @@ import time ...@@ -3,12 +3,10 @@ import time
import pytest import pytest
WAIT_TIME = 0.05 WAIT_TIME = 0.05
@pytest.mark.skip(reason="Unhandled problem with mockito 5") def test_simple_case(japc, japc_mock, japc_set):
def test_simple_case(japc, japc_mock):
param_name = 'TEST/TestProperty' param_name = 'TEST/TestProperty'
param = japc_mock.mockParameter(param_name) param = japc_mock.mockParameter(param_name)
japc_mock.whenGetValueThen( japc_mock.whenGetValueThen(
...@@ -18,7 +16,7 @@ def test_simple_case(japc, japc_mock): ...@@ -18,7 +16,7 @@ def test_simple_case(japc, japc_mock):
japc.getNextParamValue(param_name, timeout=0.25) japc.getNextParamValue(param_name, timeout=0.25)
def set_value(): 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() threading.Timer(WAIT_TIME, set_value).start()
result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST") result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST")
...@@ -30,19 +28,18 @@ def test_simple_case(japc, japc_mock): ...@@ -30,19 +28,18 @@ def test_simple_case(japc, japc_mock):
assert 'isFirstUpdate' in result[1] assert 'isFirstUpdate' in result[1]
@pytest.mark.skip(reason="Unhandled problem with mockito 5") def test_n_values(japc, japc_mock, japc_set):
def test_n_values(japc, japc_mock):
param_name = 'TEST/TestProperty' param_name = 'TEST/TestProperty'
param = japc_mock.mockParameter(param_name) param = japc_mock.mockParameter(param_name)
japc_mock.whenGetValueThen( japc_mock.whenGetValueThen(
param, japc_mock.sel('LHC.USER.TEST'), japc_mock.acqVal(param_name, 42, 0)) param, japc_mock.sel('LHC.USER.TEST'), japc_mock.acqVal(param_name, 42, 0))
def set_several_values(): 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) 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) 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() threading.Timer(WAIT_TIME, set_several_values).start()
result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST", n_values=3) result = japc.getNextParamValue(param_name, timeout=1, timingSelectorOverride="LHC.USER.TEST", n_values=3)
......
...@@ -2,13 +2,10 @@ import logging ...@@ -2,13 +2,10 @@ import logging
import time import time
from unittest import mock from unittest import mock
import pytest
SMALL_WAIT = 0.1 SMALL_WAIT = 0.1
@pytest.mark.xfail(reason="Unhandled problem with mockito 5") def test_subscription_integration(japc, japc_mock, japc_set):
def test_subscription_integration(japc, japc_mock):
param_name = "TEST/TestProperty" param_name = "TEST/TestProperty"
param = japc_mock.mockParameter(param_name) param = japc_mock.mockParameter(param_name)
japc_mock.whenGetValueThen( japc_mock.whenGetValueThen(
...@@ -36,7 +33,7 @@ def test_subscription_integration(japc, japc_mock): ...@@ -36,7 +33,7 @@ def test_subscription_integration(japc, japc_mock):
callback.reset_mock() callback.reset_mock()
# Check that a new value is sent. # 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) time.sleep(SMALL_WAIT)
assert callback.call_args[0][:2] == (param_name, 112) assert callback.call_args[0][:2] == (param_name, 112)
assert callback.call_args[0][2]['isFirstUpdate'] is False assert callback.call_args[0][2]['isFirstUpdate'] is False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment