Commit d5ba354d authored by Samuel GAIST's avatar Samuel GAIST

[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
......@@ -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)
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