Merge branch '9005-keep-http-client'
[arvados.git] / sdk / python / tests / test_util.py
index f9e5d8ce40b2a462f10ec7cf710e146e0b795d0b..bf59d0dedae5cf99e6ee3c5c13803f22cf65d299 100644 (file)
@@ -1,6 +1,8 @@
-import unittest
 import os
-import arvados.util
+import subprocess
+import unittest
+
+import arvados
 
 class MkdirDashPTest(unittest.TestCase):
     def setUp(self):
@@ -18,5 +20,17 @@ class MkdirDashPTest(unittest.TestCase):
     def runTest(self):
         arvados.util.mkdir_dash_p('./tmp/foo')
         with open('./tmp/bar', 'wb') as f:
-            f.write('bar')
+            f.write(b'bar')
         self.assertRaises(OSError, arvados.util.mkdir_dash_p, './tmp/bar')
+
+
+class RunCommandTestCase(unittest.TestCase):
+    def test_success(self):
+        stdout, stderr = arvados.util.run_command(['echo', 'test'],
+                                                  stderr=subprocess.PIPE)
+        self.assertEqual("test\n".encode(), stdout)
+        self.assertEqual("".encode(), stderr)
+
+    def test_failure(self):
+        with self.assertRaises(arvados.errors.CommandFailedError):
+            arvados.util.run_command(['false'])