Skip to content
GitLab
Menu
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
a238c42b
Commit
a238c42b
authored
Jul 03, 2018
by
Vincent Michel
Browse files
Update tests
parent
8bc71c3d
Pipeline
#4053
failed with stage
in 1 minute and 35 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/conftest.py
0 → 100644
View file @
a238c42b
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
)
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 @
a238c42b
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 @
a238c42b
...
...
@@ -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
Supports
Markdown
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