11139: Added new test to check for non-default values. Updated example config files.
[arvados.git] / services / nodemanager / tests / test_arguments.py
index e4749ce01caee552e310aa471077d954e1971235..f98309aef4b41238cda05e5c459d3a9222afd593 100644 (file)
@@ -1,42 +1,27 @@
 #!/usr/bin/env python
 
-import multiprocessing
+import io
 import os
 import sys
 import tempfile
 import unittest
 
 import arvnodeman.launcher as nodeman
+from . import testutil
 
 class ArvNodemArgumentsTestCase(unittest.TestCase):
     def run_nodeman(self, args):
         return nodeman.main(args)
 
-    def run_nodeman_process(self, args=[]):
-        _, stdout_path = tempfile.mkstemp()
-        _, stderr_path = tempfile.mkstemp()
-        def wrap():
-            def wrapper(*args, **kwargs):
-                sys.stdout = open(stdout_path, 'w')
-                sys.stderr = open(stderr_path, 'w')
-                nodeman.main(*args, **kwargs)
-            return wrapper
-        p = multiprocessing.Process(target=wrap(), args=(args,))
-        p.start()
-        p.join()
-        out = open(stdout_path, 'r').read()
-        err = open(stderr_path, 'r').read()
-        os.unlink(stdout_path)
-        os.unlink(stderr_path)
-        return p.exitcode, out, err
-
     def test_unsupported_arg(self):
         with self.assertRaises(SystemExit):
             self.run_nodeman(['-x=unknown'])
 
     def test_version_argument(self):
-        exitcode, out, err = self.run_nodeman_process(['--version'])
-        self.assertEqual(0, exitcode)
-        self.assertEqual('', out)
-        self.assertNotEqual('', err)
-        self.assertRegexpMatches(err, "[0-9]+\.[0-9]+\.[0-9]+")
+        err = io.BytesIO()
+        out = io.BytesIO()
+        with testutil.redirected_streams(stdout=out, stderr=err):
+            with self.assertRaises(SystemExit):
+                self.run_nodeman(['--version'])
+        self.assertEqual(out.getvalue(), '')
+        self.assertRegexpMatches(err.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+")