Merge branch 'master' into 7167-keep-rsync
[arvados.git] / sdk / python / tests / test_util.py
1 import os
2 import subprocess
3 import unittest
4
5 import arvados
6
7 class MkdirDashPTest(unittest.TestCase):
8     def setUp(self):
9         try:
10             os.path.mkdir('./tmp')
11         except:
12             pass
13     def tearDown(self):
14         try:
15             os.unlink('./tmp/bar')
16             os.rmdir('./tmp/foo')
17             os.rmdir('./tmp')
18         except:
19             pass
20     def runTest(self):
21         arvados.util.mkdir_dash_p('./tmp/foo')
22         with open('./tmp/bar', 'wb') as f:
23             f.write('bar')
24         self.assertRaises(OSError, arvados.util.mkdir_dash_p, './tmp/bar')
25
26
27 class RunCommandTestCase(unittest.TestCase):
28     def test_success(self):
29         stdout, stderr = arvados.util.run_command(['echo', 'test'],
30                                                   stderr=subprocess.PIPE)
31         self.assertEqual("test\n", stdout)
32         self.assertEqual("", stderr)
33
34     def test_failure(self):
35         with self.assertRaises(arvados.errors.CommandFailedError):
36             arvados.util.run_command(['false'])