Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
python-handel
Commits
7cbc63e8
Commit
7cbc63e8
authored
Sep 26, 2017
by
Vincent Michel
Browse files
Channel argument is now optional for get_acquisition value
parent
7977894f
Pipeline
#1080
passed with stages
in 1 minute and 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
handel/interface.py
View file @
7cbc63e8
...
...
@@ -3,6 +3,7 @@
from
__future__
import
absolute_import
import
os
from
functools
import
reduce
import
numpy
...
...
@@ -544,7 +545,21 @@ def get_master_channels():
# Parameters
def
get_acquisition_value
(
name
,
channel
):
def
get_acquisition_value
(
name
,
channel
=
None
):
# Get values for all channels
if
channel
is
None
:
# Get all the values
values
=
[
get_acquisition_value
(
name
,
channel
)
for
channel
in
get_channels
()]
# Compare the values
value
=
reduce
(
lambda
c
,
x
:
c
if
c
==
x
else
None
,
values
)
# Inconsistency
if
value
is
None
:
raise
ValueError
(
'The acquisition value differs from channel to channel'
)
# Return
return
value
# Get value for a single channel
name
=
to_bytes
(
name
)
pointer
=
ffi
.
new
(
'double *'
)
code
=
handel
.
xiaGetAcquisitionValues
(
channel
,
name
,
pointer
)
...
...
@@ -573,8 +588,7 @@ def apply_acquisition_values(channel=None):
# Apply all
if
channel
is
None
:
# Only one apply operation by module is required
grouped
=
get_grouped_channels
()
for
master
in
map
(
max
,
grouped
):
for
master
in
get_master_channels
():
apply_acquisition_values
(
master
)
return
# Apply single
...
...
tests/test_interface.py
View file @
7cbc63e8
...
...
@@ -895,6 +895,7 @@ def test_get_acquistion_value(interface):
c
[
0
]
=
2.3
return
0
# Single channel
m
.
side_effect
=
side_effect
assert
interface
.
get_acquisition_value
(
'test'
,
channel
=
1
)
==
2.3
arg
=
m
.
call_args
[
0
][
2
]
...
...
@@ -902,6 +903,36 @@ def test_get_acquistion_value(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_channels'
)
as
m2
:
m2
.
return_value
=
[
0
,
1
,
2
]
assert
interface
.
get_acquisition_value
(
'test'
)
==
2.3
arg
=
m
.
call_args
[
0
][
2
]
m
.
assert_called_with
(
2
,
b
'test'
,
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
]
=
a
# Channel number
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_channels'
)
as
m2
:
m2
.
return_value
=
[
0
,
1
,
2
]
with
pytest
.
raises
(
ValueError
):
interface
.
get_acquisition_value
(
'test'
)
arg
=
m
.
call_args
[
0
][
2
]
m
.
assert_called_with
(
2
,
b
'test'
,
arg
)
m2
.
assert_called_once_with
()
# Make sure errors have been checked
interface
.
check_error
.
assert_called_with
(
0
)
def
test_set_acquisition_value
(
interface
):
m
=
interface
.
handel
.
xiaSetAcquisitionValues
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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