[tor-commits] [stem/master] Test that 'tor --version' matches 'GETINFO version'
atagar at torproject.org
atagar at torproject.org
Mon Feb 9 04:30:53 UTC 2015
commit 852423c08b67a40eea6414a0118e8b747c8e5ef1
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Feb 2 09:16:52 2015 -0800
Test that 'tor --version' matches 'GETINFO version'
Improved version of test_cmdline_args.py's test_version(). This is kinda a
duplicate of test/integ/version.py's test_get_system_tor_version_value(), but
checks this a bit more directly. Besides, it gets us to lay the groundwork for
the other tests.
---
test/integ/process.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/test/integ/process.py b/test/integ/process.py
index 163fd2b..88ad8ca 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -29,6 +29,14 @@ class TestProcess(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.data_directory)
+ def test_version_argument(self):
+ """
+ Check that 'tor --version' matches 'GETINFO version'.
+ """
+
+ with test.runner.get_runner().get_tor_controller() as controller:
+ self.assertEqual('Tor version %s.\n' % controller.get_version(), self.run_tor('--version'))
+
def test_launch_tor_with_config(self):
"""
Exercises launch_tor_with_config.
@@ -191,3 +199,25 @@ class TestProcess(unittest.TestCase):
time.sleep(1)
self.fail("tor didn't quit after the controller that owned it disconnected")
+
+ def run_tor(self, *args, **kwargs):
+ # python doesn't allow us to have individual keyword arguments when there's
+ # an arbitrary number of positional arguments, so explicitly checking
+
+ expect_failure = kwargs.pop('expect_failure', False)
+
+ if kwargs:
+ raise ValueError("Got unexpected keyword arguments: %s" % kwargs)
+
+ args = [test.runner.get_runner().get_tor_command()] + list(args)
+ tor_process = subprocess.Popen(args, stdout = subprocess.PIPE)
+
+ stdout = tor_process.communicate()[0]
+ exit_status = tor_process.poll()
+
+ if exit_status and not expect_failure:
+ self.fail("Didn't expect tor to be able to start when we run: %s\n%s" % (' '.join(args), stdout))
+ elif not exit_status and expect_failure:
+ self.fail("Tor failed to start when we ran: %s\n%s" % (' '.join(args), stdout))
+
+ return stdout
More information about the tor-commits
mailing list