Skip to content

Commit c4efcc8

Browse files
committed
maintenance: remove unittest from test_js_sandbox
1 parent 7ade479 commit c4efcc8

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

tests/test_js_sandbox.py

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,41 @@
1-
from __future__ import absolute_import
2-
3-
import unittest
4-
51
import pytest
6-
from mock import Mock, patch
72

8-
import cwltool
9-
import cwltool.factory
10-
import cwltool.sandboxjs
11-
# we should modify the subprocess imported from cwltool.sandboxjs
12-
from cwltool.sandboxjs import (check_js_threshold_version, exec_js_process,
13-
subprocess)
3+
from cwltool import sandboxjs
144
from cwltool.utils import onWindows
155

166
from .util import get_data, get_windows_safe_factory, windows_needs_docker
177

188

19-
class Javascript_Sanity_Checks(unittest.TestCase):
20-
21-
def setUp(self):
22-
self.check_output = subprocess.check_output
23-
24-
def tearDown(self):
25-
subprocess.check_output = self.check_output
26-
27-
def test_node_version(self):
28-
subprocess.check_output = Mock(return_value=b'v0.8.26\n')
29-
self.assertEquals(check_js_threshold_version('node'), False)
30-
31-
subprocess.check_output = Mock(return_value=b'v0.10.25\n')
32-
self.assertEquals(check_js_threshold_version('node'), False)
33-
34-
subprocess.check_output = Mock(return_value=b'v0.10.26\n')
35-
self.assertEquals(check_js_threshold_version('node'), True)
36-
37-
subprocess.check_output = Mock(return_value=b'v4.4.2\n')
38-
self.assertEquals(check_js_threshold_version('node'), True)
9+
node_versions = [
10+
(b'v0.8.26\n', False),
11+
(b'v0.10.25\n', False),
3912

40-
subprocess.check_output = Mock(return_value=b'v7.7.3\n')
41-
self.assertEquals(check_js_threshold_version('node'), True)
13+
(b'v0.10.26\n', True),
14+
(b'v4.4.2\n', True),
15+
(b'v7.7.3\n', True)
16+
]
4217

43-
def test_is_javascript_installed(self):
44-
pass
18+
@pytest.mark.parametrize('version,supported', node_versions)
19+
def test_node_version(version, supported, mocker):
20+
mocked_subprocess = mocker.patch("cwltool.sandboxjs.subprocess")
21+
mocked_subprocess.check_output = mocker.Mock(return_value=version)
4522

23+
assert sandboxjs.check_js_threshold_version('node') == supported
4624

47-
class TestValueFrom(unittest.TestCase):
25+
@windows_needs_docker
26+
def test_value_from_two_concatenated_expressions():
27+
factory = get_windows_safe_factory()
28+
echo = factory.make(get_data("tests/wf/vf-concat.cwl"))
29+
file = {"class": "File",
30+
"location": get_data("tests/wf/whale.txt")}
4831

49-
@windows_needs_docker
50-
def test_value_from_two_concatenated_expressions(self):
51-
f = get_windows_safe_factory()
52-
echo = f.make(get_data("tests/wf/vf-concat.cwl"))
53-
self.assertEqual(echo(file1={
54-
"class": "File",
55-
"location": get_data("tests/wf/whale.txt")}),
56-
{u"out": u"a string\n"})
32+
assert echo(file1=file) == {u"out": u"a string\n"}
5733

34+
@pytest.mark.skipif(onWindows(), reason="Caching processes for windows is not supported.")
35+
def test_caches_js_processes(mocker):
36+
sandboxjs.exec_js_process("7", context="{}")
5837

59-
class ExecJsProcessTest(unittest.TestCase):
60-
@pytest.mark.skipif(onWindows(),
61-
reason="Caching processes for windows is not supported.")
62-
def test_caches_js_processes(self):
63-
exec_js_process("7", context="{}")
38+
mocked_new_js_proc = mocker.patch("cwltool.sandboxjs.new_js_proc")
39+
sandboxjs.exec_js_process("7", context="{}")
6440

65-
with patch("cwltool.sandboxjs.new_js_proc", new=Mock(wraps=cwltool.sandboxjs.new_js_proc)) as mock:
66-
exec_js_process("7", context="{}")
67-
mock.assert_not_called()
41+
mocked_new_js_proc.assert_not_called()

0 commit comments

Comments
 (0)