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

[tor-commits] [stem/master] Skip running async tests under python 2.6



commit 70b49df22b11f9dfc18e939413d9e847996c1f11
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Oct 27 09:20:43 2017 -0700

    Skip running async tests under python 2.6
    
    Turns out importlib was added in python 2.7...
    
      Traceback (most recent call last):
        File "./run_tests.py", line 9, in <module>
          import importlib
      ImportError: No module named importlib
    
    This means we're losing quite a bit of test coverage under python 2.6 but...
    screw it. Guido rolled his eyes when I mentioned we even offered 2.6 support.
    It's been dead a long time.
    
    We'll continue to support python 2.6 until stem 2.0, but not gonna bend over
    backwards for it. This change will let us invoke our tests again.
---
 run_tests.py            | 11 +++++++++--
 stem/util/test_tools.py |  6 ++++++
 test/integ/process.py   |  2 +-
 test/task.py            | 14 ++++++++++++--
 4 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index e2bc19ad..fe4a908f 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -6,7 +6,6 @@
 Runs unit and integration tests. For usage information run this with '--help'.
 """
 
-import importlib
 import os
 import sys
 import threading
@@ -15,6 +14,14 @@ import traceback
 import unittest
 
 try:
+  # TODO: added in python 2.7, drop check when removing 2.6 support
+
+  import importlib
+  RUN_ASYNC_TESTS = true
+except ImportError:
+  RUN_ASYNC_TESTS = False
+
+try:
   from StringIO import StringIO
 except ImportError:
   from io import StringIO
@@ -194,7 +201,7 @@ def main():
     async_args = test.AsyncTestArgs(default_test_dir, args.tor_path)
 
     for module_str in stem.util.test_tools.ASYNC_TESTS:
-      if not args.specific_test or module_str.startswith(args.specific_test):
+      if RUN_ASYNC_TESTS and (not args.specific_test or module_str.startswith(args.specific_test)):
         module = importlib.import_module(module_str.rsplit('.', 1)[0])
         test_classes = [v for k, v in module.__dict__.items() if k.startswith('Test')]
 
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index d12ccf82..62ca1577 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -158,6 +158,9 @@ class AsyncTest(object):
     self._status = AsyncStatus.PENDING
 
   def run(self, *runner_args, **kwargs):
+    if stem.prereq._is_python_26():
+      return  # not supported under python 2.6
+
     def _wrapper(conn, runner, args):
       os.nice(12)
 
@@ -199,6 +202,9 @@ class AsyncTest(object):
     self.result(None)
 
   def result(self, test):
+    if stem.prereq._is_python_26():
+      return  # not supported under python 2.6
+
     with self._process_lock:
       if self._status == AsyncStatus.PENDING:
         self.run()
diff --git a/test/integ/process.py b/test/integ/process.py
index 72cba38b..1c8035b5 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -45,7 +45,7 @@ PublishServerDescriptor 0
 DataDirectory %s
 """
 
-TOR_CMD = None
+TOR_CMD = 'tor'
 
 
 def random_port():
diff --git a/test/task.py b/test/task.py
index 53606a19..2af92875 100644
--- a/test/task.py
+++ b/test/task.py
@@ -22,7 +22,6 @@
   +- PYCODESTYLE_TASK - style checks
 """
 
-import importlib
 import os
 import re
 import sys
@@ -39,6 +38,14 @@ import test.output
 
 from test.output import STATUS, ERROR, NO_NL, println
 
+try:
+  # TODO: remove check when dropping python 2.6 support
+
+  import importlib
+  HAS_IMPORTLIB = True
+except ImportError:
+  HAS_IMPORTLIB = False
+
 CONFIG = stem.util.conf.config_dict('test', {
   'integ.test_directory': './test/data',
   'test.unit_tests': '',
@@ -81,6 +88,9 @@ def _import_tests():
   register if they're asynchronous.
   """
 
+  if not HAS_IMPORTLIB:
+    return
+
   for module in (CONFIG['test.unit_tests'].splitlines() + CONFIG['test.integ_tests'].splitlines()):
     importlib.import_module(module.rsplit('.', 1)[0])
 
@@ -217,7 +227,7 @@ class ModuleVersion(Task):
     def version_check():
       if prereq_check is None or prereq_check():
         for module in modules:
-          if stem.util.test_tools._module_exists(module):
+          if HAS_IMPORTLIB and stem.util.test_tools._module_exists(module):
             return importlib.import_module(module).__version__
 
       return 'missing'



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