Commit a238c42b authored by Vincent Michel's avatar Vincent Michel
Browse files

Update tests

parent 8bc71c3d
Pipeline #4053 failed with stage
in 1 minute and 35 seconds
import mock
import pytest
def interface_import():
with mock.patch('cffi.FFI.dlopen') as dlopen:
with mock.patch('', new='nt'):
# Set up get version info to trigger a warning
m = dlopen.return_value.xiaGetVersionInfo
def side_effect(a, b, c, d):
# v1.2.18 is too old!
d[0], c[0], b[0], a[0] = b'v', 1, 2, 18
m.side_effect = side_effect
# Perform the import only once
with pytest.warns(UserWarning) as record:
from handel import interface
assert len(record) == 1
assert "older than 1.2.19" in str(record[0].message)
assert interface.handel == dlopen.return_value
yield interface
def interface(interface_import):
with mock.patch('handel.interface.check_error'):
# Reset mock
handel = interface_import.handel
yield interface_import
# Revert gevent patch
interface_import.handel = handel
import mock
def test_gevent_compatibility():
with mock.patch('cffi.FFI.dlopen') as dlopen:
def test_gevent_compatibility(interface):
# Declare xiaSomeFunction
handel = dlopen.return_value
handel = interface.handel
original = handel.xiaSomeFunction
original.__name__ = 'xiaSomeFunction'
original.return_value = 'Some result'
# Patching
from handel.gevent import patch
from handel import interface
assert patch() is None
# Checking
......@@ -3,16 +3,6 @@ import numpy
import pytest
from handel.stats import Stats
from handel.error import HandelError
def interface():
with mock.patch('cffi.FFI.dlopen') as dlopen:
with mock.patch('handel.interface.check_error'):
from handel import interface
interface.handel = dlopen.return_value
yield interface
# Initializing handel
......@@ -310,18 +300,13 @@ def test_get_module_statistics(interface):
m.side_effect = side_effect
with mock.patch('handel.interface.get_module_channels') as m2:
with mock.patch('handel.interface.get_module_type') as m3:
with mock.patch('handel.interface.get_spectrum') as m4:
m2.return_value = [-1, -1, -1, 8]
m3.return_value = u'falconxn'
m4.side_effect = HandelError(12, 'hello')
# First test
assert interface.get_module_statistics('module3') == expected
arg = m.call_args[0][2]
m.assert_called_once_with(8, b'module_statistics_2', arg)
# Second test
raw[5] = 4.56 # ICR inconsistency
Supports Markdown
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