[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Checking pycrypto version when running tests



commit 2a205415ed9bb1601a1ac65ec7c48f056561b3c8
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Apr 22 07:40:35 2013 -0700

    Checking pycrypto version when running tests
    
    Adding a check similar to python, pyflakes, and pep8 for the version when we
    run our tests. Bundling in various other small testing tweaks.
---
 run_tests.py     |   14 +++++++-------
 stem/util/log.py |    2 +-
 test/output.py   |    2 +-
 test/util.py     |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 9667f14..17c9145 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -58,7 +58,6 @@ OPT = "auist:l:h"
 OPT_EXPANDED = ["all", "unit", "integ", "style", "python3", "clean", "targets=", "test=", "log=", "tor=", "help"]
 
 CONFIG = stem.util.conf.config_dict("test", {
-  "target.prereq": {},
   "target.torrc": {},
   "integ.test_directory": "./test/data",
 })
@@ -68,7 +67,7 @@ SRC_PATHS = [os.path.join(STEM_BASE, path) for path in (
   'test',
   'run_tests.py',
   os.path.join('docs', 'republish.py'),
-  os.path.join('docs', 'trac.py'),
+  os.path.join('docs', 'roles.py'),
 )]
 
 LOG_TYPE_ERROR = """\
@@ -109,6 +108,7 @@ def main():
     "INITIALISING",
     Task("checking stem version", test.util.check_stem_version),
     Task("checking python version", test.util.check_python_version),
+    Task("checking pycrypto version", test.util.check_pycrypto_version),
     Task("checking pyflakes version", test.util.check_pyflakes_version),
     Task("checking pep8 version", test.util.check_pep8_version),
     Task("checking for orphaned .pyc files", test.util.clean_orphaned_pyc, (SRC_PATHS,)),
@@ -172,9 +172,9 @@ def main():
     for target in args.run_targets:
       # check if we meet this target's tor version prerequisites
 
-      target_prereq = CONFIG["target.prereq"].get(target)
+      target_prereq = test.util.get_prereq(target)
 
-      if target_prereq and our_version < stem.version.Requirement[target_prereq]:
+      if target_prereq and our_version < target_prereq:
         skipped_targets.append(target)
         continue
 
@@ -214,13 +214,13 @@ def main():
           for lingering_thread in active_threads:
             println("  %s" % lingering_thread, ERROR)
 
-          error_tracker.note_error()
+          error_tracker.register_error()
           break
       except KeyboardInterrupt:
         println("  aborted starting tor: keyboard interrupt\n", ERROR)
         break
       except OSError:
-        error_tracker.note_error()
+        error_tracker.register_error()
       finally:
         integ_runner.stop()
 
@@ -228,7 +228,7 @@ def main():
       println()
 
       for target in skipped_targets:
-        req_version = stem.version.Requirement[CONFIG["target.prereq"][target]]
+        req_version = test.util.get_prereq(target)
         println("Unable to run target %s, this requires tor version %s" % (target, req_version), ERROR)
 
       println()
diff --git a/stem/util/log.py b/stem/util/log.py
index 498c489..ca69e7f 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -196,7 +196,7 @@ class LogBuffer(logging.Handler):
 
   def __init__(self, runlevel):
     # TODO: At least in python 2.6 logging.Handler has a bug in that it doesn't
-    # extend object, causing our super() call to fail. When we drop python 2.5
+    # extend object, causing our super() call to fail. When we drop python 2.6
     # support we should switch back to using super() instead.
     #super(LogBuffer, self).__init__(level = logging_level(runlevel))
 
diff --git a/test/output.py b/test/output.py
index be51b60..7cd00b7 100644
--- a/test/output.py
+++ b/test/output.py
@@ -186,7 +186,7 @@ class ErrorTracker(object):
     self._category = None
     self._error_noted = False
 
-  def note_error(self):
+  def register_error(self):
     """
     If called then has_errors_occured() will report that an error has occured,
     even if we haven't encountered an error message in the tests.
diff --git a/test/util.py b/test/util.py
index fc68f09..12effd0 100644
--- a/test/util.py
+++ b/test/util.py
@@ -9,6 +9,7 @@ Helper functions for our test framework.
   get_unit_tests - provides our unit tests
   get_integ_tests - provides our integration tests
 
+  get_prereq - provides the tor version required to run the given target
   get_help_message - provides usage information for running our tests
   get_python3_destination - location where a python3 copy of stem is exported to
   get_stylistic_issues - checks for PEP8 and other stylistic issues
@@ -23,6 +24,7 @@ Tasks are...
   Initialization
   |- check_stem_version - checks our version of stem
   |- check_python_version - checks our version of python
+  |- check_pycrypto_version - checks our version of pycrypto
   |- check_pyflakes_version - checks our version of pyflakes
   |- check_pep8_version - checks our version of pep8
   |- clean_orphaned_pyc - removes any *.pyc without a corresponding *.py
@@ -41,8 +43,10 @@ import shutil
 import sys
 
 import stem
+import stem.prereq
 import stem.util.conf
 import stem.util.system
+import stem.version
 
 import test.output
 
@@ -51,6 +55,7 @@ from test.output import STATUS, ERROR, NO_NL, println
 CONFIG = stem.util.conf.config_dict("test", {
   "msg.help": "",
   "target.description": {},
+  "target.prereq": {},
   "pep8.ignore": [],
   "pyflakes.ignore": [],
   "integ.test_directory": "./test/data",
@@ -150,6 +155,25 @@ def get_help_message():
   return help_msg
 
 
+def get_prereq(target):
+  """
+  Provides the tor version required to run the given target. If the target
+  doesn't have any prerequisite then this provides **None**.
+
+  :param Target target: target to provide the prerequisite for
+
+  :returns: :class:`~stem.version.Version` required to run the given target, or
+    **None** if there is no prerequisite
+  """
+
+  target_prereq = CONFIG["target.prereq"].get(target)
+
+  if target_prereq:
+    return stem.version.Requirement[target_prereq]
+  else:
+    return None
+
+
 def get_python3_destination():
   """
   Provides the location where a python 3 copy of stem is exported to for
@@ -298,6 +322,14 @@ def check_python_version():
   return '.'.join(map(str, sys.version_info[:3]))
 
 
+def check_pycrypto_version():
+  if stem.prereq.is_crypto_available():
+    import Crypto
+    return Crypto.__version__
+  else:
+    return "missing"
+
+
 def check_pyflakes_version():
   try:
     import pyflakes



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits