10587: Added tests to Python commands to check for the --version argument.
[arvados.git] / sdk / python / tests / test_arv_copy.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import multiprocessing
5 import os
6 import sys
7 import tempfile
8 import unittest
9
10 import arvados.commands.arv_copy as arv_copy
11
12 class ArvCopyTestCase(unittest.TestCase):
13     def run_copy(self, args):
14         sys.argv = ['arv-copy'] + args
15         return arv_copy.main()
16
17     def run_copy_process(self, args):
18         _, stdout_path = tempfile.mkstemp()
19         _, stderr_path = tempfile.mkstemp()
20         def wrap():
21             def wrapper():
22                 sys.argv = ['arv-copy'] + args
23                 sys.stdout = open(stdout_path, 'w')
24                 sys.stderr = open(stderr_path, 'w')
25                 arv_copy.main()
26             return wrapper
27         p = multiprocessing.Process(target=wrap())
28         p.start()
29         p.join()
30         out = open(stdout_path, 'r').read()
31         err = open(stderr_path, 'r').read()
32         os.unlink(stdout_path)
33         os.unlink(stderr_path)
34         return p.exitcode, out, err
35
36     def test_unsupported_arg(self):
37         with self.assertRaises(SystemExit):
38             self.run_copy(['-x=unknown'])
39
40     def test_version_argument(self):
41         exitcode, out, err = self.run_copy_process(['--version'])
42         self.assertEqual(0, exitcode)
43         self.assertEqual('', out)
44         self.assertNotEqual('', err)
45         self.assertRegexpMatches(err, "[0-9]+\.[0-9]+\.[0-9]+")