Commit ff329ed5 authored by Vincent Michel's avatar Vincent Michel

Alias argument is now optional in get_module_type

parent 268b2037
Pipeline #1083 passed with stages
in 1 minute and 18 seconds
......@@ -474,7 +474,18 @@ def get_module_from_channel(channel):
return ffi.string(alias).decode()
def get_module_type(alias):
def get_module_type(alias=None):
if alias is None:
# Get all the values
values = [get_module_type(alias) for alias in get_modules()]
# Compare the values
value = reduce(lambda c, x: c if c == x else None, values)
# Inconsistency
if value is None:
raise ValueError(
'The module type differs from module to module')
# Return
return value
alias = to_bytes(alias)
value = ffi.new('char []', MAX_STRING_LENGTH)
code = handel.xiaGetModuleItem(alias, b'module_type', value)
......
......@@ -467,6 +467,7 @@ def test_set_maximum_pixels_per_buffer(interface):
(('num_map_pixels_per_buffer', 7),)]
m3.assert_called_once_with()
def test_any_buffer_overrun(interface):
with mock.patch('handel.interface.get_master_channels') as m1:
with mock.patch('handel.interface.is_buffer_overrun') as m2:
......@@ -782,6 +783,36 @@ def test_get_module_type(interface):
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
# All channels
m.reset_mock()
interface.check_error.reset_mock()
with mock.patch('handel.interface.get_modules') as m2:
m2.return_value = ['module1', 'module2']
assert interface.get_module_type() == 'mercury'
arg = m.call_args[0][2]
m.assert_called_with(b'module2', b'module_type', arg)
m2.assert_called_once_with()
# Make sure errors have been checked
interface.check_error.assert_called_with(0)
def side_effect(a, b, c):
c[0:7] = b'mercury' if a == b'module1' else b'xmap\x00\x00\x00'
return 0
# All channels with error
m.reset_mock()
interface.check_error.reset_mock()
m.side_effect = side_effect
with mock.patch('handel.interface.get_modules') as m2:
m2.return_value = ['module1', 'module2']
with pytest.raises(ValueError):
interface.get_module_type()
arg = m.call_args[0][2]
m.assert_called_with(b'module2', b'module_type', arg)
m2.assert_called_once_with()
# Make sure errors have been checked
interface.check_error.assert_called_with(0)
def test_get_module_interface(interface):
m = interface.handel.xiaGetModuleItem
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment