commit 68b57bfe7a9615a642ae98c0bcdb20ddf8e5051b Author: Damian Johnson atagar@torproject.org Date: Sun Sep 27 17:20:17 2020 -0700
Move descriptor_from_tor_data_directory test --- test/unit/examples.py | 12 ++++++++++-- test/unit/tutorial.py | 20 -------------------- 2 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/test/unit/examples.py b/test/unit/examples.py index ef1d9ed9..c972c7e9 100644 --- a/test/unit/examples.py +++ b/test/unit/examples.py @@ -420,8 +420,16 @@ class TestExamples(unittest.TestCase):
self.assertEqual('found relay caerSidi (A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB)\n', stdout_mock.getvalue())
- def test_descriptor_from_tor_data_directory(self): - pass + @patch('stem.descriptor.parse_file') + @patch('sys.stdout', new_callable = io.StringIO) + def test_descriptor_from_tor_data_directory(self, stdout_mock, parse_file_mock): + parse_file_mock.return_value = [RouterStatusEntryV3.create({ + 'r': 'caerSidi p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0', + })] + + import descriptor_from_tor_data_directory + + self.assertEqual('found relay caerSidi (A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB)\n', stdout_mock.getvalue())
def test_download_descriptor(self): pass diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py index d6b6ee3b..e2b621e8 100644 --- a/test/unit/tutorial.py +++ b/test/unit/tutorial.py @@ -9,8 +9,6 @@ import stem.descriptor.remote
from unittest.mock import patch
-from stem.descriptor.router_status_entry import RouterStatusEntryV3 -from stem.descriptor.networkstatus import NetworkStatusDocumentV3 from stem.descriptor.server_descriptor import RelayDescriptor
MIRROR_MIRROR_OUTPUT = """\ @@ -27,24 +25,6 @@ class TestTutorial(unittest.TestCase):
stem.descriptor.remote.SINGLETON_DOWNLOADER = None
- @patch('sys.stdout', new_callable = io.StringIO) - @patch('%s.open' % __name__, create = True) - def test_mirror_mirror_on_the_wall_3(self, open_mock, stdout_mock): - def tutorial_example(): - from stem.descriptor import parse_file - - for desc in parse_file(open('/home/atagar/.tor/cached-consensus')): - print('found relay %s (%s)' % (desc.nickname, desc.fingerprint)) - - test_file = io.BytesIO(NetworkStatusDocumentV3.content(routers = [RouterStatusEntryV3.create({ - 'r': 'caerSidi p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0', - })])) - test_file.name = '/home/atagar/.tor/cached-consensus' - open_mock.return_value = test_file - - tutorial_example() - self.assertEqual('found relay caerSidi (A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB)\n', stdout_mock.getvalue()) - @patch('sys.stdout', new_callable = io.StringIO) @patch('stem.descriptor.remote.DescriptorDownloader') def test_mirror_mirror_on_the_wall_5(self, downloader_mock, stdout_mock):