Commit 55be87d5 authored by Vincent Michel's avatar Vincent Michel

Update tests and fix deadtime

parent 720d6bca
Pipeline #993 passed with stages
in 1 minute and 18 seconds
......@@ -59,7 +59,8 @@ def stats_from_buffer(array):
# Deadtime computation
# It's unclear whether icr=ocr=0 should result in a 0.0 or 1.0 deadtime
deadtime = 1 - float(ocr) / icr if icr != 0 else 1.
# Prospect uses 0% so 0. it is.
deadtime = 1 - float(ocr) / icr if icr != 0 else 0.
return Stats(realtime, livetime, triggers, events, icr, ocr, deadtime)
......
......@@ -224,7 +224,6 @@ def test_get_spectrums(interface):
m2.assert_called_with(1)
def test_is_channel_running(interface):
# First test
m = interface.handel.xiaGetRunData
......@@ -256,7 +255,6 @@ def test_is_channel_running(interface):
interface.check_error.assert_called_once_with(0)
def test_is_running(interface):
with mock.patch('handel.interface.get_channels') as m1:
with mock.patch('handel.interface.is_channel_running') as m2:
......@@ -277,16 +275,18 @@ def test_get_module_statistics(interface):
m = interface.handel.xiaGetRunData
def side_effect(channel, dtype, arg):
arg[3*7:4*7] = [
1.00758784,
0.98603936,
255.,
3088.,
2742.,
3131.,
2721.]
arg[3*7:4*7] = raw
return 0
raw = [
1.00758784,
0.98603936,
255.,
3088.,
2742.,
3131.,
2721.]
expected = {8: interface.Stats(
1.00758784,
0.98603936,
......@@ -299,10 +299,25 @@ def test_get_module_statistics(interface):
m.side_effect = side_effect
with mock.patch('handel.interface.get_module_channels') as m2:
m2.return_value = [-1, -1, -1, 8]
# First test
assert interface.get_module_statistics('module3') == expected
m2.assert_called_once_with('module3')
arg = m.call_args[0][2]
m.assert_called_once_with(8, b'module_statistics', arg)
# Second test
raw[6] = 1.23 # OCR inconsistency
with pytest.raises(ValueError) as ctx:
interface.get_module_statistics('module3')
assert 'OCR' in str(ctx.value)
assert '1.23' in str(ctx.value)
assert '2721.3508' in str(ctx.value)
# Second test
raw[5] = 4.56 # ICR inconsistency
with pytest.raises(ValueError) as ctx:
interface.get_module_statistics('module3')
assert 'ICR' in str(ctx.value)
assert '4.56' in str(ctx.value)
assert '3131.7208' in str(ctx.value)
# Make sure errors have been checked
interface.check_error.assert_called_with(0)
......@@ -312,7 +327,6 @@ def test_get_statistics(interface):
with mock.patch('handel.interface.get_modules') as m1:
with mock.patch('handel.interface.get_module_statistics') as m2:
m1.return_value = ['module1', 'module2']
# First test
stats = {'module1': {0: 'some', 1: 'stats'},
'module2': {2: 'and', 3: 'some more'}}
m2.side_effect = lambda x: stats[x]
......
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