comparison planemo/lib/python3.7/site-packages/cwltool/tests/test_udocker.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 import pytest
2 import sys
3 import os
4 import subprocess
5 from .util import get_data, get_main_output
6 import tempfile
7 import shutil
8 from psutil.tests import TRAVIS
9
10 LINUX = sys.platform in ('linux', 'linux2')
11
12
13 #@pytest.mark.skipif(not LINUX, reason="LINUX only")
14 @pytest.mark.skip("Udocker install is broken, see https://github.com/indigo-dc/udocker/issues/221")
15 class TestUdocker:
16 udocker_path = None
17
18 @classmethod
19 def setup_class(cls):
20 test_cwd = os.getcwd()
21 test_environ = os.environ.copy()
22 cls.docker_install_dir = tempfile.mkdtemp()
23 os.chdir(cls.docker_install_dir)
24
25 url="https://download.ncg.ingrid.pt/webdav/udocker/udocker-1.1.3.tar.gz"
26 install_cmds = [
27 ["curl", url, "-o", "./udocker-tarball.tgz"],
28 ["tar", "xzvf", "udocker-tarball.tgz", "udocker"],
29 ["bash", "-c", "UDOCKER_TARBALL={}/udocker-tarball.tgz ./udocker install".format(cls.docker_install_dir)]]
30
31 os.environ['UDOCKER_DIR'] = os.path.join(cls.docker_install_dir, ".udocker")
32 os.environ['HOME'] = cls.docker_install_dir
33
34 results = []
35 for _ in range(3):
36 results = [subprocess.call(cmds) for cmds in install_cmds]
37 if sum(results) == 0:
38 break
39 subprocess.call(["rm", "./udocker"])
40
41 assert sum(results) == 0
42
43 cls.udocker_path = os.path.join(cls.docker_install_dir, 'udocker')
44 os.chdir(test_cwd)
45 os.environ = test_environ
46 print('Udocker install dir: ' + cls.docker_install_dir)
47
48 @classmethod
49 def teardown_class(cls):
50 shutil.rmtree(cls.docker_install_dir)
51
52 def test_udocker_usage_should_not_write_cid_file(self, tmpdir):
53 cwd = tmpdir.chdir()
54
55 test_file = "tests/wf/wc-tool.cwl"
56 job_file = "tests/wf/wc-job.json"
57 error_code, stdout, stderr = get_main_output(
58 ["--debug", "--default-container", "debian", "--user-space-docker-cmd=" + self.udocker_path,
59 get_data(test_file), get_data(job_file)])
60 cwd.chdir()
61 cidfiles_count = sum(1 for _ in tmpdir.visit(fil="*.cid"))
62
63 tmpdir.remove(ignore_errors=True)
64
65 assert "completed success" in stderr, stderr
66 assert cidfiles_count == 0
67
68 @pytest.mark.skipif(TRAVIS, reason='Not reliable on single threaded test on travis.')
69 def test_udocker_should_display_memory_usage(self, tmpdir):
70 cwd = tmpdir.chdir()
71 error_code, stdout, stderr = get_main_output(
72 ["--enable-ext", "--default-container=debian", "--user-space-docker-cmd=" + self.udocker_path,
73 get_data("tests/wf/timelimit.cwl"), "--sleep_time", "10"])
74 cwd.chdir()
75 tmpdir.remove(ignore_errors=True)
76
77 assert "completed success" in stderr, stderr
78 assert "Max memory" in stderr, stderr