21721: Remove ruamel.yaml dependency
[arvados.git] / sdk / python / tests / test_sdk.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import os
6 import unittest
7
8 from unittest import mock
9
10 import arvados
11 import arvados.collection
12
13 class TestSDK(unittest.TestCase):
14
15     @mock.patch('arvados.current_task')
16     @mock.patch('arvados.current_job')
17     def test_one_task_per_input_file_normalize(self, mock_job, mock_task):
18         mock_api = mock.MagicMock()
19
20         # This manifest will be reduced from three lines to one when it is
21         # normalized.
22         nonnormalized_manifest = """. 5348b82a029fd9e971a811ce1f71360b+43 0:43:md5sum.txt
23 . 085c37f02916da1cad16f93c54d899b7+41 0:41:md5sum.txt
24 . 8b22da26f9f433dea0a10e5ec66d73ba+43 0:43:md5sum.txt
25 """
26         dummy_hash = 'ffffffffffffffffffffffffffffffff+0'
27
28         mock_job.return_value = {
29             'uuid': 'none',
30             'script_parameters': {
31                 'input': dummy_hash
32             }
33         }
34         mock_task.return_value = {
35             'uuid': 'none',
36             'sequence': 0,
37         }
38         # mock the API client to return a collection with a nonnormalized manifest.
39         mock_api.collections().get().execute.return_value = {
40             'uuid': 'zzzzz-4zz18-mockcollection0',
41             'portable_data_hash': dummy_hash,
42             'manifest_text': nonnormalized_manifest,
43         }
44
45         # Because one_task_per_input_file normalizes this collection,
46         # it should now create only one job task and not three.
47         arvados.job_setup.one_task_per_input_file(and_end_task=False, api_client=mock_api)
48         mock_api.job_tasks().create().execute.assert_called_once_with()