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

[tor-commits] [stem/master] Fixes for prior version parsing fixes



commit e427e6d7aff32d15ecf3d5ef3e0c78d2758deb24
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Mar 30 08:14:33 2012 -0700

    Fixes for prior version parsing fixes
    
    I never cease to be amazed at how error prone something that sounds as simple
    as 'parse the tor version' can be. Guess that's why we're writing a library...
    
    This has a couple fixes for the prior set of fixes.
    
    a. The runner was misparsing 'GETINFO version' output for verisons without a
       space.
    
    b. Sinister bug (took me almost an hour to track down) where the results from
       our mocked "tor --version" call were cached and broke later tests. This only
       manifested if your tor version wasn't 0.2.2.35 and you ran both the unit and
       integ tests together.
---
 test/runner.py       |    4 +++-
 test/unit/version.py |    8 ++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/test/runner.py b/test/runner.py
index dcc7f9c..32c3872 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -409,7 +409,9 @@ class Runner:
       control_socket.close()
       
       tor_version = list(version_response)[0]
-      tor_version = tor_version[8:tor_version.find(' ', 8)]
+      tor_version = tor_version[8:]
+      if " " in tor_version: tor_version = tor_version.split(' ', 1)[0]
+      
       return stem.version.Version(tor_version)
     except TorInaccessable:
       return stem.version.get_system_tor_version(self.get_tor_command())
diff --git a/test/unit/version.py b/test/unit/version.py
index 4843321..2b5cf96 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -18,6 +18,12 @@ class TestVersion(unittest.TestCase):
     mocking.revert_mocking()
   
   def test_get_system_tor_version(self):
+    # Clear the version cache both before and after the test. Without this
+    # prior results short circuit the system call, and future calls will
+    # provide this mocked value.
+    
+    stem.version.VERSION_CACHE = {}
+    
     def _mock_call(command):
       if command == "tor --version":
         return TOR_VERSION_OUTPUT.splitlines()
@@ -27,6 +33,8 @@ class TestVersion(unittest.TestCase):
     mocking.mock(stem.util.system.call, _mock_call)
     version = stem.version.get_system_tor_version()
     self.assert_versions_match(version, 0, 2, 2, 35, None)
+    
+    stem.version.VERSION_CACHE = {}
   
   def test_parsing(self):
     """

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