Commit 0f2204e8 authored by Vincent Michel's avatar Vincent Michel

Update tests

parent fa6ac155
Pipeline #801 passed with stages
in 1 minute and 16 seconds
import pytest
from handel.error import HandelError, check_return_value
@check_return_value
def f(x):
return x
from handel.error import HandelError, check_error
def test_no_error():
assert f(0) is None
assert check_error(0) is None
def test_known_error():
with pytest.raises(HandelError) as context:
f(801)
check_error(801)
assert str(context.value) == '[HandelError 801] UNIT_TEST'
def test_known_error_with_description():
with pytest.raises(HandelError) as context:
f(404)
check_error(404)
assert str(context.value) == '[HandelError 404] EOF: EOF encountered'
def test_unknown_error():
with pytest.raises(HandelError) as context:
f(802)
check_error(802)
assert str(context.value) == '[HandelError 802] UNKNOWN_ERROR_CODE'
......@@ -6,9 +6,10 @@ import mock
@pytest.fixture
def interface():
with mock.patch('cffi.FFI.dlopen') as dlopen:
from handel import interface
interface.handel = dlopen.return_value
yield interface
with mock.patch('handel.interface.check_error'):
from handel import interface
interface.handel = dlopen.return_value
yield interface
# Initializing handel
......@@ -18,10 +19,16 @@ def test_init(interface):
m.return_value = 0
assert interface.init('somefile') is None
m.assert_called_once_with(b'somefile')
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
# Reset
m.reset_mock()
interface.check_error.reset_mock()
# Should work with bytes too
assert interface.init(b'somefile') is None
m.assert_called_once_with(b'somefile')
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
def test_init_handel(interface):
......@@ -29,6 +36,8 @@ def test_init_handel(interface):
m.return_value = 0
assert interface.init_handel() is None
m.assert_called_once_with()
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
def test_exit(interface):
......@@ -36,6 +45,8 @@ def test_exit(interface):
m.return_value = 0
assert interface.exit() is None
m.assert_called_once_with()
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
# Detectors
......@@ -45,6 +56,8 @@ def test_new_detector(interface):
m.return_value = 0
assert interface.new_detector('somealias') is None
m.assert_called_once_with(b'somealias')
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
def test_get_num_detectors(interface):
......@@ -59,6 +72,8 @@ def test_get_num_detectors(interface):
m.assert_called_once()
arg = m.call_args[0][0]
m.assert_called_once_with(arg)
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
def test_get_detectors(interface):
......@@ -82,6 +97,8 @@ def test_get_detectors(interface):
m2.assert_called_once()
arg = m2.call_args[0][0]
m2.assert_called_once_with(arg)
# Make sure errors have been checked
interface.check_error.assert_called_with(0)
# Run control
......@@ -89,21 +106,36 @@ def test_get_detectors(interface):
def test_start_run(interface):
m = interface.handel.xiaStartRun
m.return_value = 0
# First test
assert interface.start_run(1) is None
m.assert_called_once_with(1, False)
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
# Reset
m.reset_mock()
interface.check_error.reset_mock()
# Second test
assert interface.start_run(2, True) is None
m.assert_called_once_with(2, True)
# Make sure errors have been checked
interface.check_error.assert_called_once_with(0)
def test_stop_run(interface):
# Init
m = interface.handel.xiaStopRun
m.return_value = 0
# First test
assert interface.stop_run(1) is None
m.assert_called_once_with(1)
interface.check_error.assert_called_once_with(0)
# Reset
m.reset_mock()
interface.check_error.reset_mock()
# Second test
assert interface.stop_run(2) is None
m.assert_called_once_with(2)
interface.check_error.assert_called_once_with(0)
def test_get_run_data_length(interface):
......@@ -118,6 +150,7 @@ def test_get_run_data_length(interface):
m.assert_called_once()
arg = m.call_args[0][2]
m.assert_called_once_with(1, 'mca_length', arg)
interface.check_error.assert_called_once_with(0)
def test_get_run_data(interface):
......@@ -140,6 +173,7 @@ def test_get_run_data(interface):
m.assert_called()
arg = m.call_args[0][2]
m.assert_called_with(1, 'mca', arg)
interface.check_error.assert_called_with(0)
# System
......@@ -149,6 +183,7 @@ def test_load_system(interface):
m.return_value = 0
assert interface.load_system('somefile') is None
m.assert_called_once_with(b'handel_ini', b'somefile')
interface.check_error.assert_called_once_with(0)
def test_save_system(interface):
......@@ -156,6 +191,7 @@ def test_save_system(interface):
m.return_value = 0
assert interface.save_system('somefile') is None
m.assert_called_once_with(b'handel_ini', b'somefile')
interface.check_error.assert_called_once_with(0)
def test_start_system(interface):
......@@ -163,6 +199,7 @@ def test_start_system(interface):
m.return_value = 0
assert interface.start_system() is None
m.assert_called_once_with()
interface.check_error.assert_called_once_with(0)
# Logging
......@@ -172,6 +209,7 @@ def test_enable_log_output(interface):
m.return_value = 0
assert interface.enable_log_output() is None
m.assert_called_once_with()
interface.check_error.assert_called_once_with(0)
def test_disable_log_output(interface):
......@@ -179,6 +217,7 @@ def test_disable_log_output(interface):
m.return_value = 0
assert interface.disable_log_output() is None
m.assert_called_once_with()
interface.check_error.assert_called_once_with(0)
def test_set_log_level(interface):
......@@ -186,6 +225,7 @@ def test_set_log_level(interface):
m.return_value = 0
assert interface.set_log_level(3) is None
m.assert_called_once_with(3)
interface.check_error.assert_called_once_with(0)
def test_set_log_output(interface):
......@@ -193,6 +233,7 @@ def test_set_log_output(interface):
m.return_value = 0
assert interface.set_log_output('somefile') is None
m.assert_called_once_with(b'somefile')
interface.check_error.assert_called_once_with(0)
def test_close_log(interface):
......@@ -200,6 +241,7 @@ def test_close_log(interface):
m.return_value = 0
assert interface.close_log() is None
m.assert_called_once_with()
interface.check_error.assert_called_once_with(0)
# Parameters
......@@ -211,6 +253,7 @@ def test_set_acquisition_value(interface):
arg = m.call_args[0][2]
m.assert_called_once_with(1, b'test', arg)
assert arg[0] == 2.3
interface.check_error.assert_called_once_with(0)
def test_get_acquistion_value(interface):
......@@ -224,6 +267,7 @@ def test_get_acquistion_value(interface):
assert interface.get_acquisition_value(1, 'test') == 2.3
arg = m.call_args[0][2]
m.assert_called_once_with(1, b'test', arg)
interface.check_error.assert_called_once_with(0)
# Debugging
......
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