[tor-commits] [stem/master] Dropping unnecessary imports from pydoc examples

atagar at torproject.org atagar at torproject.org
Sun Oct 27 18:13:00 UTC 2013


commit daa2b6e0674257b6b673343e07d9b011f3fcad3f
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Oct 27 10:36:24 2013 -0700

    Dropping unnecessary imports from pydoc examples
    
    I added a handful of imports to our pydoc examples to allow doctest to work.
    However, with globs we can work around needing them (yay!).
---
 stem/descriptor/router_status_entry.py |    1 -
 stem/util/connection.py                |    1 -
 stem/util/str_tools.py                 |    6 ------
 test/unit/doctest.py                   |   27 +++++++++++++++++++++++++++
 4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 6622b72..6600e31 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -699,7 +699,6 @@ def _base64_to_hex(identity, validate, check_if_fingerprint = True):
 
   ::
 
-    >>> from stem.descriptor.router_status_entry import _base64_to_hex
     >>> _base64_to_hex('p1aag7VwarGxqctS7/fS0y5FU+s', True)
     'A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB'
 
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 6e87f94..893230e 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -403,7 +403,6 @@ def expand_ipv6_address(address):
 
   ::
 
-    >>> from stem.util.connection import expand_ipv6_address
     >>> expand_ipv6_address("2001:db8::ff00:42:8329")
     '2001:0db8:0000:0000:0000:ff00:0042:8329'
 
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index 100bd0c..33d5e1b 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -109,7 +109,6 @@ def _to_camel_case(label, divider = "_", joiner = " "):
 
   ::
 
-    >>> from stem.util.str_tools import _to_camel_case
     >>> _to_camel_case("I_LIKE_PEPPERJACK!")
     'I Like Pepperjack!'
 
@@ -142,7 +141,6 @@ def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
 
   ::
 
-    >>> from stem.util.str_tools import get_size_label
     >>> get_size_label(2000000)
     '1 MB'
 
@@ -178,7 +176,6 @@ def get_time_label(seconds, decimal = 0, is_long = False):
 
   ::
 
-    >>> from stem.util.str_tools import get_time_label
     >>> get_time_label(10000)
     '2h'
 
@@ -206,7 +203,6 @@ def get_time_labels(seconds, is_long = False):
 
   ::
 
-    >>> from stem.util.str_tools import get_time_labels
     >>> get_time_labels(400)
     ['6m', '40s']
 
@@ -236,7 +232,6 @@ def get_short_time_label(seconds):
 
   ::
 
-    >>> from stem.util.str_tools import get_short_time_label
     >>> get_short_time_label(111)
     '01:51'
 
@@ -278,7 +273,6 @@ def parse_short_time_label(label):
 
   ::
 
-    >>> from stem.util.str_tools import parse_short_time_label
     >>> parse_short_time_label('01:51')
     111
 
diff --git a/test/unit/doctest.py b/test/unit/doctest.py
index d016372..9735dbd 100644
--- a/test/unit/doctest.py
+++ b/test/unit/doctest.py
@@ -8,6 +8,9 @@ import doctest
 import os
 import unittest
 
+import stem.descriptor.router_status_entry
+import stem.util.connection
+import stem.util.str_tools
 import stem.version
 
 import test.util
@@ -23,6 +26,7 @@ EXPECTED_CIRCUIT_STATUS = """\
 19 BUILT $718BCEA286B531757ACAFF93AE04910EA73DE617=KsmoinOK,$30BAB8EE7606CBD12F3CC269AE976E0153E7A58D=Pascal1,$2765D8A8C4BBA3F89585A9FFE0E8575615880BEB=Anthracite PURPOSE=GENERAL TIME_CREATED=2012-12-06T13:50:56.969938\
 """
 
+
 class TestDocumentation(unittest.TestCase):
   def test_examples(self):
     stem_dir = os.path.join(test.util.STEM_BASE, 'stem')
@@ -34,6 +38,29 @@ class TestDocumentation(unittest.TestCase):
 
       if path.endswith('/stem/util/conf.py'):
         pass  # too much context to easily test
+      elif path.endswith('/stem/descriptor/router_status_entry.py'):
+        args['globs'] = {
+          '_base64_to_hex': stem.descriptor.router_status_entry._base64_to_hex
+        }
+
+        test_run = doctest.testfile(path, **args)
+      elif path.endswith('/stem/util/connection.py'):
+        args['globs'] = {
+          'expand_ipv6_address': stem.util.connection.expand_ipv6_address,
+        }
+
+        test_run = doctest.testfile(path, **args)
+      elif path.endswith('/stem/util/str_tools.py'):
+        args['globs'] = {
+          '_to_camel_case': stem.util.str_tools._to_camel_case,
+          'get_size_label': stem.util.str_tools.get_size_label,
+          'get_time_label': stem.util.str_tools.get_time_label,
+          'get_time_labels': stem.util.str_tools.get_time_labels,
+          'get_short_time_label': stem.util.str_tools.get_short_time_label,
+          'parse_short_time_label': stem.util.str_tools.parse_short_time_label,
+        }
+
+        test_run = doctest.testfile(path, **args)
       elif path.endswith('/stem/response/__init__.py'):
         pass  # the escaped slashes seem to be confusing doctest
       elif path.endswith('/stem/control.py'):





More information about the tor-commits mailing list