Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
python-handel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bliss
python-handel
Commits
8aca7ef4
Commit
8aca7ef4
authored
Feb 07, 2019
by
Cyril Guilloud
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'handel-bump' into 'master'
Update to handel >= 1.2.19 See merge request
!1
parents
77f71098
3c2a5430
Pipeline
#8321
passed with stages
in 1 minute and 45 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
69 deletions
+91
-69
handel/_cffi.py
handel/_cffi.py
+2
-1
handel/interface.py
handel/interface.py
+13
-19
tests/conftest.py
tests/conftest.py
+46
-0
tests/test_gevent.py
tests/test_gevent.py
+13
-17
tests/test_interface.py
tests/test_interface.py
+17
-32
No files found.
handel/_cffi.py
View file @
8aca7ef4
"""CFFI binding."""
import
os
import
cffi
ffi
=
cffi
.
FFI
()
...
...
@@ -48,4 +49,4 @@ int xiaSetLogOutput(char *fileName);
void xiaGetVersionInfo(int *rel, int *min, int *maj, char *pretty);
"""
)
handel
=
ffi
.
dlopen
(
"handel.dll"
)
handel
=
ffi
.
dlopen
(
'handel.dll'
if
os
.
name
==
'nt'
else
'libhandel.so'
)
handel/interface.py
View file @
8aca7ef4
...
...
@@ -3,6 +3,7 @@
from
__future__
import
absolute_import
import
os
import
warnings
from
functools
import
reduce
import
numpy
...
...
@@ -37,8 +38,8 @@ __all__ = ['init', 'init_handel', 'exit',
'get_master_channels'
,
'get_trigger_channels'
,
'set_acquisition_value'
,
'get_acquisition_value'
,
'remove_acquisition_value'
,
'apply_acquisition_values'
,
'get_handel_version'
,
'
get_config_files'
,
'get_config
'
]
'get_handel_version'
,
'get_config_files'
,
'get_config'
,
'
HandelError
'
]
MAX_STRING_LENGTH
=
80
...
...
@@ -184,14 +185,6 @@ def is_running():
def
get_module_statistics
(
module
):
channels
=
get_module_channels
(
module
)
# FalconX requires a spectrum read for the statistics to be updated
if
get_module_type
(
module
).
startswith
(
u'falconx'
):
for
channel
in
channels
:
if
channel
>=
0
:
try
:
get_spectrum
(
channel
)
except
HandelError
:
pass
# Prepare buffer
data_size
=
9
*
len
(
channels
)
master
=
next
(
c
for
c
in
channels
if
c
>=
0
)
...
...
@@ -341,7 +334,7 @@ def get_all_buffer_data(buffer_id):
return
merge_buffer_data
(
*
data
)
def
synchronized_poll_data
(
done
=
set
()
):
def
synchronized_poll_data
():
"""Convenient helper for buffer management in mapping mode.
It assumes that all the modules are configured with the same number
...
...
@@ -369,14 +362,6 @@ def synchronized_poll_data(done=set()):
# Overrun from hardware
if
any_buffer_overrun
():
raise
overrun_error
# FalconX hack
# The buffer_done command does not reset the full flag.
# It's only reset when the buffer starts being filled up again.
# For this reason, we need to remember full flags from the previous call.
# This is exactly what the done set does.
done
&=
full
# Reset done flags
full
-=
done
# Don't read twice
done
|=
full
# Set done flags
# Read data from buffers
for
x
in
full
:
data
[
x
]
=
get_all_buffer_data
(
x
)
...
...
@@ -697,3 +682,12 @@ def get_config(*path):
filename
=
os
.
path
.
join
(
*
path
)
with
open
(
filename
)
as
f
:
return
parse_xia_ini_file
(
f
.
read
())
# Check version at import time
if
get_handel_version
()
<
(
1
,
2
,
19
):
warnings
.
warn
(
"""
\
The current handel version is older than 1.2.19.
This might cause bugs, especially with the FalconX.
Please consider upgrading to a more recent version."""
)
tests/conftest.py
0 → 100644
View file @
8aca7ef4
import
mock
import
pytest
@
pytest
.
fixture
(
scope
=
'session'
)
def
interface_import
():
with
mock
.
patch
(
'cffi.FFI.dlopen'
)
as
dlopen
:
with
mock
.
patch
(
'os.name'
,
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
)
# Remove mock
del
dlopen
.
return_value
.
xiaGetVersionInfo
# Work around for https://bugs.python.org/issue31177
dlopen
.
return_value
.
_mock_children
.
clear
()
# Check dlopen
dlopen
.
assert_called_once_with
(
'handel.dll'
)
assert
interface
.
handel
==
dlopen
.
return_value
yield
interface
@
pytest
.
fixture
def
interface
(
interface_import
):
with
mock
.
patch
(
'handel.interface.check_error'
):
try
:
# Reset mock
handel
=
interface_import
.
handel
handel
.
reset_mock
()
yield
interface_import
finally
:
# Revert gevent patch
interface_import
.
handel
=
handel
tests/test_gevent.py
View file @
8aca7ef4
import
mock
def
test_gevent_compatibility
(
interface
):
# Declare xiaSomeFunction
handel
=
interface
.
handel
original
=
handel
.
xiaSomeFunction
original
.
__name__
=
'xiaSomeFunction'
original
.
return_value
=
'Some result'
def
test_gevent_compatibility
():
with
mock
.
patch
(
'cffi.FFI.dlopen'
)
as
dlopen
:
# Declare xiaSomeFunction
handel
=
dlopen
.
return_value
original
=
handel
.
xiaSomeFunction
original
.
__name__
=
'xiaSomeFunction'
original
.
return_value
=
'Some result'
# Patching
from
handel.gevent
import
patch
assert
patch
()
is
None
# Patching
from
handel.gevent
import
patch
from
handel
import
interface
assert
patch
()
is
None
# Checking
assert
interface
.
handel
.
xiaSomeFunction
.
__name__
==
'xiaSomeFunction'
assert
interface
.
handel
.
xiaSomeFunction
(
1
,
a
=
2
)
is
'Some result'
original
.
assert_called_once_with
(
1
,
a
=
2
)
# Checking
assert
interface
.
handel
.
xiaSomeFunction
.
__name__
==
'xiaSomeFunction'
assert
interface
.
handel
.
xiaSomeFunction
(
1
,
a
=
2
)
is
'Some result'
original
.
assert_called_once_with
(
1
,
a
=
2
)
tests/test_interface.py
View file @
8aca7ef4
...
...
@@ -3,16 +3,6 @@ import numpy
import
pytest
from
handel.stats
import
Stats
from
handel.error
import
HandelError
@
pytest
.
fixture
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,28 +300,23 @@ 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
m2
.
assert_called_once_with
(
'module3'
)
arg
=
m
.
call_args
[
0
][
2
]
m
.
assert_called_once_with
(
8
,
b'module_statistics_2'
,
arg
)
m4
.
assert_called_once_with
(
8
)
# Second test
raw
[
5
]
=
4.56
# ICR inconsistency
raw
[
6
]
=
1.23
# OCR inconsistency
with
pytest
.
warns
(
UserWarning
)
as
ctx
:
interface
.
get_module_statistics
(
'module3'
)
assert
ctx
[
0
].
message
.
args
[
0
].
startswith
(
'ICR buffer inconsistency: 4.56 != 3131.7208'
)
assert
ctx
[
1
].
message
.
args
[
0
].
startswith
(
'OCR buffer inconsistency: 1.23 != 2724.3282'
)
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_2'
,
arg
)
# Second test
raw
[
5
]
=
4.56
# ICR inconsistency
raw
[
6
]
=
1.23
# OCR inconsistency
with
pytest
.
warns
(
UserWarning
)
as
ctx
:
interface
.
get_module_statistics
(
'module3'
)
assert
ctx
[
0
].
message
.
args
[
0
].
startswith
(
'ICR buffer inconsistency: 4.56 != 3131.7208'
)
assert
ctx
[
1
].
message
.
args
[
0
].
startswith
(
'OCR buffer inconsistency: 1.23 != 2724.3282'
)
# Make sure errors have been checked
interface
.
check_error
.
assert_called_with
(
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment