[tor-commits] [stem/master] Minor get_streams() testing revisions
atagar at torproject.org
atagar at torproject.org
Sat Jan 5 03:17:46 UTC 2013
commit 9808fbc0abf13ea0a6e5cef3249c286e36592494
Author: Damian Johnson <atagar at torproject.org>
Date: Fri Jan 4 09:59:44 2013 -0800
Minor get_streams() testing revisions
Minor tweaks for the get_streams() tests, for instance the 'stream' argument
was unused (likely used to assert that the stream lists were equal, which
didn't work due to mock objects leading it to be replaced when a len() check).
---
test/integ/control/controller.py | 6 ++++--
test/unit/control/controller.py | 23 +++++++++++------------
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index da091c0..8fada2b 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -591,19 +591,21 @@ class TestController(unittest.TestCase):
host = "38.229.72.14" # www.torproject.org
port = 443
- target = host + ":" + str(port)
runner = test.runner.get_runner()
with runner.get_tor_controller() as controller:
# we only need one proxy port, so take the first
socks_listener = controller.get_socks_listeners()[0]
+
with test.network.Socks(socks_listener) as s:
s.settimeout(30)
s.connect((host, port))
streams = controller.get_streams()
+
# Because we do not get a stream id when opening a stream,
# try to match the target for which we asked a stream.
- self.assertTrue(target in [stream.target for stream in streams])
+
+ self.assertTrue("%s:%s" % (host, port) in [stream.target for stream in streams])
def test_close_stream(self):
"""
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index a6fc372..fa06a2d 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -180,20 +180,19 @@ class TestControl(unittest.TestCase):
("2", "SUCCEEDED", "4", "10.10.10.1:80"),
("3", "SUCCEEDED", "4", "10.10.10.1:80")
)
- response = []
- for stream_parts in valid_streams:
- stream = mocking.get_object(events.StreamEvent)
- (stream.id, stream.status, stream.circ_id, stream.target) = stream_parts
- line = "%s\r\n" % " ".join(stream_parts)
- response.append(line)
+
+ responses = ["%s\r\n" % " ".join(entry) for entry in valid_streams]
mocking.mock_method(Controller, "get_info", mocking.return_value(
- "".join(response)
+ "".join(responses)
))
+
streams = self.controller.get_streams()
self.assertEqual(len(valid_streams), len(streams))
- for index in range(len(streams)):
- self.assertEqual(valid_streams[index][0], streams[index].id)
- self.assertEqual(valid_streams[index][1], streams[index].status)
- self.assertEqual(valid_streams[index][2], streams[index].circ_id)
- self.assertEqual(valid_streams[index][3], streams[index].target)
+
+ for index, stream in enumerate(streams):
+ self.assertEqual(valid_streams[index][0], stream.id)
+ self.assertEqual(valid_streams[index][1], stream.status)
+ self.assertEqual(valid_streams[index][2], stream.circ_id)
+ self.assertEqual(valid_streams[index][3], stream.target)
+
More information about the tor-commits
mailing list