[tor-commits] [stem/master] Test create_descriptor example

atagar at torproject.org atagar at torproject.org
Fri Oct 2 23:16:05 UTC 2020


commit a72cb09d271dd04b5f81b91272a0abfbbcdc867a
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Sep 28 16:06:02 2020 -0700

    Test create_descriptor example
---
 docs/_static/example/create_descriptor_content.py |  2 +-
 test/unit/examples.py                             | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/docs/_static/example/create_descriptor_content.py b/docs/_static/example/create_descriptor_content.py
index e4a9f2b8..b69ea768 100644
--- a/docs/_static/example/create_descriptor_content.py
+++ b/docs/_static/example/create_descriptor_content.py
@@ -1,3 +1,3 @@
 from stem.descriptor.server_descriptor import RelayDescriptor
 
-print(RelayDescriptor.content({'router': 'demo 127.0.0.1 80 0 0'}))
+print(RelayDescriptor.content({'router': 'demo 127.0.0.1 80 0 0'}).decode('utf-8'))
diff --git a/test/unit/examples.py b/test/unit/examples.py
index dc9fc242..1b85c297 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -396,11 +396,25 @@ class TestExamples(unittest.TestCase):
 
     self.assertEqual(EXPECTED_COMPARE_FLAGS, stdout_mock.getvalue())
 
-  def test_create_descriptor(self):
-    pass
+  @patch('sys.stdout', new_callable = io.StringIO)
+  def test_create_descriptor(self, stdout_mock):
+    import create_descriptor
 
-  def test_create_descriptor_content(self):
-    pass
+    # First line is randomized, for example...
+    #
+    #   Unnamed566296572314 (226.149.46.74:9001)
+    #   demo (127.0.0.1:80)
+
+    lines = stdout_mock.getvalue().splitlines()
+
+    self.assertTrue(lines[0].startswith('Unnamed'))
+    self.assertEqual('demo (127.0.0.1:80)', lines[1])
+
+  @patch('sys.stdout', new_callable = io.StringIO)
+  def test_create_descriptor_content(self, stdout_mock):
+    import create_descriptor_content
+
+    self.assertTrue(stdout_mock.getvalue().startswith('router demo 127.0.0.1 80 0 0\npublish'))
 
   @patch('stem.descriptor.remote.DescriptorDownloader')
   @patch('sys.stdout', new_callable = io.StringIO)





More information about the tor-commits mailing list