Skip to content

Instantly share code, notes, and snippets.

@neelchauhan
Created November 1, 2016 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neelchauhan/2e76169143dc6e24ef69321fcd6d68fb to your computer and use it in GitHub Desktop.
Save neelchauhan/2e76169143dc6e24ef69321fcd6d68fb to your computer and use it in GitHub Desktop.
Patch to split unit testing for controller.py in Stem
From 2f52a83f2958e783975de6e8ea0b8f3c918df6f8 Mon Sep 17 00:00:00 2001
From: Neel Chauhan <neel@neelc.org>
Date: Tue, 1 Nov 2016 11:07:53 -0400
Subject: [PATCH] Split getinfo controller tests
---
test/integ/control/controller.py | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 149dc03..3e11ead 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -270,9 +270,9 @@ class TestController(unittest.TestCase):
self.assertTrue(len(event_buffer) >= 1)
@require_controller
- def test_getinfo(self):
+ def test_getinfo_single(self):
"""
- Exercises GETINFO with valid and invalid queries.
+ Exercises GETINFO with a single query.
"""
runner = test.runner.get_runner()
@@ -288,17 +288,44 @@ class TestController(unittest.TestCase):
self.assertEqual(expected, controller.get_info(['config-file']))
self.assertEqual(expected, controller.get_info(['config-file'], 'ho hum'))
+ @require_controller
+ def test_getinfo_batch(self):
+ """
+ Exercises GETINFO with a batch query.
+ """
+
+ runner = test.runner.get_runner()
+
+ with runner.get_tor_controller() as controller:
# successful batch query, we don't know the values so just checking for
# the keys
getinfo_params = set(['version', 'config-file', 'config/names'])
self.assertEqual(getinfo_params, set(controller.get_info(['version', 'config-file', 'config/names']).keys()))
+ @require_controller
+ def test_getinfo_nonexistent(self):
+ """
+ Exercises GETINFO with a nonexistent (invalid) query.
+ """
+
+ runner = test.runner.get_runner()
+
+ with runner.get_tor_controller() as controller:
# non-existant option
self.assertRaises(stem.ControllerError, controller.get_info, 'blarg')
self.assertEqual('ho hum', controller.get_info('blarg', 'ho hum'))
+ @require_controller
+ def test_getinfo_empty(self):
+ """
+ Exercises GETINFO with an empty query.
+ """
+
+ runner = test.runner.get_runner()
+
+ with runner.get_tor_controller() as controller:
# empty input
self.assertRaises(stem.ControllerError, controller.get_info, '')
--
2.9.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment