[tor-commits] [stem/master] Minor changes for windows test compatibility fixes

atagar at torproject.org atagar at torproject.org
Thu Jun 21 15:45:57 UTC 2012


commit 6f626f3f1a43368f13b2679f3eab6322f26788c0
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jun 21 08:35:32 2012 -0700

    Minor changes for windows test compatibility fixes
    
    Just a few minor tweaks...
    
    * The 'path' and 'relative_path' were starting to get confused, so making the
      former the pristine input argument and having the later be what we modify.
    
    * A recent change removed direct usage of 'skipTest' since it breaks us on
      python 2.5 and 2.6...
      https://gitweb.torproject.org/stem.git/commitdiff/ed0db8f
    
    * Skipping the 'is multiple tor instances' check rather than always skipping
      the system integ tests.
    
    * run_tests.py somehow lost its executable permissions in 2b96648 (...?)
---
 run_tests.py                    |    1 -
 stem/util/system.py             |   23 ++++++++++++-----------
 test/integ/descriptor/reader.py |   12 +++++-------
 test/integ/util/system.py       |    7 ++++---
 4 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/run_tests.py b/run_tests.py
old mode 100644
new mode 100755
index 6ab6fae..bcd7e12
--- a/run_tests.py
+++ b/run_tests.py
@@ -11,7 +11,6 @@ import getopt
 import unittest
 import threading
 import StringIO
-import platform
 
 import test.output
 import test.runner
diff --git a/stem/util/system.py b/stem/util/system.py
index 3db9cc0..d6a3ce2 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -501,31 +501,32 @@ def expand_path(path, cwd = None):
   :returns: str of the path expanded to be an absolute path
   """
   
-  if platform.system() == "Windows":
-    path = path.replace("/", "\\").rstrip("\\")
+  if is_windows():
+    relative_path = path.replace("/", "\\").rstrip("\\")
   else:
-    path = path.replace("\\", "/").rstrip("/")
-  relative_path = path
+    relative_path = path.rstrip("/")
   
-  if not path or os.path.isabs(path):
+  if not relative_path or os.path.isabs(relative_path):
     # empty or already absolute - nothing to do
     pass
-  elif path.startswith("~"):
+  elif not is_windows() and relative_path.startswith("~"):
     # prefixed with a ~ or ~user entry
-    relative_path = os.path.expanduser(path)
+    relative_path = os.path.expanduser(relative_path)
   else:
     # relative path, expand with the cwd
     if not cwd: cwd = os.getcwd()
     
     # we'll be dealing with both "my/path/" and "./my/path" entries, so
     # cropping the later
-    if path.startswith("./") or path.startswith(".\\"): path = path[2:]
-    elif path == ".": path = ""
+    if relative_path.startswith("./") or relative_path.startswith(".\\"):
+      relative_path = relative_path[2:]
+    elif relative_path == ".":
+      relative_path = ""
     
-    if path == "":
+    if relative_path == "":
         relative_path = cwd
     else:
-        relative_path = os.path.join(cwd, path)
+        relative_path = os.path.join(cwd, relative_path)
   
   return relative_path
 
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 9c793d3..27d096f 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -107,10 +107,11 @@ class TestDescriptorReader(unittest.TestCase):
     """
     
     # Skip the test on windows, since you can only set the file's
-    # read-only flag with os.chmod(). See
+    # read-only flag with os.chmod(). For more information see...
     # http://docs.python.org/library/os.html#os.chmod
+    
     if system.is_windows():
-      self.skipTest("(chmod not functional)")
+      test.runner.skip("(chmod not functional)")
     
     test_listing_path = _make_processed_files_listing(BASIC_LISTING)
     os.chmod(test_listing_path, 0077) # remove read permissions
@@ -290,7 +291,7 @@ class TestDescriptorReader(unittest.TestCase):
     """
     
     # Skip on windows since SIGALRM is unavailable
-    if system.is_windows(): self.skipTest("(SIGALRM unavailable)")
+    if system.is_windows(): test.runner.skip("(SIGALRM unavailable)")
     
     is_test_running = True
     reader = stem.descriptor.reader.DescriptorReader("/usr")
@@ -413,11 +414,8 @@ class TestDescriptorReader(unittest.TestCase):
     Listens for a file that's skipped because we lack read permissions.
     """
     
-    # Skip the test on windows, since you can only set the file's
-    # read-only flag with os.chmod(). See
-    # http://docs.python.org/library/os.html#os.chmod
     if system.is_windows():
-      self.skipTest("(chmod not functional)")
+      test.runner.skip("(chmod not functional)")
     
     test_path = test.runner.get_runner().get_test_dir("secret_file")
     
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 58e0248..6cdf0ec 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -42,10 +42,11 @@ class TestSystem(unittest.TestCase):
     # legitemately fail.
     
     if self.is_extra_tor_running is None:
-      if not stem.util.system.is_bsd():
+      if stem.util.system.is_windows():
+        # TODO: not sure how to check for this on windows
+        self.is_extra_tor_running = False
+      elif not stem.util.system.is_bsd():
         pgrep_results = stem.util.system.call(stem.util.system.GET_PID_BY_NAME_PGREP % "tor")
-        if pgrep_results is None:
-          self.skipTest("(pgrep unavailable)")
         self.is_extra_tor_running = len(pgrep_results) > 1
       else:
         ps_results = stem.util.system.call(stem.util.system.GET_PID_BY_NAME_PS_BSD)





More information about the tor-commits mailing list