[tor-commits] [stem/master] Speed up test_download_descriptor

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


commit e32f8f75ef31e7165344534dbb56e5fb1c2674a8
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Oct 2 14:42:59 2020 -0700

    Speed up test_download_descriptor
    
    Our '--help' assertion pointlessly downloaded server descriptors (since we
    negate sys.exit). This reduces this test's runtime from 211 to 1 ms.
---
 test/unit/examples.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/unit/examples.py b/test/unit/examples.py
index faea5e6c..2d6d2eec 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -606,8 +606,9 @@ class TestExamples(unittest.TestCase):
     import download_descriptor
 
     with patch('sys.stdout', new_callable = io.StringIO) as stdout_mock:
-      download_descriptor.main(['--help'])
-      self.assertTrue(stdout_mock.getvalue().startswith("Downloads a descriptor through Tor's ORPort"))
+      with patch('stem.descriptor.remote.get_server_descriptors', _download_of([])):
+        download_descriptor.main(['--help'])
+        self.assertTrue(stdout_mock.getvalue().startswith("Downloads a descriptor through Tor's ORPort"))
 
     with patch('sys.stdout', new_callable = io.StringIO) as stdout_mock:
       download_descriptor.main(['--type', 'kaboom'])





More information about the tor-commits mailing list