[tor-commits] [stem/master] Provide '[type] description' for new capabilities

atagar at torproject.org atagar at torproject.org
Mon Mar 23 01:28:54 UTC 2015


commit 4d5291895595c2ffbb59032f1865db6aa0f18851
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Mar 22 17:17:35 2015 -0700

    Provide '[type] description' for new capabilities
    
    For descriptors we just provided the keyword rather than the whole line. Might
    as well show something like...
    
      [Server descriptor line] new-keyword 25,38,290
---
 run_tests.py                                  |   12 ++++----
 test/integ/control/controller.py              |   13 ++------
 test/integ/descriptor/extrainfo_descriptor.py |   12 ++------
 test/integ/descriptor/microdescriptor.py      |   13 ++------
 test/integ/descriptor/networkstatus.py        |   41 ++++++++-----------------
 test/integ/descriptor/server_descriptor.py    |   13 ++------
 test/util.py                                  |   21 ++++++++-----
 7 files changed, 41 insertions(+), 84 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 2a44366..4e8a8fd 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -62,9 +62,10 @@ NEW_CAPABILITIES_FOUND = """\
 Your version of Tor has capabilities stem presently isn't taking advantage of.
 If you're running the latest version of stem then please file a ticket on:
 
-https://trac.torproject.org/projects/tor/wiki/doc/stem/bugs
+  https://trac.torproject.org/projects/tor/wiki/doc/stem/bugs
 
 New capabilities are:
+
 """
 
 PYFLAKES_TASK = Task(
@@ -296,15 +297,14 @@ def main():
       println('%i TESTS WERE SKIPPED' % skipped_tests, STATUS)
 
     println('TESTING PASSED %s\n' % runtime_label, SUCCESS)
-    
+
   new_capabilities = test.util.get_new_capabilities()
-  
+
   if new_capabilities:
     println(NEW_CAPABILITIES_FOUND, ERROR)
-    
-    for item in new_capabilities:
-      println('%s: %s' % (new_capabilities[item], item), ERROR)
 
+    for capability_type, msg in new_capabilities:
+      println('  [%s] %s' % (capability_type, msg), ERROR)
 
   sys.exit(1 if error_tracker.has_errors_occured() else 0)
 
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 2be5a17..fb08e0f 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -26,6 +26,7 @@ from stem import Flag, Signal
 from stem.control import EventType, Listener, State
 from stem.exit_policy import ExitPolicy
 from stem.version import Requirement
+
 from test.util import register_new_capability
 
 from test.runner import (
@@ -1085,16 +1086,8 @@ class TestController(unittest.TestCase):
         self.assertTrue(desc.fingerprint is not None)
         self.assertTrue(desc.nickname is not None)
 
-        unrecognized_lines = desc.get_unrecognized_lines()
-
-        if unrecognized_lines:
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
-
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Network Descriptor Entry')
+        for line in desc.get_unrecognized_lines():
+          register_new_capability('Consensus line', line)
 
         count += 1
         if count > 10:
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 92dcbf5..0c37afa 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -9,7 +9,6 @@ import stem.descriptor
 import test.runner
 
 from test.runner import only_run_once
-
 from test.util import register_new_capability
 
 
@@ -30,7 +29,8 @@ class TestExtraInfoDescriptor(unittest.TestCase):
 
     with open(descriptor_path, 'rb') as descriptor_file:
       for desc in stem.descriptor.parse_file(descriptor_file, 'extra-info 1.0', validate = True):
-        unrecognized_lines = desc.get_unrecognized_lines()
+        for line in desc.get_unrecognized_lines():
+          register_new_capability('Extra-info descriptor line', line)
 
         if desc.dir_v2_responses_unknown:
           self.fail('Unrecognized statuses on dirreq-v2-resp lines: %s' % desc.dir_v2_responses_unknown)
@@ -42,11 +42,3 @@ class TestExtraInfoDescriptor(unittest.TestCase):
           self.fail('Unrecognized stats on dirreq-v3-direct-dl lines: %s' % desc.dir_v2_direct_dl_unknown)
         elif desc.dir_v2_tunneled_dl_unknown:
           self.fail('Unrecognized stats on dirreq-v2-tunneled-dl lines: %s' % desc.dir_v2_tunneled_dl_unknown)
-        elif unrecognized_lines:
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
-
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Extrainfo Descriptor Entry')
diff --git a/test/integ/descriptor/microdescriptor.py b/test/integ/descriptor/microdescriptor.py
index 0ea7ea1..26d04ef 100644
--- a/test/integ/descriptor/microdescriptor.py
+++ b/test/integ/descriptor/microdescriptor.py
@@ -9,7 +9,6 @@ import stem.descriptor
 import test.runner
 
 from test.runner import only_run_once
-
 from test.util import register_new_capability
 
 
@@ -30,13 +29,5 @@ class TestMicrodescriptor(unittest.TestCase):
 
     with open(descriptor_path, 'rb') as descriptor_file:
       for desc in stem.descriptor.parse_file(descriptor_file, 'microdescriptor 1.0', validate = True):
-        unrecognized_lines = desc.get_unrecognized_lines()
-
-        if unrecognized_lines:
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
-
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Microdescriptor Descriptor Entry')
+        for line in desc.get_unrecognized_lines():
+          register_new_capability('Microdescriptor line', line)
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index 21fdaf1..215188a 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -12,7 +12,6 @@ import stem.version
 import test.runner
 
 from test.runner import only_run_once
-
 from test.util import register_new_capability
 
 
@@ -35,26 +34,19 @@ class TestNetworkStatus(unittest.TestCase):
       test.runner.skip(self, '(unavailable on windows)')
       return
 
-    count = 0
+    count, reported_flags = 0, []
+
     with open(consensus_path, 'rb') as descriptor_file:
       for router in stem.descriptor.parse_file(descriptor_file, 'network-status-consensus-3 1.0', validate = True):
         count += 1
 
-        # check if there's any unknown flags and report them to the user
         for flag in router.flags:
-          if flag not in stem.Flag:
-            register_new_capability(flag, 'Network Flag')
-
-        unrecognized_lines = router.get_unrecognized_lines()
+          if flag not in stem.Flag and flag not in reported_flags:
+            register_new_capability('Relay flag', flag)
+            reported_flags.append(flag)
 
-        if unrecognized_lines:
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
-
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Network Descriptor Entry')
+        for line in router.get_unrecognized_lines():
+          register_new_capability('Consensus line', line)
 
     # Sanity test that there's at least a hundred relays. If that's not the
     # case then this probably isn't a real, complete tor consensus.
@@ -76,25 +68,18 @@ class TestNetworkStatus(unittest.TestCase):
       test.runner.skip(self, '(unavailable on windows)')
       return
 
-    count = 0
+    count, reported_flags = 0, []
+
     with open(consensus_path, 'rb') as descriptor_file:
       for router in stem.descriptor.parse_file(descriptor_file, 'network-status-microdesc-consensus-3 1.0', validate = True):
         count += 1
 
-        # check if there's any unknown flags and report them to the user
         for flag in router.flags:
           if flag not in stem.Flag:
-            register_new_capability(flag, 'Network Flag')
-
-        unrecognized_lines = router.get_unrecognized_lines()
-
-        if unrecognized_lines:
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
+            register_new_capability('Relay flag (microdescriptor consensus)', flag)
+            reported_flags.append(flag)
 
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Network Descriptor Entry')
+        for line in router.get_unrecognized_lines():
+          register_new_capability('Microdescriptor consensus line', line)
 
     self.assertTrue(count > 100)
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index 1404cfa..7afff60 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -10,7 +10,6 @@ import stem.descriptor
 import test.runner
 
 from test.runner import only_run_once
-
 from test.util import register_new_capability
 
 
@@ -37,13 +36,5 @@ class TestServerDescriptor(unittest.TestCase):
         self.assertEqual(None, desc.eventdns)
         self.assertEqual(None, desc.socks_port)
 
-        unrecognized_lines = desc.get_unrecognized_lines()
-
-        if unrecognized_lines:          
-          # Forward-compability:
-          # 1) SHOULD function at least as it does normally (ignore the unknown)
-          # 2) Report each of the aditional (unrecognized) fields to the user
-
-          for line in unrecognized_lines:
-            key = line.split()[0]
-            register_new_capability(key, 'Server Descriptor Entry')
+        for line in desc.get_unrecognized_lines():
+          register_new_capability('Server descriptor line', line)
diff --git a/test/util.py b/test/util.py
index 10fd408..87fc47e 100644
--- a/test/util.py
+++ b/test/util.py
@@ -82,7 +82,7 @@ STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
 
 # Store new capabilities (events, descriptor entries, etc.)
 
-NEW_CAPABILITIES = {}
+NEW_CAPABILITIES = []
 
 
 def get_unit_tests(module_prefix = None):
@@ -181,8 +181,12 @@ def get_torrc_entries(target):
 
 def get_new_capabilities():
   """
-  Return list of new capabilities found during the tests
+  Provides a list of capabilities tor supports but stem doesn't, as discovered
+  while running our tests.
+
+  :returns: **list** of (type, message) tuples for the capabilities
   """
+
   return NEW_CAPABILITIES
 
 
@@ -274,16 +278,17 @@ def check_for_unused_tests(paths):
 
   if unused_tests:
     raise ValueError('Test modules are missing from our test/settings.cfg:\n%s' % '\n'.join(unused_tests))
-    
 
-def register_new_capability(key, label):
+
+def register_new_capability(capability_type, msg):
   """
   Register new capability found during the tests.
-  
-  :param str key: unique string to identify this new capability
-  :param str label: string describing where we found this new capability
+
+  :param str capability_type: type of capability this is
+  :param str msg: description of what we found
   """
-  NEW_CAPABILITIES[key] = label
+
+  NEW_CAPABILITIES.append((capability_type, msg))
 
 
 def _is_test_data(path):





More information about the tor-commits mailing list