8491: Merge branch 'master' into 8491-import-build-tools
[arvados.git] / sdk / cwl / tests / test_job.py
1 import unittest
2 import mock
3 import arvados_cwl
4
5 class TestJob(unittest.TestCase):
6
7     # The test passes no builder.resources
8     # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
9     def test_run(self):
10         runner = mock.MagicMock()
11         tool = {
12             "inputs": [],
13             "outputs": [],
14             "baseCommand": "ls"
15         }
16         arvtool = arvados_cwl.ArvadosCommandTool(runner, tool)
17         arvtool.formatgraph = None
18         for j in arvtool.job({}, "", mock.MagicMock()):
19             j.run()
20         runner.api.jobs().create.assert_called_with(body={
21             'runtime_constraints': {},
22             'script_parameters': {
23                 'tasks': [{
24                     'task.env': {'TMPDIR': '$(task.tmpdir)'},
25                     'command': ['ls']
26                 }],
27                 'crunchrunner': '83db29f08544e1c319572a6bd971088a+140/crunchrunner'
28             },
29             'script_version': 'master',
30             'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
31             'repository': 'arvados',
32             'script': 'crunchrunner',
33             'runtime_constraints': {
34                 'min_cores_per_node': 1,
35                 'min_ram_mb_per_node': 1024,
36                 'min_scratch_mb_per_node': 2048 # tmpdirSize + outdirSize
37             }
38         }, find_or_create=True)
39
40     # The test passes some fields in builder.resources
41     # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
42     def test_resource_requirements(self):
43         runner = mock.MagicMock()
44         tool = {
45             "inputs": [],
46             "outputs": [],
47             "hints": [{
48                 "class": "ResourceRequirement",
49                 "coresMin": 3,
50                 "ramMin": 3000,
51                 "tmpdirMin": 4000
52             }],
53             "baseCommand": "ls"
54         }
55         arvtool = arvados_cwl.ArvadosCommandTool(runner, tool)
56         arvtool.formatgraph = None
57         for j in arvtool.job({}, "", mock.MagicMock()):
58             j.run()
59         runner.api.jobs().create.assert_called_with(body={
60             'runtime_constraints': {},
61             'script_parameters': {
62                 'tasks': [{
63                     'task.env': {'TMPDIR': '$(task.tmpdir)'},
64                     'command': ['ls']
65                 }],
66                 'crunchrunner': '83db29f08544e1c319572a6bd971088a+140/crunchrunner'
67             },
68             'script_version': 'master',
69             'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
70             'repository': 'arvados',
71             'script': 'crunchrunner',
72             'runtime_constraints': {
73                 'min_cores_per_node': 3,
74                 'min_ram_mb_per_node': 3000,
75                 'min_scratch_mb_per_node': 5024 # tmpdirSize + outdirSize
76             }
77         }, find_or_create=True)