[tor-commits] [stem/master] Test custom_path_selection example
atagar at torproject.org
atagar at torproject.org
Fri Oct 2 23:16:05 UTC 2020
commit c01daf3be5be2906a4dfd0d85464dee9667d2d1a
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 28 16:25:46 2020 -0700
Test custom_path_selection example
---
docs/_static/example/custom_path_selection.py | 4 ++--
test/unit/examples.py | 22 ++++++++++++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/docs/_static/example/custom_path_selection.py b/docs/_static/example/custom_path_selection.py
index d63a2069..551f7b2f 100644
--- a/docs/_static/example/custom_path_selection.py
+++ b/docs/_static/example/custom_path_selection.py
@@ -1,4 +1,4 @@
-import StringIO
+import io
import time
import pycurl
@@ -20,7 +20,7 @@ def query(url):
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
- output = StringIO.StringIO()
+ output = io.StringIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
diff --git a/test/unit/examples.py b/test/unit/examples.py
index 1b85c297..aa1c25ce 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -427,8 +427,26 @@ class TestExamples(unittest.TestCase):
self.assertEqual('found relay caerSidi (A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB)\n', stdout_mock.getvalue())
- def test_custom_path_selection(self):
- pass
+ @patch('stem.control.Controller.from_port', spec = Controller)
+ @patch('sys.stdout', new_callable = io.StringIO)
+ def test_custom_path_selection(self, stdout_mock, from_port_mock):
+ original_modules = dict(sys.modules)
+
+ try:
+ # pycurl mocked out so its query method returns an empty string
+
+ sys.modules['pycurl'] = Mock()
+
+ controller = from_port_mock().__enter__()
+ controller.get_network_statuses.return_value = [RouterStatusEntryV2.create({
+ 'r': 'caerSidi p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0',
+ })]
+
+ import custom_path_selection
+
+ self.assertEqual("A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB => Request didn't have the right content\n", stdout_mock.getvalue())
+ finally:
+ sys.modules = original_modules
def test_descriptor_from_orport(self):
pass
More information about the tor-commits
mailing list