Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / sdk / python / tests / test_util.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import os
6 import subprocess
7 import unittest
8
9 import arvados
10
11 class MkdirDashPTest(unittest.TestCase):
12     def setUp(self):
13         try:
14             os.path.mkdir('./tmp')
15         except:
16             pass
17     def tearDown(self):
18         try:
19             os.unlink('./tmp/bar')
20             os.rmdir('./tmp/foo')
21             os.rmdir('./tmp')
22         except:
23             pass
24     def runTest(self):
25         arvados.util.mkdir_dash_p('./tmp/foo')
26         with open('./tmp/bar', 'wb') as f:
27             f.write(b'bar')
28         self.assertRaises(OSError, arvados.util.mkdir_dash_p, './tmp/bar')
29
30
31 class RunCommandTestCase(unittest.TestCase):
32     def test_success(self):
33         stdout, stderr = arvados.util.run_command(['echo', 'test'],
34                                                   stderr=subprocess.PIPE)
35         self.assertEqual("test\n".encode(), stdout)
36         self.assertEqual("".encode(), stderr)
37
38     def test_failure(self):
39         with self.assertRaises(arvados.errors.CommandFailedError):
40             arvados.util.run_command(['false'])