Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.core
Commits
d5ba354d
Commit
d5ba354d
authored
Oct 08, 2019
by
Samuel GAIST
Browse files
[test][execution] Move conda related helper out of class
That will make them re-usable in other tests like in beat/beat.cmdline>
parent
9c25d8b1
Pipeline
#34151
passed with stage
in 54 minutes and 53 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/core/test/test_execution.py
View file @
d5ba354d
...
...
@@ -58,6 +58,39 @@ from .utils import slow
logger
=
logging
.
getLogger
(
__name__
)
# ----------------------------------------------------------
# Helpers
def
create_conda_environment
(
additional_packages
=
[]):
environment_name
=
"subprocess_environment"
environment_prefix
=
os
.
path
.
join
(
tmp_prefix
,
environment_name
)
packages
=
[
"python=3"
]
+
additional_packages
sp
.
run
(
[
"conda"
,
"create"
,
"-y"
,
"-c"
,
"defaults"
,
"-c"
,
"http://www.idiap.ch/software/bob/conda/"
,
"--prefix"
,
environment_prefix
,
]
+
packages
,
check
=
True
,
stdout
=
sp
.
PIPE
,
stderr
=
sp
.
PIPE
,
)
return
environment_prefix
def
clear_conda_environment
(
environment_prefix
):
rmtree
(
environment_prefix
)
# ----------------------------------------------------------
...
...
@@ -463,35 +496,9 @@ class TestSubprocessExecution(BaseExecutionMixIn):
result
[
"user_error"
],
"'Could not setup algorithm (returned False)'"
)
def
create_conda_environment
(
self
,
additional_packages
=
[]):
environment_name
=
"subprocess_environment"
environment_prefix
=
os
.
path
.
join
(
tmp_prefix
,
environment_name
)
packages
=
[
"python=3"
]
+
additional_packages
sp
.
run
(
[
"conda"
,
"create"
,
"-y"
,
"-c"
,
"defaults"
,
"-c"
,
"http://www.idiap.ch/software/bob/conda/"
,
"--prefix"
,
environment_prefix
,
]
+
packages
,
check
=
True
,
stdout
=
sp
.
PIPE
,
stderr
=
sp
.
PIPE
,
)
return
environment_prefix
def
clear_conda_environment
(
self
,
environment_prefix
):
rmtree
(
environment_prefix
)
@
slow
def
test_different_environment
(
self
):
environment_prefix
=
self
.
create_conda_environment
([
"beat.backend.python"
])
environment_prefix
=
create_conda_environment
([
"beat.backend.python"
])
result
=
self
.
execute
(
"user/user/loop/1/loop"
,
[{
"sum"
:
135
,
"nb"
:
9
},
{
"sum"
:
9
,
"nb"
:
9
}],
...
...
@@ -499,13 +506,13 @@ class TestSubprocessExecution(BaseExecutionMixIn):
"python_path"
:
os
.
path
.
join
(
environment_prefix
,
"bin"
,
"python"
)
},
)
self
.
clear_conda_environment
(
environment_prefix
)
clear_conda_environment
(
environment_prefix
)
nose
.
tools
.
assert_is_none
(
result
)
@
slow
def
test_wrong_different_environment
(
self
):
environment_prefix
=
self
.
create_conda_environment
()
environment_prefix
=
create_conda_environment
()
with
nose
.
tools
.
assert_raises
(
RuntimeError
):
self
.
execute
(
"user/user/loop/1/loop"
,
...
...
@@ -514,4 +521,4 @@ class TestSubprocessExecution(BaseExecutionMixIn):
"python_path"
:
os
.
path
.
join
(
environment_prefix
,
"bin"
,
"python"
)
},
)
self
.
clear_conda_environment
(
environment_prefix
)
clear_conda_environment
(
environment_prefix
)
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