Commit 0cfaceab authored by Samuel GAIST's avatar Samuel GAIST

Merge branch 'test_execution_extract_helper_methods' into 'master'

Move conda related helper methods out of test class

See merge request !101
parents 9c25d8b1 d5ba354d
Pipeline #34531 passed with stage
in 22 minutes and 54 seconds
...@@ -58,6 +58,39 @@ from .utils import slow ...@@ -58,6 +58,39 @@ from .utils import slow
logger = logging.getLogger(__name__) 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): ...@@ -463,35 +496,9 @@ class TestSubprocessExecution(BaseExecutionMixIn):
result["user_error"], "'Could not setup algorithm (returned False)'" 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 @slow
def test_different_environment(self): 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( result = self.execute(
"user/user/loop/1/loop", "user/user/loop/1/loop",
[{"sum": 135, "nb": 9}, {"sum": 9, "nb": 9}], [{"sum": 135, "nb": 9}, {"sum": 9, "nb": 9}],
...@@ -499,13 +506,13 @@ class TestSubprocessExecution(BaseExecutionMixIn): ...@@ -499,13 +506,13 @@ class TestSubprocessExecution(BaseExecutionMixIn):
"python_path": os.path.join(environment_prefix, "bin", "python") "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) nose.tools.assert_is_none(result)
@slow @slow
def test_wrong_different_environment(self): def test_wrong_different_environment(self):
environment_prefix = self.create_conda_environment() environment_prefix = create_conda_environment()
with nose.tools.assert_raises(RuntimeError): with nose.tools.assert_raises(RuntimeError):
self.execute( self.execute(
"user/user/loop/1/loop", "user/user/loop/1/loop",
...@@ -514,4 +521,4 @@ class TestSubprocessExecution(BaseExecutionMixIn): ...@@ -514,4 +521,4 @@ class TestSubprocessExecution(BaseExecutionMixIn):
"python_path": os.path.join(environment_prefix, "bin", "python") "python_path": os.path.join(environment_prefix, "bin", "python")
}, },
) )
self.clear_conda_environment(environment_prefix) clear_conda_environment(environment_prefix)
Markdown is supported
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